【问题标题】:Creation of Terraform Variables for Nested Objects为嵌套对象创建 Terraform 变量
【发布时间】:2022-01-12 19:45:09
【问题描述】:

以下是我们的云中使用的 terraform 模块的变量声明,这些变量的输入是通过其中一种自动化解决方案获得的。现在,我想重现一个问题,我想从下面的变量定义中创建一个 tfvars 文件。

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
        })
      })
    })
  })
}

我已经尝试过这样的事情,但是对于下一个嵌套的反对,我不太确定如何放下这些。有人可以指导或提供一些指示吗?

terraform.tfvars:

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

【问题讨论】:

    标签: azure terraform terraform-provider-azure


    【解决方案1】:

    var.docker 的有效值示例如下:

    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"
            }      
         }       
      }    
    
    }
    
    

    【讨论】:

      猜你喜欢
      • 2019-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多