我有以下变量声明:
variable "environment" {
type = object({
SFTP = map(object({
containers = list(object({
name = string
container_access_type = optional(string)
metadata = optional(map(string))
}))
users = list(object({
name = string
home_directory = optional(string)
ssh_key_enabled = optional(bool, true)
permissions_scopes = list(object({
target_container = string
permissions = optional(list(string), ["All"])
}))
ssh_authorized_keys = optional(list(object({
key = string
description = optional(string)
})), [])
}))
}))
})
}
还有base.auto.tfvars 文件:
environment = {
SFTP = {
containers = [
{
name = "sftp-container-1"
container_access_type = "public"
metadata = {
environment = "production"
}
}
]
users = [
{
name = "user1"
home_directory = "/home/user1"
ssh_key_enabled = true
permissions_scopes = [
{
target_container = "sftp-container-1"
permissions = ["Read", "Write"]
},
{
target_container = "sftp-container-2"
permissions = ["All"]
}
]
ssh_authorized_keys = [
{
key = "ssh-rsa AAAAB3Nza [email protected]"
description = "User 1's SSH key"
}
]
}
]
}
}
运行这个,Terraform 说: 给定值不适合在 infra-variables.tf:1,1-23 声明的 var.environment:属性“SFTP”:元素“containers”:需要对象。
我对这个愚蠢的帖子感到抱歉,但我找不到它。
谢谢 沃尔夫冈
类型定义与值冲突,因为
SFTP
的值应该是 map(object)
,但提供了 object
作为值。目前尚不清楚您的意图,因此如果您打算object
,您可以更新定义,例如:
type = object({
SFTP = object({
containers = list(object({
name = string
container_access_type = optional(string)
metadata = optional(map(string))
}))
users = list(object({
name = string
home_directory = optional(string)
ssh_key_enabled = optional(bool, true)
permissions_scopes = list(object({
target_container = string
permissions = optional(list(string), ["All"])
}))
ssh_authorized_keys = optional(list(object({
key = string
description = optional(string)
})), [])
}))
})
})
但是如果您想要
map(object)
,那么您可以更新该值,例如:
environment = {
SFTP = {
"some_descriptive_key" = {
...
}
}
}