Requirements: I have a bunch of EC2s. Which I am grouping according to the Tags. in this example total number of group =4 and each group has 7 EC2 : 1 parent-6 Child. here i am sharing code of child whose naming matters.
working code:Here I am sharing the child EC2 code which is working perfectly fine with the input variables of map type named :ws_to_Child_Node_name_map_count. Now i want it to be scalable(number of parent-child) for which I am looking to use 'dynamically created map in locals' instead of using input variable. 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)}"
}
}
variable.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
}
the map shown above I want to create dynamically using two variables, which in future i will not be constant.
variable "child_count" {
default = 6
}
variable "group_count" {
default = 4
}