# Not able to iterate over unknown resource/module value

**URL:** <https://discuss.hashicorp.com/t/not-able-to-iterate-over-unknown-resource-module-value/44453>\
**Category:** Terraform\
**Created:** [September 18, 2022, 5:18pm UTC](https://discuss.hashicorp.com/t/not-able-to-iterate-over-unknown-resource-module-value/44453 "2022-09-18T17:18:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JinoArch](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jinoarch/32/28724_2.png) [@JinoArch](https://discuss.hashicorp.com/u/JinoArch)\
**Post date:** [September 18, 2022, 5:18pm UTC](https://discuss.hashicorp.com/t/not-able-to-iterate-over-unknown-resource-module-value/44453/1 "2022-09-18T17:18:36Z")

</div>

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

```auto
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
}

```

```auto
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
}

```

```auto
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](http://123.com)”,“[456.com](http://456.com)”,“[789.com](http://789.com)”]

```auto
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:

```auto
 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.

```

---

<div class="post-metadata">

**Author:** ![hsimon-hashicorp](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/hsimon-hashicorp/32/19684_2.png) [@hsimon-hashicorp](https://discuss.hashicorp.com/u/hsimon-hashicorp)\
**Post date:** [October 10, 2022, 5:13pm UTC](https://discuss.hashicorp.com/t/not-able-to-iterate-over-unknown-resource-module-value/44453/2 "2022-10-10T17:13:49Z")

</div>

Closed on October 10, 2022, 5:13pm UTC


