Skip to content

Instantly share code, notes, and snippets.

@Satak
Last active May 25, 2021 05:23
Show Gist options
  • Save Satak/b49be1e7d5393c095e49eb2e30ba9e53 to your computer and use it in GitHub Desktop.
Save Satak/b49be1e7d5393c095e49eb2e30ba9e53 to your computer and use it in GitHub Desktop.
Terraform snippets
variable "my_list" {
default = [
{
id = 1
name = "name1"
},
{
id = 2
name = "my_name"
},
{
id = 3
name = "name3"
},
]
}
# find object id from list of objects by its name
locals {
for_loop_method = [for item in var.my_list : item.id if item.name == "my_name"][0]
splat_method = var.my_list[index(var.my_list.*.name, "my_name")].id
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment