How to get an object from a list of objects in Terraform?

You get the map with id=”name2″ with the following expression:

var.objects[index(var.objects.*.id, "name2")]

For a quick test, run the following one-liner in terraform console:

[{id = "name1", attribute = "a"}, {id = "name2", attribute = "a,b"}, {id = "name3", attribute = "d"}][index([{id = "name1", attribute = "a"}, {id = "name2", attribute = "a,b"}, {id = "name3", attribute = "d"}].*.id, "name2")]

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)