TFLint Terraform linter
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
tflint --inittflinttflint --recursive
tflint --chdir=<dir>
tflint --format=compact
tflint --config=<file>
tflint --enable-rule=<rule>
tflint --fixConcepts
- .tflint.hcl plugins and rules
- Plugins rulesets on disk
- Rules run on your .tf files
- Issues error / warning / notice
Setup
brew install terraform-linters/tap/tflint
tflint --version
tflint --inittflint --recursive --init
docker run --rm -v $(pwd):/data -t
ghcr.io/terraform-linters/tflint
export GITHUB_TOKEN=<token>
Running
tflinttflint --chdir=<dir>
tflint --recursive
tflint --filter=<file>
tflint --fixtflint --call-module-type=<all|local|none>
tflint --helpOutput and exit codes
tflint --format=compact
tflint --format=json
tflint --format=sarif
tflint --no-color
tflint --forcetflint
--minimum-failure-severity=<error|warning|notice>
| Code | Meaning |
|---|---|
0 |
No issues |
1 |
Error while running |
2 |
Issues found |
Rules
tflint --enable-rule=<rule>
tflint --disable-rule=<rule>
tflint --only=<rule>
| Source | Where |
|---|---|
| 1. --only | CLI |
| 2. --enable-rule / --disable-rule | CLI |
| 3. rule blocks | Config file |
| 4. preset | terraform plugin config |
| 5. disabled_by_default | Config file |
Config file
tflint --config=<file>
tflint --config=$(realpath .tflint.hcl) --recursive
| Order | File |
|---|---|
| 1 | --config |
| 2 | $TFLINT_CONFIG_FILE |
| 3 | ./.tflint.hcl |
| 4 | ./.tflint.json |
| 5 | ~/.tflint.hcl |
| 6 | ~/.tflint.json |
plugin "aws" { enabled = true version = "0.4.0" source = "github.com/terraform-linters/tflint-ruleset-aws"}rule "terraform_typed_variables" { enabled = true}
config { format = "compact" call_module_type = "local" disabled_by_default = false varfile = ["dev.tfvars"] variables = ["env=dev"]}
plugin "terraform" { enabled = true preset = "recommended"}
Ignoring issues
# tflint-ignore: <rule>instance_type = "t1.2xlarge"
# tflint-ignore: <rule> # too new for TFLintinstance_type = "t1.2xlarge"
# tflint-ignore: <rule_a>, <rule_b># tflint-ignore: all
# tflint-ignore-file: <rule>
Modules and variables
tflint --var-file=<file>
tflint --var='<name>=<value>'
tflint --ignore-module=<source>
Recipes
cat > .tflint.hcl <<'EOF'plugin "terraform" { enabled = true preset = "recommended"}EOFtflint --inittflint --recursive
tflint --inittflint --recursive --format=sarif > tflint.sarif# exit code 2 fails the job
tflint --recursive --minimum-failure-severity=error



