
tflint Tips
はじめに tflint 利用時のメモ 想定するディレクトリ構成 環境は dev, prd など 環境毎にディレクトリを切る 各環境の main.tf から使用したい module を使う module は 機能単位でディレクトリを切る cognitoとかで切ってるけど、サービスの有効無効など、もう少し大きな単位で切っても良いイメージ ├── envs │ ├── dev │ │ ├── main.tf │ │ ├── outputs.tf │ │ ├── swagger.yaml │ │ ├── terraform.tfvars │ │ └── variables.tf │ └── prd │ ├── main.tf │ └── ... └── module_aws ├── cognito │ ├── main.tf │ ├── outputs.tf │ └── variables.tf └── s3 ├── main.tf ├── outputs.tf └── variables.tf tflint の設定ファイルの読み込み優先順位: tflint/docs/user-guide/config.md at master · terraform-linters/tflint File passed by the –config option File set by the TFLINT_CONFIG_FILE environment variable Current directory (./.tflint.hcl) Home directory (~/.tflint.hcl) awsでこんな設定をしてみた # 結構口うるさいタイプ plugin "terraform" { enabled = true preset = "all" } # `tflint --init` needed plugin "aws" { enabled = true # deep_check = true version = "0.34.0" source = "github.com/terraform-linters/tflint-ruleset-aws" } # rule "terraform_required_version" { # enabled = false # } # # rule "terraform_required_providers" { # enabled = false # } よくでてくるエラーは以下 variable.tf ではなく、variables.tf にする output は outputs.tf に書く outputs.tf は空でも要る output, variable には description を書く 無視する方法は以下 以下のように tflint-ignore を書く # tflint-ignore: terraform_required_version # tflint-ignore: terraform_required_providers module を再帰的にチェックはしない --recursive を指定しても、ロードしている module のなかまでチェックされない ref: tflint の仕様や使い方についてのメモ 対象のディレクトリ(module)に移動または、–chdirで指定して、モジュールのチェックを行う必要がある => 想定構成のディレクトリでは、構成のルートディレクトリから --recursive つけて tflint すればいい => envs配下も、module_aws 配下もチェックされる Terraform 的には 暗黙的 プロバイダの継承 を推奨? Providers Within Modules - Configuration Language | Terraform | HashiCorp Developer For convenience in simple configurations, a child module automatically inherits default provider configurations from its parent. This means that explicit provider blocks appear only in the root module, and downstream modules can simply declare resources for that provider and have them automatically associated with the root provider configurations. ...