Created
November 26, 2019 07:12
-
-
Save dalethestirling/5e0226fd6143b07d7501371441e0688f to your computer and use it in GitHub Desktop.
Terraform 0.12 - merge and output map values based on key
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 "var_a" { | |
type = "map" | |
default = { | |
"a" = "one" | |
"b" = "two" | |
} | |
} | |
variable "var_b" { | |
type = "map" | |
default = { | |
"a" = "one" | |
"b" = "two" | |
} | |
} |
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
# Handles matches where B does not have the key listed in A | |
output "my_vars_mismatch" { | |
value = { | |
for item in keys(var.var_a): | |
var.var_a[item] => lookup(var.var_b, item, null) | |
} | |
} |
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
# Assumes that the lists are aligned | |
output "my_vars_aligned" { | |
value = { | |
for item in keys(var.var_a): | |
var.var_a[item] => var.var_b[item] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment