I have a terraform variable defined like that:
variable "domains" {
default = {
instance01 = [
"example.com",
"www.example.com",
"staging.example.com"
]
}
}
Terraform version:
Terraform v0.13.3
How can I access the domain names in instance01
and loop over the values?
How can I access the instance names and loop over the instance names?
Edit:
What I tried was creating a loop to iterate over each instance and over each domain name in the list associated to the instance:
resource "aws_lb_listener_certificate" "lb_listener_certs" {
for_each = var.domains
listener_arn = aws_lb_listener.front_end_https[each.key].arn
certificate_arn = data.aws_acm_certificate.cert[each.value].arn
}
Error I get is:
Error: Invalid index
on main.tf line 86, in resource "aws_lb_listener_certificate" "lb_listener_certs":
86: certificate_arn = data.aws_acm_certificate.cert[each.value].arn
|----------------
| data.aws_acm_certificate.cert is object with 3 attributes
| each.value is tuple with 3 elements
The given key does not identify an element in this collection value: string
required.
It should create for each key (e.g. instance01) and each child of the list a aws_lb_listener_certificate
(e.g. example.com
, www.example.com
). But I cannot get it to interate over the items of the list assigned to instance01
.
I basically want it to make a map like that:
instance01 => example.com
instance01 => www.example.com
instance01 => staging.example.com
I'd like to use this key value pair to create the aws_lb_listener_certificate
.