Quantcast
Channel: Terraform - HashiCorp Discuss
Viewing all articles
Browse latest Browse all 11357

How to create resources from a list of objects?

$
0
0

I have a list of objects, and I want to use the object information to create resources. How is that possible?

let’s assume I have this “object_list”

[
  {
  "id" = "abc1",
  "target" = "xyz1"
  },
  {
  "id" = "abc2",
  "target" = "xyz2"
  }
]

when applying that list to resources:

resource "myresource" "example" {
  for_each = object_list
  resource_id = each.value.id
  resource_target = each.value.target
}

obviously doesn’t work - but I am running out of ideas how to reach these resources I want to create (pseudo-code):

example[0]
{
  resource_id = "abc1"
  resource_target = "xyz1"
}
example[1]
{
  resource_id = "abc2"
  resource_target = "xyz2"
}

Any ideas? Thanks!

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 11357

Trending Articles