我正在尝试使用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"
}
]
}
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个错误:
$ {element(var.names,count.index)} * gitlab_user.user [1]:element:element()仅可用于平面列表,此列表包含以下类型的map元素:
$ {element(var.names,count.index)}
答案 0 :(得分:1)
您可以使用一些built in Terraform functions使其正常工作
resource "gitlab_user" "user" {
name = "${lookup(var.names, element(keys(var.names), count.index))}"
password = "dummypassword"
etc, etc, etc
count = "${length(keys(var.names))}"
}
答案 1 :(得分:0)
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)}"
}