Terraform 变量中的映射(映射(字符串))问题
我正在尝试将此模块用于Terraform:。我有一个如下构造的地形变量Terraform 变量中的映射(映射(字符串))问题,terraform,Terraform,我正在尝试将此模块用于Terraform:。我有一个如下构造的地形变量 variable "repositories" { description = "Repositories setup." type = object({ owner = string location = string format = string description = string roles = map
variable "repositories" {
description = "Repositories setup."
type = object({
owner = string
location = string
format = string
description = string
roles = map(map(string))
labels = map(string)
kms_key_name = string
})
default = {
activerepo = {
owner = "eric@xxxxxx"
location = "asia-east1"
format = "DOCKER"
description = "Docker repository"
roles = [{
members = "mark@xxxxxx"
role = "artifactregistry.admin"
},
]
labels = null
kms_key_name = null
}
}
}
当我运行terraform plan
时,我得到以下输出:
│ Error: Invalid default value for variable
│
│ on variables.tf line 59, in variable "repositories":
│ 59: default = {
│ 60: activeops = {
│ 61: owner = "eric@xxxxxxx"
│ 62: location = "asia-east1"
│ 63: format = "DOCKER"
│ 64: description = "Docker repository"
│ 65: roles = [{
│ 66: members = "mark@xxxxxxxx"
│ 67: role = "artifactregistry.admin"
│ 68: },
│ 69: ]
│ 70: labels = null
│ 71: kms_key_name = null
│ 72: }
│ 73: }
│
│ This default value is not compatible with the variable's type constraint: attributes
"description", "format", "kms_key_name", "labels", "location", "owner", and "roles"
are required.
我做错了什么?非常感谢您的帮助
提前谢谢
Eric.您的默认值是对象的贴图,而不是对象。此外,您的
角色
是地图列表,而不是地图列表。因此,它应该是:
variable "repositories" {
description = "Repositories setup."
type = map(object({
owner = string
location = string
format = string
description = string
roles = list(map(string))
labels = map(string)
kms_key_name = string
}))
default = {
activerepo = {
owner = "eric@xxxxxx"
location = "asia-east1"
format = "DOCKER"
description = "Docker repository"
roles = [{
members = "mark@xxxxxx"
role = "artifactregistry.admin"
},
]
labels = null
kms_key_name = null
}
}
}
variable "repositories" {
description = "Repositories setup."
type = object({
owner = string
location = string
format = string
description = string
roles = map(map(string))
labels = map(string)
kms_key_name = string
})
default = {
owner = "eric@xxxxxx"
location = "asia-east1"
format = "DOCKER"
description = "Docker repository"
roles = {
myrole= {
members = "mark@xxxxxx"
role = "artifactregistry.admin"
}},
labels = null
kms_key_name = null
}
}
更新
如果要将默认值
调整为类型
,则应为:
variable "repositories" {
description = "Repositories setup."
type = map(object({
owner = string
location = string
format = string
description = string
roles = list(map(string))
labels = map(string)
kms_key_name = string
}))
default = {
activerepo = {
owner = "eric@xxxxxx"
location = "asia-east1"
format = "DOCKER"
description = "Docker repository"
roles = [{
members = "mark@xxxxxx"
role = "artifactregistry.admin"
},
]
labels = null
kms_key_name = null
}
}
}
variable "repositories" {
description = "Repositories setup."
type = object({
owner = string
location = string
format = string
description = string
roles = map(map(string))
labels = map(string)
kms_key_name = string
})
default = {
owner = "eric@xxxxxx"
location = "asia-east1"
format = "DOCKER"
description = "Docker repository"
roles = {
myrole= {
members = "mark@xxxxxx"
role = "artifactregistry.admin"
}},
labels = null
kms_key_name = null
}
}
感谢您的回复,但会抛出相同的错误。我认为模块确实需要一个地图地图,如示例中所示,但我不知道如何在角色部分反映这一点。@EricV。我用oposite change更新了答案-更新默认值以匹配类型。@EricV。进展如何?更新后的答案有效吗?很抱歉回复太晚。这在更新后的值之后起作用。非常感谢。进展如何?这个问题仍然存在吗?