Maryo David
Maryo David

Reputation: 579

Creation of Terraform Variables for Nested Objects

Following is the variable declaration for my terraform module which is used in our cloud and inputs for these variables are obtained via one of the automation solutions. Now, I would like to reproduce one of the issues for which I would like to create a tfvars file from the below variable definition.

variables.tf:

variable "docker" {
  type = object({
    image_name    = string
    image_location = string
    docker_ports = object({
      internal = number
      external    = number
    })
    rmodelling = object({
      lang  = object({
        version = number
        enabled    = bool
        policy = object({
          identification = string
        })
      })
      impl = object({
        version   = number
        enabled      = bool
        policy = object({
          identification = string
        })
      })
    })
  })
}

I have tried something like this, but for the next nested objected I am not quite sure on how those can be put down. Can someone guide or shed some pointers?

terraform.tfvars:

docker = {
  image_name = "Ubuntu 18.04"
  image_location = "https://registry.jd.com/ubuntu/<custom_location>"
  docker_ports = {
    internal = 80
    external = 443
  }
rmodelling = { ??
???

Upvotes: 5

Views: 10290

Answers (1)

Marcin
Marcin

Reputation: 238061

An example of a valid value for your var.docker is:

docker = {
  image_name = "Ubuntu 18.04"
  image_location = "https://registry.jd.com/ubuntu/<custom_location>"
  docker_ports = {
    internal = 80
    external = 443
  }
  rmodelling = { 
      lang = {
            version = 3
            enabled = true
            policy = {
              identification = "test"
            }
      }
      impl = {
        version = 4
        enabled = false
        policy = {
          identification = "test2"
        }      
     }       
  }    

}

Upvotes: 4

Related Questions