terraform how to describe variable type with changing keys in object

Viewed 402

I've got an ever changing list of objects as variable and wanted to know how to properly describe its type

variable "lifecycle_rules" {
  type = set(object({
#    set(object({
#      action = map(string)
#      condition = map(string)
#    }))
  }))
  default = [
    {
    first = [
      {
        condition = {
          age = "1"
        }
        action = {
          type = "Delete"
        }
      },
      {
        condition = {
          age = "2"
        }
        action = {
          type = "Delete"
        }
      }
    ]},
    {
     second = [
      {
        condition = {
          age = "3"
        }
        action = {
          type = "Delete"
        }
      },
      {
        condition = {
          age = "4"
        }
        action = {
          type = "Delete"
        }
      }
    ]
  }
  ]
}

Here should be line with smth like this string = set(object({... the first and second are always changing, so key value should be string but can't really set it - any other thoguhts, how to write type for the default below ?

1 Answers

You are almost there. I think the correct one is:

  type = set(
      map(
        set(
          object({condition = map(string), 
                  action    = map(string)})
           )
       )
     )

In the map you don't specify attributes, as they can be different. In the most inner one you have object as condition and action are constant.

Related