Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds tflint validation to Terraform in documentation #14549

Merged
merged 6 commits into from
Aug 13, 2020

Conversation

gdavison
Copy link
Contributor

Adds GitHub workflow to validate Terraform code in documentation.

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Relates #14417

Release note for CHANGELOG:

NONE

Output from acceptance testing:

N/A

@gdavison gdavison requested a review from a team August 10, 2020 23:44
@ghost ghost added size/XL Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. provider Pertains to the provider itself, rather than any interaction with AWS. service/acm Issues and PRs that pertain to the acm service. service/appsync Issues and PRs that pertain to the appsync service. service/autoscaling Issues and PRs that pertain to the autoscaling service. service/cloudformation Issues and PRs that pertain to the cloudformation service. service/cloudfront Issues and PRs that pertain to the cloudfront service. service/cognito service/dlm Issues and PRs that pertain to the dlm service. service/ec2 Issues and PRs that pertain to the ec2 service. service/elbv2 Issues and PRs that pertain to the elbv2 service. service/emr Issues and PRs that pertain to the emr service. service/globalaccelerator Issues and PRs that pertain to the globalaccelerator service. service/iam Issues and PRs that pertain to the iam service. service/kms Issues and PRs that pertain to the kms service. service/lambda Issues and PRs that pertain to the lambda service. service/workspaces Issues and PRs that pertain to the workspaces service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Aug 10, 2020
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking real good! It'd be nice to consolidate this over in website.yml so all the website checks are together and get it in a supported terrafmt release, but other than that I think this will be good to go. 👍

If this scripting will be used in multiple places like the acceptance testing configurations, we will probably want to make it a shell script and call out to it directly.

TFLINT_VERSION: "v0.18.0"
run: |
curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | sh
- name: lint code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's consolidate this over to the existing website.yml 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I wasn't sure the best approach here, since we'll need to do an almost identical workflow for checking acceptance tests.

We're waiting on katbyte/terrafmt#26 being merged for the supported release.

Comment on lines +100 to +144
exit_code=0

# Configure the rules for tflint.
# The *_invalid_* rules disabled here prevent evaluation of expressions.
# Do not disable *_invalid_name rules, since these are good checks for e.g. "%s" formatting verbs
# being carried over from test cases.
shared_rules=(
"--enable-rule=terraform_comment_syntax"
"--disable-rule=aws_cloudwatch_event_target_invalid_arn"
"--disable-rule=aws_cognito_user_pool_domain_invalid_domain"
"--disable-rule=aws_db_instance_default_parameter_group"
"--disable-rule=aws_elasticache_cluster_default_parameter_group"
"--disable-rule=aws_iam_saml_provider_invalid_saml_metadata_document"
"--disable-rule=aws_iam_server_certificate_invalid_certificate_body"
"--disable-rule=aws_iam_server_certificate_invalid_private_key"
"--disable-rule=aws_transfer_ssh_key_invalid_body"
"--disable-rule=aws_worklink_website_certificate_authority_association_invalid_certificate"
)
find ./website/docs -type f \( -name '*.md' -o -name '*.markdown' \) \
| sort -u \
| while read -r filename ; do
rules=("${shared_rules[@]}")
if [[ "$filename" == "./website/docs/guides/version-2-upgrade.html.md" ]]; then
# ./website/docs/guides/version-2-upgrade.html.md should still include pre-0.12 syntax,
# since v1.0 does not support Terraform 0.12.
rules+=(
"--disable-rule=terraform_deprecated_interpolation"
"--disable-rule=terraform_deprecated_index"
)
else
rules+=(
"--enable-rule=terraform_deprecated_interpolation"
"--enable-rule=terraform_deprecated_index"
)
fi
# echo "Let's go with $filename..."
# We need to capture the output and error code here. We don't want to exit on the first error
set +e
./scripts/validate-terraform-file.sh "$filename" "${rules[@]}"
lint_exitcode=$?
set -e
if [ $lint_exitcode -ne 0 ]; then exit_code=1; fi
done

exit $exit_code
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be moved to yet another script. It's messy because of the special handling for ./website/docs/guides/version-2-upgrade.html.md. Otherwise, the read could be moved into the script, and it could be called like

find ./website/docs -type f \( -name '*.md' -o -name '*.markdown' \) | ./scripts/validate-terraform.sh "${rules[@]}"

That model could be used for the acceptance test validation

Copy link
Member

@YakDriver YakDriver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT 💯

@gdavison gdavison merged commit d94bc74 into master Aug 13, 2020
@gdavison gdavison deleted the documentation-ftlint branch August 13, 2020 18:47
@ghost
Copy link

ghost commented Sep 13, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Sep 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. provider Pertains to the provider itself, rather than any interaction with AWS. service/acm Issues and PRs that pertain to the acm service. service/appsync Issues and PRs that pertain to the appsync service. service/autoscaling Issues and PRs that pertain to the autoscaling service. service/cloudformation Issues and PRs that pertain to the cloudformation service. service/cloudfront Issues and PRs that pertain to the cloudfront service. service/dlm Issues and PRs that pertain to the dlm service. service/ec2 Issues and PRs that pertain to the ec2 service. service/elbv2 Issues and PRs that pertain to the elbv2 service. service/emr Issues and PRs that pertain to the emr service. service/globalaccelerator Issues and PRs that pertain to the globalaccelerator service. service/iam Issues and PRs that pertain to the iam service. service/kms Issues and PRs that pertain to the kms service. service/lambda Issues and PRs that pertain to the lambda service. service/workspaces Issues and PRs that pertain to the workspaces service. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants