地形变量中的地图内的地图 [英] Map within a map in terraform variables

查看:31
本文介绍了地形变量中的地图内的地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道是否有可能用代码片段来表示我是否可以在 terraform 变量的地图变量中创建地图变量?

Does anyone know if it's possible with possibly code snipits representing whether I can create a map variable within a map variable in terraform variables?

variable "var" {
  type = map
  default = {
    firstchoice = {
      firstAChoice ="foo"
      firstBChoice = "bar"
    }
    secondchoice = {
      secondAChoice = "foobar"
      secondBChoice = "barfoo"
    }
  }
}

如果有人对这是否可行或任何详细说明的文档有任何见解,那就太好了.

If anyone has any insight to whether this is possible or any documentation that elaborates that would be great.

推荐答案

是的,可以将地图变量作为地图变量键的值.您的变量只需要正确的缩进.此外,我正在尝试访问该变量.

Yes, it's possible to have map variable as value of map variable key. Your variable just needed right indentation. Also I am putting ways to access that variable.

variable "var" {
  default = {
    firstchoice = {
      firstAChoice = "foo"
      firstBChoice = "bar"
    }

    secondchoice = {
      secondAChoice = "foobar"
      secondBChoice = "barfoo"
    }
  }
}

要访问地图键的整个地图值firstchoice,您可以尝试以下

To access entire map value of a map key firstchoice, you can try following

value = "${var.var["firstchoice"]}"

output:
{
  firstAChoice = foo
  firstBChoice = bar
}

要访问该映射键的特定键(例如firstAchoice),您可以尝试

To access specific key of that map key (example firstAChoice), you can try

value = "${lookup(var.var["firstchoice"],"firstAChoice")}"

output: foo

这篇关于地形变量中的地图内的地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆