简体   繁体   English

Golang 中的 Terraform 列表 object

[英]Terraform list object in Golang

I am trying to represent Terraform list of objects in Go ie我试图代表 Go 中的objects列表 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)
  }))

Are rolearn and others basic types or composite ones eg a map?rolearn和其他基本类型还是复合类型,例如 map? And so is map_roles just a struct of strings and slice of string (list), or is it a struct of maps? map_roles 只是一个字符串结构和字符串切片(列表),还是一个映射结构?

Terratest converts variable values given in terraform.Options to -var command line arguments using its internal function toHclString . Terratest 使用其内部 function toHclString 将-var terraform.OptionstoHclString

From reading through the implementation of that function and the other functions it calls, it seems like it will convert a Go []interface{} value into Terraform tuple syntax and a Go map[string]interface{} into Terraform object syntax, so a valid value for the type constraint shown might look like this: From reading through the implementation of that function and the other functions it calls, it seems like it will convert a Go []interface{} value into Terraform tuple syntax and a Go map[string]interface{} into Terraform object syntax, so a显示的类型约束的有效值可能如下所示:

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

Based on my read of the code (note: I didn't actually test it ) I would expect that to generate a -var argument value like this:根据我对代码的阅读(注意:我实际上并没有测试它),我希望生成一个像这样的-var参数值:

-var map_roles='[{"rolearn" = "foo", "username" = "bar", "groups" = ["baz"]},{"rolearn" = "boop", "username" = "beep", "groups" = ["blurp"]}]'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM