docs-terraform-guidelines

Tflint

The goal of this page is to list some useful information about tflint

Default configuration

Within the .tflint.hcl file, you can define a default configuration for all your projects.

plugin "terraform" {
  enabled = true
  source  = "github.com/terraform-linters/tflint-ruleset-terraform"
  preset  = "all"
}

rule "terraform_naming_convention" {
  enabled = true
}

# Change it depending on your cloud providers
plugin "aws" {
  enabled = true
  source  = "github.com/terraform-linters/tflint-ruleset-aws"
}

How to use it

terraform {
  after_hook "validate_tflint" {
    commands = ["validate"]
    execute = [
      "sh", "-c", <<EOT
        echo "Run tflint for layer '${path_relative_to_include()}'..."
        (tflint --config="${get_repo_root()}/.tflint.hcl" --force --color -f compact)
        error_code=$?
        echo "Run tflint for layer '${path_relative_to_include()}'...DONE\n"
        exit $error_code
      EOT
    ]
  }
}