Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

各種バージョンアップ #28

Merged
merged 1 commit into from
Dec 24, 2024
Merged

各種バージョンアップ #28

merged 1 commit into from
Dec 24, 2024

Conversation

fittecs
Copy link
Member

@fittecs fittecs commented Dec 23, 2024

概要

各種アクションや利用ツールのバージョンアップ。
OIDCがモジュールのバージョンアップと同時に設定の互換性が無くなって動かなくなっていたので修正。
あとシェルのシェバンを気分で変更。

作業手順

1. terraformコマンドのバージョンアップ

$ tfenv list-remote
$ tfenv install 1.10.3
$ tfenv use 1.10.3
$ terraform version

2. 各種ファイルに記載されたバージョンをアップ

ファイル 更新対象
.github/action/setup/action.yaml terraform_version
.github/actions/**/*.yaml 各ツールおよびactionのバージョン
.github/workflows/*.yaml 各ツールおよびactionのバージョン
terraform/globals.tf required_version
terraform/globals.tf required_providersの各providerのバージョン
terraform/.tflint.hcl googleプラグインのバージョン
.regal/config.yaml capabilities.from.version
terraform/tier1-main.tf project_servicesモジュールのバージョン
terraform/modules/**/main.tf サードパーティのモジュールのバージョン

バージョンアップしたファイルに関連するツールが正しく動くかを確認するために、scriptsディレクトリ内のシェルを実行して正常系、異常系どちらも反応することを確認。

$ cd /path/to/infra-testing-google-sample/scripts
$ ./scripts/conftest.sh
.tflin.hclの定義を消して実行すれば異常系のテストが可能。

$ ./scripts/opafmt.sh
policies配下のregoのコードのフォーマット崩して実行して、フォーマッタが効くことを確認。

$ ./scripts/regal.sh
tflint_hcl.regoのpackage名をconftestから始まらないように修正してリンタ実行 -> 検知できることを確認。

$ ./scripts/tffmt.sh
何かしらの.tfファイルのインデントを崩すなどしてフォーマット実行 -> フォーマッタが効くことを確認。

$ ./scripts/tflint.sh
何かしらの.tfファイルのresourceのnameにハイフン入れてチェック実行 -> 検知できることを確認。

$ ./scripts/trivy.sh
バージョンアップ時の追加チェックで引っかかったので異常検知は出来ている。

あとREADME.mdにも各ツールのバージョン書いてるので、それらを最新に変更する必要がある。

3. OPAのメジャーバージョンアップ対応

ついにOPA1.0がリリースされたので対応。

まずリリースノートとマイグレーションのドキュメント読む。
https://github.com/open-policy-agent/opa/releases
https://www.openpolicyagent.org/docs/latest/v0-upgrade/

コードをopa, regal, conftestで検索。
そしてopa fmt --v1-compatible --rego-v1 $OPT policies/から--v1-compatible --rego-v1オプションを削除。

そもそもOPA1.0.0がリリースから3日しか経過していない状態であるため、Regalはv0.69.0を使用している。
Regalは0.70.0でも動くので.regal/config.yamlのcapabilities.from.versionはv0.70.0になる。
他はすでにv1のオプトイン行っていたため修正の必要はなかった。

4. test環境のtier1、tier2ディレクトリ内にある.terraform.lock.hclを更新(しないとCIが落ちる)

$ cd /path/to/infra-testing-google-sample/terraform/environments/test/tier1
$ terraform init -backend-config="bucket=infra-testing-google-sample-sbx-e-terraform" -upgrade

$ cd ../tier2
$ terraform init -backend-config="bucket=infra-testing-google-sample-sbx-e-terraform" -upgrade

stg環境と本番環境では不要。

@fittecs fittecs force-pushed the feature/version-upgrade branch 2 times, most recently from 812ea88 to 30aa1d3 Compare December 24, 2024 12:56
@fittecs fittecs force-pushed the feature/version-upgrade branch from 30aa1d3 to 26a5347 Compare December 24, 2024 13:27
@fittecs fittecs merged commit 797be24 into main Dec 24, 2024
1 check passed
@fittecs fittecs deleted the feature/version-upgrade branch December 24, 2024 13:27
Copy link

Action URL: https://github.com/erueru-tech/infra-testing-google-sample/actions/runs/12482332175

stg$ terraform apply -auto-approve

$\color{red}\textsf{[tier1] Plan: 4 to add, 1 to change, 1 to destroy.}$

$\color{green}\textsf{[tier2] Plan: 6 to add, 0 to change, 0 to destroy.}$

Copy link

Action URL: https://github.com/erueru-tech/infra-testing-google-sample/actions/runs/12482323110

stg$ terraform plan

$\color{green}\textsf{[tier1] No changes. Your infrastructure matches the configuration.}$

$\color{green}\textsf{[tier2] No changes. Your infrastructure matches the configuration.}$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant