0

我正在尝试代表objectsGo 中的 Terraform 列表,即

variable "map_roles" {
  description = "Additional IAM roles to add to the aws-auth configmap."
  type = list(object({
    rolearn  = string
    username = string
    groups   = list(string)
  }))

rolearn和其他基本类型或复合类型,例如地图?map_roles 只是一个字符串结构和字符串切片(列表),还是一个映射结构?

4

1 回答 1

1

Terratest使用其内部函数将给定的变量值转换terraform.Options为命令行参数。-vartoHclString

通过阅读该函数及其调用的其他函数的实现,它似乎会将 Go[]interface{}值转换为 Terraform 元组语法和 Gomap[string]interface{}转换为 Terraform 对象语法,因此显示的类型约束的有效值可能如下所示:

[]interface{}{
    map[string]interface{}{
        "rolearn":  "foo",
        "username": "bar",
        "groups":   []interface{"baz"},
    },
    map[string]interface{}{
        "rolearn":  "boop",
        "username": "beep",
        "groups":   []interface{"blurp"},
    },
}

根据我对代码的阅读(注意:我实际上并没有对其进行测试),我希望它会生成一个-var像这样的参数值:

-var map_roles='[{"rolearn" = "foo", "username" = "bar", "groups" = ["baz"]},{"rolearn" = "boop", "username" = "beep", "groups" = ["blurp"]}]'
于 2020-04-17T19:12:06.073 回答