Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TFLintカスタムプラグインで始める Terraformコード品質管理

Avatar for bells17 bells17
October 14, 2025

TFLintカスタムプラグインで始める Terraformコード品質管理

o Night Talks – After Conference の LT資料です
https://mercari.connpass.com/event/367075/

Avatar for bells17

bells17

October 14, 2025
Tweet

More Decks by bells17

Other Decks in Programming

Transcript

  1. ▶ @bells 1 7 ▶ Software Engineer@ 3 -shake inc.

    ▶ CNCF Ambassadors ▶ Kubernetes Novice Tokyo Organizer ▶ GitHub: @bells 1 7 ▶ : @bells 1 7 _
  2. Terraformのコードルール ▶ バージョンの指定 方 法 ▶ 独 自 のリソースの命名規約 ▶

    リソースに対するタグ付けポリシーの強制 ▶ etc... こういった独 自 ルールなどを terrafrom fmt やモジュール化などだけで対応 するものも難しい...
  3. Terraform Language rules ▶ Terraformの 言 語設定の推奨事項を実装したルールセット ▶ 公式のTerraform 言

    語推奨事項を超えるスタイルルールを適 用 したい 場合は、独 自 のルールセットプラグインを作成する必要がある
  4. TFLintプラグインの実 行方 法 ▶ デフォルトで ~/.t fl int.d/plugins/ にある t

    fl int-ruleset-<name> をTFLint プラグインと認識する ▶ TFLINT_PLUGIN_DIR 環境変数で指定も可能 ▶ GitHub Release で公開されている場合、URLでの指定も可能
  5. TFLintプラグインのデバッグ 方 法 ▶ 自 作プラグインでエラーが出る examples を 用 意しておいて、コマンドで

    examples に対して 自 作プラグインを使ったTFLintを実 行 して、lint/ auto fi xを確認できるようにしておくと便利だった ▶ また、ユニットテスト 用 のhelperが 用 意されているので、それを使って テストを書くようにしてた ▶ 最終的にどうやってインストールして実 行 するのかを 示 す意味でも examples を 用 意しておくと導 入 が楽
  6. TFLintプラグインの配布 方 法 ▶ ( 手 動でビルドしたプラグインを)~/.t fl int.d/plugins/t fl

    int-ruleset- <name> に配置 ▶ GitHub Releaseにバイナリを配置して 自 動インストール可能にする 今回はプライベート環境でかつCI/CD ・ ローカル環境両 方 で利 用 したかった ので、 手 動ビルドする 方 法を採 用 (GitHub Releaseを利 用 する 方 法だとGitHub Tokenの設定が必要そうだった)
  7. 参考リンク ・ 画像など引 用 元 一 覧 ▶ https://github.com/terraform-linters/t fl

    int/tree/v 0 . 5 8 . 0 ▶ https://github.com/terraform-linters/t fl int-ruleset-terraform/tree/v 0 . 1 2 . 0 ▶ https://github.com/terraform-linters/t fl int-plugin-sdk/tree/v 0 . 2 2 . 0 ▶ https://github.com/terraform-linters/t fl int-ruleset-template/tree/main ▶ https://github.com/hashicorp/go-plugin/tree/v 1 . 7 . 0 /examples ▶ https://brand.hashicorp.com/product_logos ▶ https://ray.so/