显示<computed>的地形隐藏值

时间:2019-01-22 23:17:37

标签: terraform

在Terraform计划中,有很多显示<computed>的值,例如:

aws_s3_bucket.environment-store: Creating...
  acceleration_status:         "" => "<computed>"
  acl:                         "" => "private"
  arn:                         "" => "<computed>"
  bucket:                      "" => "my-unique-bucket-1234"
  bucket_domain_name:          "" => "<computed>"
  bucket_regional_domain_name: "" => "<computed>"
  force_destroy:               "" => "false"
  hosted_zone_id:              "" => "<computed>"
  region:                      "" => "<computed>"
  request_payer:               "" => "<computed>"
  tags.%:                      "" => "2"
  tags.Environment:            "" => "env-tag"
  tags.Name:                   "" => "Storage for my environment"
  versioning.#:                "" => "1"
  versioning.0.enabled:        "" => "true"
  versioning.0.mfa_delete:     "" => "false"
  website_domain:              "" => "<computed>"
  website_endpoint:            "" => "<computed>"

有没有一种方法可以不显示值为“ <computed>”的行,像这样:

aws_s3_bucket.environment-store: Creating...
  acl:                         "" => "private"
  bucket:                      "" => "my-unique-bucket-1234"
  force_destroy:               "" => "false"
  tags.%:                      "" => "2"
  tags.Environment:            "" => "env-tag"
  tags.Name:                   "" => "Storage for my environment"
  versioning.#:                "" => "1"
  versioning.0.enabled:        "" => "true"
  versioning.0.mfa_delete:     "" => "false"

编辑:我忘了提到grep -v不是这里的选择-不管模式有多复杂,它都可能删除超出预期的内容。

2 个答案:

答案 0 :(得分:0)

我不认为只能隐藏所创建资源的字段子集。

根据terraform plan command的文档,您可以使用-module-depth=n标志来控制向控制台输出多少数据。我相信,如果您设置了-module-depth=0,则不会获得任何输出,但是我现在不在笔记本电脑上进行测试/确认。

答案 1 :(得分:0)

只需将计划的标准输出传送到grep的排除范围即可。

terraform plan | grep -v ' => <computed>'

甚至

alias tfnc="terraform plan | grep -v ' => <computed>'"
tfnc

如果这还不够好,您可以安装terraform-plan-parser并编写脚本来解析不是<computed>的属性。