Skip to content

Instantly share code, notes, and snippets.

@dalethestirling
Created November 26, 2019 07:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dalethestirling/5e0226fd6143b07d7501371441e0688f to your computer and use it in GitHub Desktop.
Save dalethestirling/5e0226fd6143b07d7501371441e0688f to your computer and use it in GitHub Desktop.
Terraform 0.12 - merge and output map values based on key
variable "var_a" {
type = "map"
default = {
"a" = "one"
"b" = "two"
}
}
variable "var_b" {
type = "map"
default = {
"a" = "one"
"b" = "two"
}
}
# 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)
}
}
# 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