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要求propaly_at_launch字段。
我已经在许多其他资源中使用了我的标签映射,我想将其重新用作asg资源。可以肯定的是,我将始终将broadcast_at_launch设置为true。如何将其添加到地图的每个元素并将其用于tags
字段?
答案 0 :(得分:4)
我使用null资源来完成此操作,并将其输出作为标记,如下所示-
extend()
您可以将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
。