我正试图写一个清晰的文档/描述我的地形模块。根据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
否则