【发布时间】:2020-07-28 10:40:55
【问题描述】:
要求:我有一堆 EC2。我根据标签进行分组。在此示例中,组总数 = 4,每个组有 7 个 EC2:1 个父级 - 6 个子级。在这里,我正在分享命名重要的孩子的代码。
工作代码:这里我分享子 EC2 代码,它与名为 :ws_to_Child_Node_name_map_count 的地图类型的输入变量完美配合。现在我希望它是可扩展的(父子数量),我希望使用“在本地动态创建的地图”而不是使用输入变量。 main.tf
resource "aws_instance" "ec2_instance_child" {
count = var.ec2_instance_child_count
tags = {
NodeName = "${lookup(var.ws_to_Child_Node_name_map_count, count.index+1, 99)}"
}
}
变量.tf
variable "ws_to_Child_Node_name_map_count" {
type = map
default = {
"1"="1"
"2"="2"
"3"="3"
"4"="4"
"5"="5"
"6"="6"
"7"="1"
"8"="2"
"9"="3"
"10"="4"
"11"="5"
"12"="6"
"13"="1"
"14"="2"
"15"="3"
"16"="4"
"17"="5"
"18"="6"
"19"="1"
"20"="2"
"21"="3"
"22"="4"
"23"="5"
"24"="6"
}
}
variable "ec2_instance_child_count" {
description = "Number of instances to run"
default = "24" #number of group *6
}
上面显示的地图我想使用两个变量动态创建,将来我不会是常量。
variable "child_count" {
default = 6
}
variable "group_count" {
default = 4
}
【问题讨论】:
标签: terraform terraform-provider-aws terraform0.12+