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
When Dependencies Fail: Building Antifragile Applications in a Fragile World
selcukusta
0
120
ビルドプロセスをデバッグしよう!
yt8492
0
150
Amazon Verified Permissions実践入門 〜Cedar活用とAppSync導入事例/Practical Introduction to Amazon Verified Permissions
fossamagna
2
110
Migration to Signals, Resource API, and NgRx Signal Store
manfredsteyer
PRO
0
130
Module Proxyのマニアックな話 / Niche Topics in Module Proxy
kuro_kurorrr
0
200
実践Claude Code:20の失敗から学ぶAIペアプログラミング
takedatakashi
18
9.2k
Webサーバーサイド言語としてのRustについて
kouyuume
1
5k
CSC305 Lecture 12
javiergs
PRO
0
240
モテるデスク環境
mozumasu
3
1.4k
外接に惑わされない自システムの処理時間SLIをOpenTelemetryで実現した話
kotaro7750
0
130
AI 駆動開発におけるコミュニティと AWS CDK の価値
konokenj
5
300
SwiftDataを使って10万件のデータを読み書きする
akidon0000
0
250
Featured
See All Featured
Automating Front-end Workflow
addyosmani
1371
200k
Agile that works and the tools we love
rasmusluckow
331
21k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
The Power of CSS Pseudo Elements
geoffreycrofte
80
6k
Balancing Empowerment & Direction
lara
5
710
A designer walks into a library…
pauljervisheath
209
24k
Side Projects
sachag
455
43k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
132
19k
Done Done
chrislema
186
16k
The Language of Interfaces
destraynor
162
25k
Documentation Writing (for coders)
carmenintech
76
5.1k
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 _