terraform の linter tflin を導入し、GitHub Actions で構文チェック
terraform の linter として tflint を導入し、
GitHub Actions でチェックが良かったのでまとめます。
asdf で導入
asdf で複数バージョンの導入・切り替えが可能です。
asdf 経由で導入
1 | asdf plugin-add tflint https://github.com/skyzyx/asdf-tflint |
GitHub Actions で設定
Pull Request 作成・更新時に tflint を走らせる設定です。
以下ディレクトリ毎に tflint を実行しています。
- envs/prd
- envs/stg
1 | name: Lint |
timeout-minutes: 3
おおよそ完了する時間は 1 分も掛からないですが、3 分もあれば終わるのと
意図せぬ長時間の実行を回避すべく、3 分でタイムアウトする様に設定しています。
リソース数にもよるので適宜設定してください。
GITHUB_TOKEN を指定する理由
いらなそう?と思いましたが、公式に以下コメントがあります。
When you install plugins with tflint –init, TFLint calls the GitHub API to get release metadata. By default, this is an unauthenticated request, subject to a rate limit of 60 requests per hour per IP address.
認証されていないリクエストで、IP アドレスあたり 1 時間あたり 60 リクエストというレート制限がある為、
それを回避する為に設定する必要があるとのこと。
以上
参考になれば幸いです。
terraform の linter tflin を導入し、GitHub Actions で構文チェック
https://kenzo0107.github.io/2023/04/04/2023-04-05-tflint-is-good/