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
590
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
190
コードを読んで理解するko build
bells17
1
440
Kubernetes History Inspector(KHI)を触ってみた
bells17
0
470
スリーシェイクにおけるOSSの取り組み
bells17
4
570
コミュニティ紹介: Kubernetes Meetup Novice
bells17
1
290
社内活動の取り組み紹介 ~ スリーシェイクでこんな取り組みしてます ~
bells17
1
700
モダンインフラの基礎を学ぼう!実践コンテナ入門
bells17
2
430
Kubernetes Code Contribution入門
bells17
5
1.4k
Dev ContainersとTestcontainers
bells17
3
830
Other Decks in Programming
See All in Programming
AIの弱点、やっぱりプログラミングは人間が(も)勉強しよう / YAPC AI and Programming
kishida
13
5.3k
TypeScript 5.9で使えるようになった import defer でパフォーマンス最適化を実現する
bicstone
1
390
Combinatorial Interview Problems with Backtracking Solutions - From Imperative Procedural Programming to Declarative Functional Programming - Part 1
philipschwarz
PRO
0
100
2025 컴포즈 마법사
jisungbin
0
150
しっかり学ぶ java.lang.*
nagise
1
420
例外処理を理解して、設計段階からエラーを見つけやすく、起こりにくく #phpconfuk
kajitack
12
6.4k
「正規表現をつくる」をつくる / make "make regex"
makenowjust
1
750
スタートアップを支える技術戦略と組織づくり
pospome
8
11k
r2-image-worker
yusukebe
1
180
AIと協働し、イベントソーシングとアクターモデルで作る後悔しないアーキテクチャ Regret-Free Architecture with AI, Event Sourcing, and Actors
tomohisa
2
8.4k
ソフトウェア設計の課題・原則・実践技法
masuda220
PRO
21
16k
予防に勝る防御なし(2025年版) - 堅牢なコードを導く様々な設計のヒント / Growing Reliable Code PHP Conference Fukuoka 2025
twada
PRO
39
13k
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
56
14k
Statistics for Hackers
jakevdp
799
230k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.5k
A better future with KSS
kneath
239
18k
Done Done
chrislema
186
16k
Building an army of robots
kneath
306
46k
Making Projects Easy
brettharned
120
6.5k
Writing Fast Ruby
sferik
630
62k
How to train your dragon (web standard)
notwaldorf
97
6.4k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
36
6.1k
Large-scale JavaScript Application Architecture
addyosmani
514
110k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
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 _