[Solved] Datasource interpolation in dynamic block

hi,

I’m trying to do the following :

data "subnet" "foo" {
  name = "sub"
}

locals { 
  network = ["foo"]
}

dynamic "nic_list" {
  for_each = local.network
  content {
    bar = data.subnet.${nic_list.value}.metadata.uuid
  }
}

but i’m getting Error: Invalid attribute name, an attribute name is required after a dot

Thus I tried to surround bar value with quote which seems to work in a sense.
Bar variable effectively get assigned the string litteral data.subnet.foo.metadata.uuid whereas I was expecting that it would be expanded to the real datasource attribute value.

Is this how terraform do interpolation ?

Is there a way to assign dynamiccaly from datasource value ?

You can’t refer to another resource using a dynamic label, no. But since the label is also a fixed string, I’m not sure why you’re trying to do this. Why not write data.subnet.foo.metadata.uuid?

Can you explain more about what you’re trying to achieve here?

Well how we met again :slight_smile:
Thanks again for your answer.

Indeed I came up with what you suggest. Looking back I think I was trying something kind of overcomplicated.

Anyway thank you very much.