【问题标题】:Ignore certain tags from terraform locals忽略来自 terraform locals 的某些标签
【发布时间】:2019-10-01 03:28:59
【问题描述】:

如何忽略 locals 变量中定义的某个标签? 例如:我想忽略这个 dynamodb 表资源的电子邮件标签。

局部定义

locals {
  global_tags = {
    email = "xxx.com"
    owner = "xxx"
  }
  common_tags = {
    Name = "live"
  }
}

 lifecycle {
    ignore_changes = [
      read_capacity,
      write_capacity,
      local.global_tags.email
    ]
  }

  tags = merge(local.global_tags,local.common_tags,var.received_nexgen_events_tags)

}

详情:

Terraform v0.12.0
+ provider.aws v2.30.0

我试过了,但是出错了

错误:不支持的属性

在 ../../../../tf_module_dynamodb/events.tf 第 22 行,资源“aws_dynamodb_table”“事件”中: 22:local.global_tags.email

此对象没有名为的参数、嵌套块或导出属性 “本地”。

2:我也这样试过,需要静态变量引用,什么是静态变量引用?

 lifecycle {
    ignore_changes = [
      read_capacity,
      write_capacity,
      local.global_tags["xxx.com"]
    ]
  }


error :
 22:       local.global_tags["xxx.com"]

A static variable reference is required.

【问题讨论】:

  • 运行时是否出现错误?如果是这样,请将其包含在问题中。如果它没有出错但没有达到您的预期,请清楚说明正在发生的事情以及您希望发生的事情。

标签: amazon-web-services terraform terraform-provider-aws


【解决方案1】:

嗯,terraform > 0.12 版本有一个bug

terraform plan 和 terraform apply 会说它要添加 tag.email ,但是当 terraform apply 命令运行时它会忽略 tag.email 。

我使用 terraform state rm --target=resource-name 进行了测试并进行了导入,然后 terraform state 显示了资源名称,tag.email 未导入(被忽略)!

更多详情:https://github.com/hashicorp/terraform-plugin-sdk/issues/167M

  lifecycle {
    ignore_changes = [
      read_capacity,
      write_capacity,
      tags.email  
    ]
  }

【讨论】:

  • 链接有错别字。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多