potatopotato
potatopotato

Reputation: 1174

Terragrunt or Terraform define an object in variable with not known number of key/values

I have a list of objects (buckets) that I'd like to create with my module

  buckets = [
    {
      name                        = "my_bucket",
      location                    = "EU"
      storage_class               = "STANDARD"
      force_destroy               = false
      versioning                  = true
      uniform_bucket_level_access = false
      public_bucket               = true
      labels = {
        "app" = "my_app"
      }

some fields are required, (like name and location) some are not and I gave them default value in resources if not provided in here; - the full module and everything is operational, but it worked without defining 'type' in variable - so it just took everything, but my question is how do I define that object in variable block ?

variable "buckets" {
  #type = list(object()) #? 
  type = set(object({
      name                        = string
      location                    = string
      storage_class               = string
      force_destroy               = boolean
      versioning                  = boolean
      uniform_bucket_level_access = boolean
      public_bucket               = boolean
      labels = object({
        string = string # ?
      })
  }))
}

how would and object look like that has optional fields

Upvotes: 0

Views: 2193

Answers (1)

Related Questions