TFLint
TFLint is a pluggable linter for Terraform code. It can detect possible errors, enforce best practices, and provide style checking.
Installation
Using Homebrew
brew install tflintUsing Curl
curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bashDocker
docker pull ghcr.io/terraform-linters/tflintConfiguration
Create .tflint.hcl in your project root:
plugin "aws" {
enabled = true
version = "0.23.1"
source = "github.com/terraform-linters/tflint-ruleset-aws"
}
rule "aws_instance_invalid_type" {
enabled = true
}
rule "terraform_deprecated_index" {
enabled = true
}
# Disallow // comments in favor of #
rule "terraform_comment_syntax" {
enabled = true
}
# Enforce consistent naming
rule "terraform_naming_convention" {
enabled = true
format = "snake_case"
}Available Rules
Built-in Rules
Provider-specific Rules
Integration with CI/CD
GitHub Actions
Azure DevOps Pipeline
Pre-commit Hook Integration
Add to .pre-commit-config.yaml:
Best Practices
1. Rule Configuration
2. Plugin Management
3. Ignore Rules When Needed
Common Issues and Solutions
Version Mismatches
Keep TFLint and plugins updated
Pin versions in CI/CD
Use version constraints
Performance
Use
.tflint.hclto enable only needed rulesImplement caching in CI/CD
Use parallel execution for large codebases
False Positives
Use ignore comments judiciously
Configure rules appropriately
Report issues to maintainers
Checklist
Last updated