-
Notifications
You must be signed in to change notification settings - Fork 7
Run Terraform Linting Locally
This document highlights the steps needed in order to perform linting of the terraform files locally.
All information was taken from this page but I have only included the necessary information.
MacOS - Homebrew:
brew install tflint
Windows - Chocolatey:
choco install tflint
Open a terminal and cd into the terraform directory. Run the following command
tflint --init
TFLint runs on the root module by default. It does not support recursion (similar to how terraform operates).
Run the following command to run tflint on the main module and other modules we use within the project
tflint --module
tflint --module security
tflint --module networking
tflint --module database
tflint --module storage
tflint --module compute
At the moment there are no errors returned by the TFLint tool which is what we want.
To simualte a TFLint warning to see how tool works.
Open up the file terraform/database/database.tf
Search for the text instance_class = var.dbase_instance_type
Replace it with the text instance_class = "db.t3.micro123"
This test will simualte a tflint warning as the instance type db.t3.micro123 does not exist
Run the command tflint --module database
The returned error should be similar to the following message
Error: "db.t3.micro123" is invalid instance type. (aws_db_instance_invalid_type)
on database/database.tf line 80:
80: instance_class = "db.t3.micro123"
Reference: https://github.com/terraform-linters/tflint-ruleset-aws/blob/v0.5.0/docs/rules/aws_db_instance_invalid_type.md