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
1
62
TFLintカスタムプラグインで始める Terraformコード品質管理
o 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
150
コードを読んで理解するko build
bells17
1
410
Kubernetes History Inspector(KHI)を触ってみた
bells17
0
450
スリーシェイクにおけるOSSの取り組み
bells17
4
540
コミュニティ紹介: Kubernetes Meetup Novice
bells17
1
270
社内活動の取り組み紹介 ~ スリーシェイクでこんな取り組みしてます ~
bells17
1
680
モダンインフラの基礎を学ぼう!実践コンテナ入門
bells17
2
400
Kubernetes Code Contribution入門
bells17
5
1.3k
Dev ContainersとTestcontainers
bells17
3
790
Other Decks in Programming
See All in Programming
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
0
210
CSC509 Lecture 06
javiergs
PRO
0
260
なぜあの開発者はDevRelに伴走し続けるのか / Why Does That Developer Keep Running Alongside DevRel?
nrslib
3
390
CSC305 Lecture 06
javiergs
PRO
0
210
After go func(): Goroutines Through a Beginner’s Eye
97vaibhav
0
350
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
280
CSC509 Lecture 04
javiergs
PRO
0
300
アメ車でサンノゼを走ってきたよ!
s_shimotori
0
220
iOSエンジニア向けの英語学習アプリを作る!
yukawashouhei
0
190
CSC305 Lecture 04
javiergs
PRO
0
260
技術的負債の正体を知って向き合う / Facing Technical Debt
irof
0
150
Django Ninja による API 開発効率化とリプレースの実践
kashewnuts
0
1.2k
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
232
18k
Building Adaptive Systems
keathley
43
2.8k
Faster Mobile Websites
deanohume
310
31k
GitHub's CSS Performance
jonrohan
1032
470k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
Building Better People: How to give real-time feedback that sticks.
wjessup
368
20k
Navigating Team Friction
lara
189
15k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.7k
Become a Pro
speakerdeck
PRO
29
5.5k
Code Reviewing Like a Champion
maltzj
525
40k
Facilitating Awesome Meetings
lara
56
6.6k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
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 _