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
68
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
「ちょっと古いから」って避けてた技術書、今だからこそ読もう
mottyzzz
10
6.6k
overlayPreferenceValue で実現する ピュア SwiftUI な AdMob ネイティブ広告
uhucream
0
180
Introducing ReActionView: A new ActionView-Compatible ERB Engine @ Kaigi on Rails 2025, Tokyo, Japan
marcoroth
3
980
開発生産性を上げるための生成AI活用術
starfish719
3
420
CSC305 Lecture 03
javiergs
PRO
0
240
(Extension DC 2025) Actor境界を越える技術
teamhimeh
1
250
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
230
Pythonスレッドとは結局何なのか? CPython実装から見るNoGIL時代の変化
curekoshimizu
5
1.7k
技術的負債の正体を知って向き合う / Facing Technical Debt
irof
0
150
Swift Concurrency - 状態監視の罠
objectiveaudio
2
510
Serena MCPのすすめ
wadakatu
4
960
複雑化したリポジトリをなんとかした話 pipenvからuvによるモノレポ構成への移行
satoshi256kbyte
1
1k
Featured
See All Featured
Designing for Performance
lara
610
69k
GraphQLの誤解/rethinking-graphql
sonatard
73
11k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
9
590
Automating Front-end Workflow
addyosmani
1371
200k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
132
19k
A designer walks into a library…
pauljervisheath
209
24k
[RailsConf 2023] Rails as a piece of cake
palkan
57
5.9k
How to Ace a Technical Interview
jacobian
280
24k
Producing Creativity
orderedlist
PRO
347
40k
BBQ
matthewcrist
89
9.8k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
285
14k
Optimizing for Happiness
mojombo
379
70k
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 _