Adding the tflint linter for Terraform and running syntax checks in GitHub Actions
I introduced tflint as a linter for Terraform,
and since running the checks in GitHub Actions worked out well, I’m writing it up here.
Installing with asdf
With asdf you can install and switch between multiple versions.
Install via asdf:
1 | asdf plugin-add tflint https://github.com/skyzyx/asdf-tflint |
Configuring GitHub Actions
This is the configuration that runs tflint when a Pull Request is created or updated.
It runs tflint for each of the following directories:
- envs/prd
- envs/stg
1 | name: Lint |
timeout-minutes: 3
It usually completes in less than a minute, but since three minutes is more than enough to finish
and to avoid unintentionally long-running executions, I set it to time out after 3 minutes.
This depends on the number of resources, so adjust it as appropriate.
Why specify GITHUB_TOKEN
I thought it might not be necessary, but the official docs include the following comment:
When you install plugins with tflint –init, TFLint calls the GitHub API to get release metadata. By default, this is an unauthenticated request, subject to a rate limit of 60 requests per hour per IP address.
Because unauthenticated requests are subject to a rate limit of 60 requests per hour per IP address,
you need to set this in order to avoid that limit.
That’s all.
I hope this is helpful.
Adding the tflint linter for Terraform and running syntax checks in GitHub Actions