Skip to content

Instantly share code, notes, and snippets.

@shubhamoli
Created July 11, 2021 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shubhamoli/03796f096521cbdbdafaf4802ea715d4 to your computer and use it in GitHub Desktop.
Save shubhamoli/03796f096521cbdbdafaf4802ea715d4 to your computer and use it in GitHub Desktop.
terraform optional keys in maps
locals {
required_value = {
RequiredValue = "${var.required}"
}
optional_value = {
exists = {
OptionalValue = "${var.optional}"
}
not_exists = {}
}
final_value = "${merge(
local.required_value,
local.optional_value[var.optional != "" ? "exists" : "not_exists"]
)}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment