Conversation
terraform fmt / validate、tflint、trivy(設定スキャン)、 terraform-docsドリフト検査をPRごとに実行するワークフローを追加。 クラウド認証情報は不要で、4つのTerraformルート (modules/aws/ecs-fargate, modules/gcp/cloud-run, examples/*)を matrixで検査する。tflintはterraform推奨プリセットに加えて AWS/Googleルールセットを使用。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
modules/gcp/cloud-runとexamples/gcp-cloud-runにはterraform-docsの 生成マーカーがあるのに設定ファイルがなく、生成内容がAWSモジュールと 不統一だった。AWSモジュールの.terraform-docs.ymlを両ディレクトリに 展開し、3ディレクトリのREADMEを再生成してドリフトを解消 (examples/gcp-cloud-runのrequired_version表記が実態と異なっていた 点なども修正される)。 あわせてname_prefixのdescriptionにvalidationで課している制約 (8文字以内・英数字とハイフンのみ・先頭末尾ハイフン不可)を明記。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- examples/aws-ecs-fargate/acm.tf: どこからも参照されていない local.certificate_arn / local.has_certificateを削除 - examples/gcp-cloud-run/dns.tf: 未使用のdata.google_dns_managed_zone のみのファイルのため削除(var.dns_zone_name自体はモジュールへの 受け渡しで使用されており影響なし) - examples/aws-ecs-fargate/variables.tf: var.certificate_arnは 現状どこにも配線されていないが、READMEに記載のある利用者向け インターフェースのため宣言を維持し、理由コメント付きで tflint-ignoreを付与(配線の修正は別PRで対応) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
既存の #tfsec:ignore:AWSxxx は旧tfsecのID体系のため現行trivyでは 効いておらず、CIのtrivyスキャンが意図的な設計まで検出してしまう。 現行のAVD ID形式(#trivy:ignore:AVD-AWS-xxxx)へ置き換え、 これまでignore対象でなかった検出(bastionのSSHインバウンド、 Secrets ManagerのCMK、GCPサンプルDBの監査ログフラグ等)にも 理由コメント付きでignoreを追加した。 いずれも「BaseMachinaから到達可能にするための意図的な公開設定」 または「接続テスト用サンプルリソースの簡易設定」であり、 実設定の変更は行っていない。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
PR #14で追加されたname_prefixのvalidation(8文字以内)に対し、 テストの "test-<6文字>"(11文字)が違反しており、テスト実行時に planの時点でエラーになる状態だった。ランダム部を3文字に切り詰めて "test-<3文字>"(8文字)とする。cleanupExistingS3Endpointsの テストリソース判定が "test-" 前方一致に依存しているため、 プレフィックス形式は維持している。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
trivyはバージョンによってチェックIDと内容が変わり (例: フローログのAVD-GCP-0029がGCP-0076に刷新、 Private Google AccessのGCP-0075が新規追加)、 ローカルとCIで結果が揺れるため、CIのtrivyバージョンを v0.72.0に固定した。network.tfのignoreは新旧両方のIDを指定。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
クラウド認証情報なしで動く静的チェックCIを導入し、CIをグリーンにするために必要な既存コードの修正を行いました。品質担保の仕組み整備の第1弾です(E2Eテストの自動実行・リリース自動化は後続で対応予定)。
CIの内容(
.github/workflows/ci.yml)PRごと・mainへのpushごとに以下を実行します。AWS/GCPの認証情報は一切使いません。
terraform fmt -check -recursiveinit -backend=false→validate.tflint.hcl)既存コードの修正(チェックで実際に検出されたもの)
#tfsec:ignore:AWSxxxが全く効いていなかったため、現行trivyのID形式(#trivy:ignore:AVD-AWS-xxxx)へ更新。これまでignore対象でなかった検出にも理由コメント付きでignoreを追加。いずれも意図的な設計(ALB公開等)またはサンプル用の簡易設定で、実設定の変更はありませんname_prefixがPR #14のvalidation(8文字以内)に違反していたため、test-<3文字>(8文字)に短縮。go buildで確認済みlocal.certificate_arn/local.has_certificate/data.google_dns_managed_zone)required_versionの古い表記も実態に修正)name_prefixのdescriptionにvalidation制約(8文字以内等)を明記ローカルでの動作確認
CIと同一のコマンド・同一バージョン(terraform 1.13.3 / tflint 0.64.0 / terraform-docs 0.24.0 / trivy)で以下をすべてexit 0で確認済みです。
terraform fmt -check -recursiveterraform init -backend=false→terraform validatetflinttrivy config --exit-code 1 .(検出0件)actionlint(ワークフロー自体の検証)cd test && go build ./...気づいた点(別PRで対応予定)
examples/aws-ecs-fargateのvar.certificate_arnとenable_acm_importは現在どこにも配線されておらず、ALBの証明書は常にroute53_domain.tfのaws_acm_certificate.bridgeが使われます(READMEの記載と実装が乖離)。機能修正になるため本PRではtflint-ignoreと理由コメントのみ付与し、配線の修正は別PRで対応します。マージ後に行うこと
terraform fmt/terraform validate (*)/tflint (*)/trivy config scan/terraform-docs drift checkです。🤖 Generated with Claude Code