I’m in the process of learning Terraform, the questions I have are based on the code below. This is not all of the code… The code does function now.
module "route53-health-checks" {
source = "./route53-health-checks"
for_each = var.map
environment = each.value["environment"] #var.environment
domain_name = each.value["domain_name"] #var.domain_name
resource_path = each.value["resource_path"] #var.resource_path
}
variable "map" {
type = map(object({
environment = string
domain_name = string
resource_path = string
}))
default = {
"1" = {
environment = "all"
domain_name = "mywebsite.com"
resource_path = "/"
}
"2" = {
environment = "misc1"
domain_name = "myothersite.com"
resource_path = "/onlineservices/account/login.aspx"
}
"3" = {
environment = "misc2"
domain_name = "stuffhere.com"
resource_path = "/"
}
}
}
So i have a module that I call using the for_each = var.map
The variable “map” default section I had to create by hand… How can i automate that based of some sort of external input… file etc…? I will have possibly hundreds of entries… Manually creation is not going to cut it.
I have seen things like leveraging Dynamic Blocks, but looks like that is not recommended… Any help would be greatly appreciated…
thanks