Terraform 地形-覆盖地图中的单个值
我想知道是否有可能合并两张地图而不替换主地图对象 我的地图对象定义如下:Terraform 地形-覆盖地图中的单个值,terraform,Terraform,我想知道是否有可能合并两张地图而不替换主地图对象 我的地图对象定义如下: variable "apps" { type = map(object({ is_enabled = bool cost_center = string })) default = {} } locals { default_apps = { "api-1" = { is_enabled = false cost_cente
variable "apps" {
type = map(object({
is_enabled = bool
cost_center = string
}))
default = {}
}
locals {
default_apps = {
"api-1" = {
is_enabled = false
cost_center = "1234"
},
"api-2" = {
is_enabled = false
cost_center = "1235"
},
}
apps = merge(
local.default_apps,
var.apps
)
}
如果按如下方式定义我的TFAR,则覆盖api-1的值['s_enabled']
apps = {
"api-1" = {
is_enabled = true
}
}
我得到以下错误:
Error: Invalid value for input variable
The environment variable TF_VAR_apps does not contain a valid value for
variable "apps": element "api-1": attribute "cost_center" is required.
如果我这样定义我的TFVAR,它就会起作用:
apps = {
"api-1" = {
is_enabled = true
cost_center = "1234"
}
}
我的目标是覆盖tfvars中default\u apps
(e.x已启用)下预定义局部变量之一的单个值
编辑:需求错误不是关于您的
合并
,而是关于您的TFAR
。以下变量在您的情况下无效:
apps = {
"api-1" = {
is_enabled = true
}
}
正如您明确定义的:
type = map(object({
is_enabled = bool
cost_center = string
}))
您的应用程序
缺少成本中心
,这是必需的。如果使用类型,则必须提供在类型定义中指定的所有内容:
与对象类型匹配的值必须包含所有指定的键,并且每个键的值必须与其指定的类型匹配
谢谢你回答我的问题。我没有提到我正在试图覆盖一个在本地语言中预定义的变量。如果我要在tfvars中添加
api-3
,我同意。我需要定义成本中心和is_enabled@AaronBandelli没问题,但是tfars
中的变量被称为apps
,并且您定义了variable“apps”
以要求成本中心
。如果您不想使用变量“apps”
中的类型定义,请将其重命名为其他名称。