Iteration counter in dynamic blocks

When using

dynamic "foo" {
 for_each = [for s in bar: {

Is there a way to access the index value, particular when looping through arrays. I’d want to know what element number it is up to to assist with unique stringifying.

If the argument to for_each is a list, foo.key yields the index value:

dynamic "foo" {
  for_each = [ "bar", "baz"]
  content {
    name = foo.key
  }
}

If the argument is a map, foo.key will access the key in the map.

1 Like

This works - had a type issue regarding strings and numbers of .key