Hello
I am trying to iterate over a module object which is know only after apply. I tried for_each and count, both works with known values only. So I tried For loop but I am not able to do it. It will be helpful if anyone can give me a hand
What is needed? I need 3 resource to be create like this via loop
resource "aws_route53_record" "msk_cname_record" {
zone_id = "XXXXXXX"
name = "kafka01"
records = <element 1 of list known after apply from module.qa_rr_kafka.bootstrap_brokers>
type = "CNAME"
ttl = 60
}
resource "aws_route53_record" "msk_cname_record" {
zone_id = "XXXXXXX"
name = "kafka02"
records = <element 2 of list known after apply from module.qa_rr_kafka.bootstrap_brokers>
type = "CNAME"
ttl = 60
}
resource "aws_route53_record" "msk_cname_record" {
zone_id = "XXXXXXX"
name = "kafka03"
records = <element 3 of list known after apply from module.qa_rr_kafka.bootstrap_brokers>
type = "CNAME"
ttl = 60
}
I tried like this but not working
list comes from [module.qa_rr_kafka.bootstrap_brokers]
sample value: module.qa_rr_kafka.bootstrap_brokers = [“123.com”,“456.com”,“789.com”]
locals {
lvar = {
for list in [module.qa_rr_kafka.bootstrap_brokers] : list => list
}
}
locals {
lind = {
for index,list in [module.qa_rr_kafka.bootstrap_brokers] : index => index
}
}
resource "aws_route53_record" "msk_cname_record" {
zone_id = "XXXXXX"
name = "kafka0${local.lind}"
records = local.lvars
type = "CNAME"
ttl = 60
}
Error shown:
Error: Invalid template interpolation value
│
│ on cname.tf line 22, in resource "aws_route53_record" "msk_cname_record":
│ 22: name = "qa-rr-kafka0${local.lind}"
│ ├────────────────
│ │ local.lind is object with 1 attribute "0"
│
│ Cannot include the given value in a string template: string required.