TFLint is a Terraform linter focused on possible errors, best practices, etc.
Terraform is a great tool for Infrastructure as Code. However, many of these tools don't validate provider-specific issues. For example, see the following configuration file:
resource "aws_instance" "foo" {
ami = "ami-0ff8a91507f77f867"
instance_type = "t1.2xlarge" # invalid type!
}
Since t1.2xlarge
is a nonexistent instance type, an error will occur when you run terraform apply
. But terraform plan
and terraform validate
cannot find this possible error beforehand. That's because it's an AWS provider-specific issue and it's valid as a Terraform configuration.
TFLint finds such errors in advance:
You can download the binary built for your architecture from the latest release. The following is an example of installation on macOS:
$ wget https://github.com/terraform-linters/tflint/releases/download/v0.13.2/tflint_darwin_amd64.zip
$ unzip tflint_darwin_amd64.zip
Archive: tflint_darwin_amd64.zip
inflating: tflint
$ mkdir -p /usr/local/tflint/bin
$ export PATH=/usr/local/tflint/bin:$PATH
$ install tflint /usr/local/tflint/bin
$ tflint -v
For Linux based OS, you can use the install_linux.sh
to automate the installation process, or try the following oneliner to download latest binary for AMD64 architecture.
$ curl -L "$(curl -Ls https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.zip")" -o tflint.zip && unzip tflint.zip && rm tflint.zip