Tools for generating an up-to-date .tflint.hcl
configuration file for use with tflint
.
The configuration options change often enough to annoy me, so here is some automation for generating it.
- macOS/Linux/WSL
- make
- Git
- Go
- Familiarity with Go templates (for making changes)
There are 4 supported modes:
- Amazon Web Services (AWS)
- Google Cloud Platform (GCP)
- Microsoft Azure (Azure)
- "base" (e.g., New Relic, PagerDuty, Cloudflare, Artifactory)
This is the version that has the good rules for standard Terraform, but is not tied to any particular cloud provider. This is useful when using one of the other 2,000 providers that aren't AWS, GCP, or Azure.
make base
This will output a file called .tflint.hcl
which can be copied into your project and used with tflint
.
This is the version that has everything that base has, with the addition of all of the cloud-specific rules enabled.
NOTE: There is not yet any way to override individual values as
enabled = false
. Open an issue if you want this and are willing to help.
make aws
make gcp
make azure
This will output a file called .tflint.hcl
which can be copied into your project and used with tflint
.
This whole approach works by fetching the terraform-linters/tflint-ruleset-*
repository and leveraging its existing code generation in a different way. By default, this uses the latest version of that ruleset I've personally tested. But if there is a newer/older version you want to use instead, you can pass the intended Git tag for the repository.
make aws TFLINT_AWS_TAG=0.13.2
make gcp TFLINT_GCP_TAG=0.16.1
make azure TFLINT_AZURE_TAG=0.15.0
You can find Git tag values at:
- https://github.com/terraform-linters/tflint-ruleset-aws/tags
- https://github.com/terraform-linters/tflint-ruleset-google/tags
- https://github.com/terraform-linters/tflint-ruleset-azurerm/tags
- Generate the "Base"
.tflint.hcl
file from the_base.tmpl.hcl
template.
- Read
_base.tmpl.hcl
. - Apply cloud-specific overlay (e.g.,
_aws.tmpl.hcl
) to generate a new template that will be passed to the ruleset repo for further code generation. - Clones the
tflint-ruleset-*
repo to your/tmp
directory. - Resolves the Git submodules.
- There is a file that is used as a template for generating a README with a list of all of the options. We replace that template with our own (see step 2).
- We run the generation step that's already part of the the upstream build process.
- We take the output file, and replace our
.tflint.hcl
file with it.