我有template_file
包含user_data
用于launch_template
的支持和ASG。
我想要实现的是在每个ASG实例中使用数组变量中的一个元素
variable "my_array_var" {
type = "list"
default = [ "one", "two" ]
}
data "template_file" "node-user-data" {
count = "${length(var.my_array_var)}"
template = <<EOF
#cloud-config
runcmd:
- [ my-command, ${element(var.my_array_var, count.index)} ]
EOF
}
resource "aws_launch_template" "node-lt" {
name = "node-lt"
image_id = "${var.instance_ami}"
instance_type = "${var.instance_type_node}"
user_data = "${base64encode(data.template_file.node-user-data.rendered)}"
}
resource "aws_autoscaling_group" "node-asg" {
name = "node-asg"
desired_capacity = 2
max_size = 2
min_size = 2
launch_template {
id = "${aws_launch_template.node-lt.id}"
version = "$$Latest"
}
}
有没有办法用terraform做到这一点?