Last active
May 25, 2021 05:23
-
-
Save Satak/b49be1e7d5393c095e49eb2e30ba9e53 to your computer and use it in GitHub Desktop.
Terraform snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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