Skip to content

Instantly share code, notes, and snippets.

@rafaelfuchsbr
Last active June 8, 2022 19:04
Show Gist options
  • Save rafaelfuchsbr/c9653d591ac50250834fa0e638203c67 to your computer and use it in GitHub Desktop.
Save rafaelfuchsbr/c9653d591ac50250834fa0e638203c67 to your computer and use it in GitHub Desktop.
Terraform maps matching
locals {
a = {
"key1" = "valueX"
"key2" = "valueY"
"key3" = "valueZ"
}
b = {
"key1" = "valueA"
"key2" = "valueB"
"key3" = "valueC"
}
c = merge([
for ka,va in local.a : {
for kb,vb in local.b: va => vb if ka == kb
}
]...)
}
output "c" {
value = local.c
}
@rafaelfuchsbr
Copy link
Author

The Terraform language has a general feature for turning lists/tuples into multiple arguments, by using the special symbol ... after the last argument expression

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment