如何在Terraform中描述对象类型变量?



我正试图写一个清晰的文档/描述我的地形模块。根据Hashicorp的文档,description属性允许这样做,但是我找不到详细描述object类型变量的方法。

这里是我想做的或多或少:

variable "sa_to_impersonate_info" {
type = object(
{
id                   = string
email                = string
belonging_org_id     = string
belonging_project_id = string
token_scopes         = list(string)
token_lifetime       = string
}
)
description = {
id : "an identifier for the resource with format projects/{{project}}/serviceAccounts/{{email}}"
email : "Email of the service account to impersonate"
belonging_org_id : "Organization ID where the service account belongs"
belonging_project_id : "Porject ID where the service account belongs"
token_scopes : "List of scopes affected by this service account impersonation"
token_lifetime : "Time the token will be active"
}
}

对于这种格式,当我执行terraform plan时,我得到这个错误:

Error: Unsuitable value type

您可以使用EOT分隔符将其设置为以下格式。

variable "sa_to_impersonate_info" {
type = object(
{
id                   = string
email                = string
belonging_org_id     = string
belonging_project_id = string
token_scopes         = list(string)
token_lifetime       = string
}
)
description = <<EOT
sa_to_impersonate_info = {
id : "an identifier for the resource with format projects/{{project}}/serviceAccounts/{{email}}"
email : "Email of the service account to impersonate"
belonging_org_id : "Organization ID where the service account belongs"
belonging_project_id : "Porject ID where the service account belongs"
token_scopes : "List of scopes affected by this service account impersonation"
token_lifetime : "Time the token will be active"
}
EOT
}

这是一种使用terraform的heredoc将所有字段打印为一个字符串的方法…(可能不是最好的解决方案)

variable "sa_to_impersonate_info" {
type = object(
{
id                   = string
email                = string
belonging_org_id     = string
belonging_project_id = string
token_scopes         = list(string)
token_lifetime       = string
}
)
description = <<-_EOT
{
id : "an identifier for the resource with format projects/{{project}}/serviceAccounts/{{email}}"
email = Email of the service account to impersonate
belonging_org_id = Organization ID where the service account belongs
belonging_project_id = Porject ID where the service account belongs
token_scopes = List of scopes affected by this service account impersonation
token_lifetime = Time the token will be active
}
_EOT
}

使用<<-_EOT来考虑缩进,使用<<_EOT否则

最新更新