LoginSignup
0
0

More than 1 year has passed since last update.

terraform planのsensitiveな値が含まれる部分のdiffを見たい

Last updated at Posted at 2022-10-24

問題

最近のterraformではsensitiveとマークされた値を含む部分はterraform planでも表示されなくなりました。

  ~ resource "aws_cloudfront_distribution" "this" {
        id                             = "ABCDEFGHIJKL"
        tags                           = {}
        # (20 unchanged attributes hidden)

      ~ origin {
          # At least one attribute in this block is (or was) sensitive,
          # so its contents will not be displayed.
        }

        # (3 unchanged blocks hidden)
    }

これにより困るのがCloudFrontのような中にいろいろ書けるリソースで、具体的に中で何が変更されたか推測することが難しくなっています。

この隠されているところで具体的に何が変更されたのか、確認する必要があります。

解答

terraform plan結果のファイルへの出力とそのjson化の機能を使います。
ただ、そのままですと長大なjsonを目視で読む必要があり大変です。
なので、jqとdiffを使って差分を効果的に可視化します。

具体コマンド

terraform plan -out=tfplan
terraform show -json tfplan > tfplan.json
cat tfplan.json | jq ".resource_changes[].change.before" > tfplan.before.json
cat tfplan.json | jq ".resource_changes[].change.after" > tfplan.after.json
diff tfplan.before.json tfplan.after.json

参考

How to show sensitive values - Terraform - HashiCorp Discuss

Sponsor

この記事はSpeee社内での知見を元にSpeeeの業務時間を使用して書かれました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0