Last active
December 4, 2020 20:31
-
-
Save jonathanhle/a362059f5a48d0b4512df8a837335b5d to your computer and use it in GitHub Desktop.
terraform 12 - find map object matching values
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
| sqs_data = { | |
| matt_test_one = { | |
| delay = 10 | |
| max_msg_size = 1024 | |
| environment = "dev" | |
| }, | |
| matt_test_two = { | |
| delay = 10 | |
| max_msg_size = 2048 | |
| environment = "test" | |
| }, | |
| matt_test_three = { | |
| delay = 5 | |
| max_msg_size = 4096 | |
| environment = "prod" | |
| } | |
| } |
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 "sqs_data" { | |
| type = map(object({ | |
| delay = number | |
| max_msg_size = number | |
| environment = string | |
| })) | |
| } | |
| output "test" { | |
| value = [ | |
| for k, v in var.sqs_data : | |
| k if v["max_msg_size"] == 2048 && v["environment"] == "test" | |
| ] | |
| } |
Author
jonathanhle
commented
Dec 4, 2020
Updated example with mostly locals:
variable "name_type" {
default = "matt"
}
locals {
sqs_data = {
matt_test_one = {
delay = 10
max_msg_size = 1024
environment = "dev"
},
matt_test_two = {
delay = 10
max_msg_size = 2048
environment = "test"
},
matt_test_three = {
delay = 5
max_msg_size = 4096
environment = "prod"
}
}
sqs_data_A = [
for k, v in local.sqs_data :
k if contains(split("_", k), var.name_type) && v["max_msg_size"] == 2048 && v["environment"] == "test"
]
}
output "test" {
value = local.sqs_data_A
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment