Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
TFLintカスタムプラグインで始める Terraformコード品質管理
Search
bells17
October 14, 2025
Programming
2
500
TFLintカスタムプラグインで始める Terraformコード品質管理
Go Night Talks – After Conference の LT資料です
https://mercari.connpass.com/event/367075/
bells17
October 14, 2025
Tweet
Share
More Decks by bells17
See All by bells17
Amazon VPC CNIに学ぶCNI-LT版
bells17
2
170
コードを読んで理解するko build
bells17
1
430
Kubernetes History Inspector(KHI)を触ってみた
bells17
0
450
スリーシェイクにおけるOSSの取り組み
bells17
4
550
コミュニティ紹介: Kubernetes Meetup Novice
bells17
1
280
社内活動の取り組み紹介 ~ スリーシェイクでこんな取り組みしてます ~
bells17
1
690
モダンインフラの基礎を学ぼう!実践コンテナ入門
bells17
2
410
Kubernetes Code Contribution入門
bells17
5
1.4k
Dev ContainersとTestcontainers
bells17
3
810
Other Decks in Programming
See All in Programming
Pythonに漸進的に型をつける
nealle
1
140
GC25 Recap: The Code You Reviewed is Not the Code You Built / #newt_gophercon_tour
mazrean
0
130
Inside of Swift Export
giginet
PRO
1
240
Dive into Triton Internals
appleparan
0
300
Temporal Knowledge Graphで作る! 時間変化するナレッジを扱うAI Agentの世界
po3rin
5
1.1k
Google Opalで使える37のライブラリ
mickey_kubo
3
170
alien-signals と自作 OSS で実現する フレームワーク非依存な ロジック共通化の探求 / Exploring Framework-Agnostic Logic Sharing with alien-signals and Custom OSS
aoseyuu
3
2.3k
NixOS + Kubernetesで構築する自宅サーバーのすべて
ichi_h3
0
1.3k
品質ワークショップをやってみた
nealle
0
660
CSC305 Lecture 11
javiergs
PRO
0
320
オープンソースソフトウェアへの解像度🔬
utam0k
18
3.2k
Amazon ECS Managed Instances が リリースされた!キャッチアップしよう!! / Let's catch up Amazon ECS Managed Instances
cocoeyes02
0
110
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
40
2.1k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Java REST API Framework Comparison - PWX 2021
mraible
34
8.9k
Designing for Performance
lara
610
69k
Building Adaptive Systems
keathley
44
2.8k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1k
Why You Should Never Use an ORM
jnunemaker
PRO
60
9.6k
Thoughts on Productivity
jonyablonski
71
4.9k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
4 Signs Your Business is Dying
shpigford
186
22k
KATA
mclloyd
PRO
32
15k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
2.9k
Transcript
TFLintカスタムプラグインで始める Terraformコード品質管理 Go Night Talks – After Conference ( 2
0 2 5 / 1 0 / 1 4 ) @bells 1 7
▶ @bells 1 7 ▶ Software Engineer@ 3 -shake inc.
▶ CNCF Ambassadors ▶ Kubernetes Novice Tokyo Organizer ▶ GitHub: @bells 1 7 ▶ : @bells 1 7 _
皆さんTerraformのコード管理ってどうしてますか?
Terraformのコードルール ▶ バージョンの指定 方 法 ▶ 独 自 のリソースの命名規約 ▶
リソースに対するタグ付けポリシーの強制 ▶ etc... こういった独 自 ルールなどを terrafrom fmt やモジュール化などだけで対応 するものも難しい...
https://github.com/terraform-linters/t fl int より 💡 TFLintのカスタムプラグインを作ればいいじゃない
TFLintとは ▶ Terraformのlint/auto fi xツール ▶ lintルールはプラグイン+ルールによるルールセットで提供 ▶ 公式が提供するプラグインは下記 +
Terraform Language + Amazon Web Services + Microsoft Azure + Google Cloud Platform
TFLintの基本的な使い 方
メインとなるTerraform Languageのルールセットは下記のようなものがある https://github.com/terraform-linters/t fl int-ruleset-terraform/blob/v 0 . 1 2 .
0 /docs/rules/README.md より
Terraform Language rules ▶ Terraformの 言 語設定の推奨事項を実装したルールセット ▶ 公式のTerraform 言
語推奨事項を超えるスタイルルールを適 用 したい 場合は、独 自 のルールセットプラグインを作成する必要がある
ということでプラグインを 自 作していく (プラグインを作るための基礎知識を解説)
TFLintのプラグイン呼び出しのシーケンス図 https://github.com/terraform-linters/t fl int/blob/v 0 . 5 8 . 0
/docs/developer-guide/architecture.md より
ホスト → プラグインのリクエスト ▶ 設定ファイルを元にプラグインの設定を適 用 する ▶ lint/auto fi
x処理の実 行 を依頼
プラグイン → ホストのリクエスト ▶ Terraform構成(Terraformの設定ファイル)の取得 ▶ 式の評価結果の取得 ▶ lint/auto fi
x処理の実 行 結果を送信
t fl int-plugin-sdkを使 用 してプラグインを実装していく https://github.com/terraform-linters/t fl int-ruleset-template/blob/main/main.go より
下記のようにルールを記述していく https://github.com/terraform-linters/t fl int-ruleset-template/blob/main/rules/terraform_backend_type.go より
Checkメソッドでlint/auto fi xルールを実装する https://github.com/terraform-linters/t fl int-ruleset-template/blob/main/rules/terraform_backend_type.go より
これでプラグインを実装してく流れは なんとなくわかった
じゃあ後はプラグインの実 行方 法やデバッグ 方 法
TFLintプラグインの実 行方 法 ▶ デフォルトで ~/.t fl int.d/plugins/ にある t
fl int-ruleset-<name> をTFLint プラグインと認識する ▶ TFLINT_PLUGIN_DIR 環境変数で指定も可能 ▶ GitHub Release で公開されている場合、URLでの指定も可能
TFLintプラグインの実 行 例
TFLintプラグインのデバッグ 方 法 ▶ 自 作プラグインでエラーが出る examples を 用 意しておいて、コマンドで
examples に対して 自 作プラグインを使ったTFLintを実 行 して、lint/ auto fi xを確認できるようにしておくと便利だった ▶ また、ユニットテスト 用 のhelperが 用 意されているので、それを使って テストを書くようにしてた ▶ 最終的にどうやってインストールして実 行 するのかを 示 す意味でも examples を 用 意しておくと導 入 が楽
helperを利 用 したユニットテストの例 https://github.com/terraform-linters/t fl int-ruleset-template/blob/main/rules/terraform_backend_type_test.go より ▶ helper.IssuesでExpectedを定義 ▶
helper.TestRunnerでテスト 用 のTerraform構 成を読み込み ▶ helper.AssertIssuesで結果をテスト
TFLintプラグインの配布 方 法 ▶ ( 手 動でビルドしたプラグインを)~/.t fl int.d/plugins/t fl
int-ruleset- <name> に配置 ▶ GitHub Releaseにバイナリを配置して 自 動インストール可能にする 今回はプライベート環境でかつCI/CD ・ ローカル環境両 方 で利 用 したかった ので、 手 動ビルドする 方 法を採 用 (GitHub Releaseを利 用 する 方 法だとGitHub Tokenの設定が必要そうだった)
これで最低限TFLintのプラグインを 開発〜配布するための基礎知識が揃った
後はルールの中 身 を実装していくだけ...
まとめ ▶ 組織独 自 のTerraformルールの維持管理ができるようにするために TFLintプラグインを 自 作した例を紹介しました ▶ プラグインの全体像を掴めると、後はそんなに苦戦せずに実装できたん
じゃないかと思います
参考リンク ・ 画像など引 用 元 一 覧 ▶ 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/
Thanks / Question? ▶ @bells 1 7 ▶ Slide: https://speakerdeck.com/bells
1 7 ▶ : @bells 1 7 _