설치

brew install tflint

설정

tflint은 기본적으로 terraform 언어에 대한 lint 및 error체크를 해준다. 하지만 terraform에는 다양한 plugin들이 있듯이, 모든 plugin를 체크할 순 없으므로 별도의 설정이 필요할 수 있다.

.tflint.hcl 파일을 생성한다. 어떤 경로든 상관없다. tflint —init을 실행

├── .terraform.lock.hcl
**├── .tflint.hcl**
├── main.tf
├── variables.tf
└── versions.tf

.tflint.hcl 파일에 각종 configuration, rule들을 설정한다.

config {
    force = false
    disabled_by_default = false
}

plugin "aws" {
    enabled = true
    version = "0.22.1"
    source  = "github.com/terraform-linters/tflint-ruleset-aws"
}
...
# Disallow deprecated (0.11-style) interpolation
rule "terraform_deprecated_interpolation" {
    enabled = true
}
...

.tflint.hcl 파일 설정이 완료되었으면 초기화를 해준다. .tflint.hcl 파일에 설정했던 plugin들이 설치된다.

설치된 plugin들은 ~/.tflint.d/plugins 폴더에 캐싱된다.

tflint --init

실행

아래 명령어를 실행하면 lint, error들을 체크해준다. —recursive 옵션을 추가하면 부모 디렉토리에서 모든 terraform 파일들을 검사한다.

config {
    force = false
    disabled_by_default = false
}

plugin "aws" {
    enabled = true
    version = "0.22.1"
    source  = "github.com/terraform-linters/tflint-ruleset-aws"
}
tflint -f compact --recursive

Github action

https://github.com/terraform-linters/setup-tflint