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

optional function for list(object) in terraform

I am using below experimental block module in terraform settings block to use optional function .

experiments = [module_variable_optional_attrs]

I want to make variable urlMaps which is list(object) as optional . When I dont give urlMaps as a input to terraform.tfvars , I am expecting it send a null vaule. But it is giving exception mentioned below. If its not possible, is there any alternative to achieve this.

terraform.tfvars

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

urlMaps = [
  {
    hosts   = ["example.com"]
    paths   = ["/image"]
    service = "backend-service"
  }
]

Variables.tf

variable "urlMaps" {
  description = "Netowork endpoint group region"
  type        = optional(list(object({
    hosts     = list(string)
    paths     = list(string)
    service   = string
  })))
}

Exception

│ Error: Invalid type specification
│ 
│   on lb/variables.tf line 30, in variable "urlMaps":
│   30:   type        = list(optional(object({
│ 
│ Keyword "optional" is valid only as a modifier for object type attributes.

>Solution :

There are two posibilities:

  1. Add a default value to your urlMaps.
  2. Make it a normal list(map), not list(object).
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