Is there a way to merge the following list of objects
variable "common_variables" {
type = list(object({ var_name = string, var_value = string, workspace_name = string }))
default = [
{
"var_name" = "location"
"var_value" = "West US"
"workspace_name" = "env-1"
}
]
}
variable "custom_variables" {
type = list(object({ var_name = string, var_value = string, workspace_name = string }))
default = [
{
"var_name" = "location"
"var_value" = "West Europe"
"workspace_name" = "env-1"
}
]
}
locals {
# custom_variables should replace common_variables
merged_variables = concat(var.common_variables, var.custom_variables)
}
output "merged_variables" {
value = local.merged_variables
}
Any custom_variables should replace common_variables that match on workspace_name & var_name.
So the output I want is:
merged_variables = [
{
"var_name" = "location"
"var_value" = "West Europe"
"workspace_name" = "env-1"
}
]