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

How to describe an object type variable in Terraform?

我正在尝试写一个清晰的 documentation/description 我的 terraform 模块。 根据 Hashicorp's docdescription 属性将允许这样做,但我找不到详细描述 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

这是一种使用 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否则

您可以使用以下格式并使用 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
}