列表的地形插值?



我正在尝试使用terraform gitlab-provider。我想要以列表的形式传递地图并在模块中调用它们。

我怎样才能做到这一点?是否有任何可以在此处使用的插值语法?

# names and can_create_groups
variable "names" {
type    = "list"
default = [
{
"name"             = "test"
"username"         = "test"
"email"            = "test@xxxxx.com"
"project_limit"    = "100"
"can_create_groups"= "false"
"is_admin"         = "false"
},
{
"name"             = "test2"
"username"         = "tetst.2"
"email"            = "test2@xxxx.com"
"project_limit"    = "100"
"can_create_groups"= "true"
"is_admin"         = "false"
}
]
}

GIT - 用户

resource "gitlab_user" "user" {
name             = "${element(var.names,count.index)}"
username         = "${element(var.names,count.index)}"
password         = "dummypassword"
email            = "${element(var.names,count.index)}"
is_admin         = "${element(var.names,count.index)}"
projects_limit   = "${element(var.names,count.index)}"
can_create_group = "${element(var.names,count.index)}"
count            = 2
}

错误: 错误: gitlab_user.user: 发生 2 个错误:

  • gitlab_user.user[0]: element: element(( 只能与平面列表一起使用,此列表包含 map 类型的元素:

${element(var.names,count.index(} * gitlab_user.user[1]: element: element(( 只能与平面列表一起使用,此列表包含 map 类型的元素:

${element(var.names,count.index(}

您可以使用一些内置的 Terraform 函数来使其正常工作

resource "gitlab_user" "user" {
name             = "${lookup(var.names, element(keys(var.names), count.index))}"
password         = "dummypassword"
etc, etc, etc
count            =  "${length(keys(var.names))}"
}
resource "gitlab_user" "user" {
name             = "${lookup(var.gitlab_users[count.index], "name")}"
username         = "${lookup(var.gitlab_users[count.index], "username")}"
password         = "dummypassword"
email            = "${lookup(var.gitlab_users[count.index], "email")}"
is_admin         = "${lookup(var.gitlab_users[count.index], "is_admin")}"
projects_limit   = "${lookup(var.gitlab_users[count.index], "projects_limit")}"
can_create_group = "${lookup(var.gitlab_users[count.index], "can_create_groups")}"
count            = "${length(var.gitlab_users)}"
}

相关内容

  • 没有找到相关文章

最新更新