首页 文章

如何将标签映射应用于aws_autoscaling_group?

提问于
浏览
0

https://www.terraform.io/docs/providers/aws/r/autoscaling_group.html#propagate_at_launch

我这样做是为aws资源应用标签:

tags = "${merge(
    local.common_tags, // reused in many resources
    map(
      "Name", "awesome-app-server",
      "Role", "server"
    )
  )}"

但是asg需要propagate_at_launch字段 .

我已经在许多其他资源中使用了我的标签映射,并且我总是将propagate_at_launch设置为true . 如何将其添加到 Map 的每个元素并将其用于 tags 字段?

1 回答

  • 1

    我使用null资源并将其输出作为标记,下面的示例 -

    data "null_data_source" "tags" {
      count = "${length(keys(var.tags))}"
    
      inputs = {
        key                 = "${element(keys(var.tags), count.index)}"
        value               = "${element(values(var.tags), count.index)}"
        propagate_at_launch = true
      }
    }
    
    
    resource "aws_autoscaling_group" "asg_ec2" {
        ..........
        ..........
    
        lifecycle {
        create_before_destroy = true
        }
    
        tags = ["${data.null_data_source.tags.*.outputs}"]
        tags = [
          {
          key                 = "Name"
          value               = "awesome-app-server"
          propagate_at_launch = true
           },
          {
          key                 = "Role"
          value               = "server"
          propagate_at_launch = true
          }
        ]
    }
    

    您可以将 var.tags 替换为 local.common_tags .

相关问题