Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to describe an object type variable in Terraform?

I am trying to write a clear documentation/description of my terraform modules.
According to Hashicorp’s doc, the description attribute will permit that, but I cannot find a way to describe an object type variable in details.

Here’s more or less I want to do :

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"
  }
}

For this format I get this error when I perform a terraform plan:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 Error: Unsuitable value type

>Solution :

You can have it in below format with EOT delimiter.

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
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading