1

Is there a option to set a defaults and description for nested variables in terraform?

Example:

variable "example_page_rule"{
      type = list(object({
            level = string,
            tags = string,
            prefix = string    
      }))   
}

This can be achieved ?

variable "example_page_rule"{
          type = list(object({
                level = string, default = "1", description = "debug level 0-7"
                tags = string, default = {}, description = "tags"
                prefix = string, default = "abc", description = "some description"    
          }))   
    }
Vidya
  • 179
  • 1
  • 2
  • 12

1 Answers1

1

You could set default values for your map with new, experimental feature defaults of TF. Its different syntax, but same outcome. There are no descriptions though.

If you don't want to use the experiential feature, you would have to develop custom code for handling default values, like any other TF code that does it these days. One example of this is here.

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • Description can be added in custom code? in example defaults got assigned but not description for each value – Vidya Aug 04 '21 at 02:46
  • @Vidya There is no description for individual fields. You only have [description for the entire variable](https://www.terraform.io/docs/language/values/variables.html#input-variable-documentation). – Marcin Aug 04 '21 at 02:47