1

I'm trying to use this module for Terraform: Artifact Registry module. I have a variable for Terraform of the following construct.

variable "repositories" {
description = "Repositories setup."
type = object({
  owner        = string
  location     = string
  format       = string
  description  = string
  roles        = map(map(string))
  labels       = map(string)
  kms_key_name = string
})
default = {
  activerepo = {
    owner = "eric@xxxxxx"
    location = "asia-east1"
    format = "DOCKER"
    description = "Docker repository"
    roles = [{
      members = "mark@xxxxxx"
      role = "artifactregistry.admin"
      },
    ]
    labels = null
    kms_key_name = null
    }
  }
}

When I run terraform plan I get the below output:

│ Error: Invalid default value for variable
│ 
│   on variables.tf line 59, in variable "repositories":
│   59:   default = {
│   60:     activeops = {
│   61:       owner = "eric@xxxxxxx"
│   62:       location = "asia-east1"
│   63:       format = "DOCKER"
│   64:       description = "Docker repository"
│   65:       roles = [{
│   66:         members = "mark@xxxxxxxx"
│   67:         role = "artifactregistry.admin"
│   68:       },
│   69:       ]
│   70:       labels = null
│   71:       kms_key_name = null
│   72:     }
│   73:   }
│ 
│ This default value is not compatible with the variable's type constraint: attributes
  "description", "format", "kms_key_name", "labels", "location", "owner", and "roles"
  are required.

What am I doing wrong here? Any help is greatly appreciated.

Thanks in advance.

Eric.

1
  • How did it go? The issue still persist? Commented Jun 11, 2021 at 10:12

1 Answer 1

1

Your default value is a map of objects, not an object. Also your roles is a list of maps, not a map of maps. So it should be:

variable "repositories" {

  description = "Repositories setup."
  
  type = map(object({
    owner        = string
    location     = string
    format       = string
    description  = string
    roles        = list(map(string))
    labels       = map(string)
    kms_key_name = string
  }))
  
  default = {
    activerepo = {
      owner = "eric@xxxxxx"
      location = "asia-east1"
      format = "DOCKER"
      description = "Docker repository"
      roles = [{
        members = "mark@xxxxxx"
        role = "artifactregistry.admin"
        },
      ]
      labels = null
      kms_key_name = null
      }
    }
}

UPDATE

If you want to adjust default value to the type it should be:

variable "repositories" {

  description = "Repositories setup."
  
  type = object({
    owner        = string
    location     = string
    format       = string
    description  = string
    roles        = map(map(string))
    labels       = map(string)
    kms_key_name = string
  })
  
  default = {
      owner = "eric@xxxxxx"
      location = "asia-east1"
      format = "DOCKER"
      description = "Docker repository"
      roles = {
          myrole= {          
           members = "mark@xxxxxx"
           role = "artifactregistry.admin"
        }},
      labels = null
      kms_key_name = null
    }
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for your reply but throws the same error. I think the module does expect a map of maps as that's in the example but I don't know how to reflect that in the roles section..
@EricV. I updated the answer with the oposite change - update default value to match type.
@EricV. How did it go? Did the updated answer worked?
sorry for the late reply. This worked following the updated value. Thank you a million.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.