英文:
Pass list to helm using terraform helm_release provider
问题
Ive看到了这个和另一个类似的问题,但无法让它工作。https://stackoverflow.com/questions/71754003/using-terraforms-helm-release-how-do-i-set-array-or-list-values
我的列表来自一个JSON文件,其中包含一组允许的群组
app_groups = jsondecode(file("../../work/resources/gke/params/access_auths.json")).accessgroups[var.project][0].app_group
}
output "app_groups" {
value = local.app_groups
}
结果 -
"bigquery-team",
"devops-team",
]
main.tf -
name = "oauth2proxy"
chart = "../charts/oauth2proxy"
namespace = kubernetes_namespace.oauth2proxy.metadata.0.name
set {
name = "app_groups[0]"
value = "${local.app_groups}"
}
values = [
templatefile("../charts/oauth2proxy/oauth2proxy_values.yaml", {
projectID = var.project
clusterName = var.clusterName
})
]
}
在helm deployment.yml中,它需要在启动容器时进入-args -
- --allowed-group="{{ $v }}"
{{ end }}
但我得到了错误:
on main.tf line 129, in resource "helm_release" "oauth2proxy":
129: value = "${local.app_groups}"
────────────────
│ local.app_groups is tuple with 2 elements
│ Inappropriate value for attribute "value": string required.
问题是,它是一个元组,我希望它仍然是元组,但我不知道如何告诉terraform或helm它应该是一个元组。
我尝试过各种不同的"set"和"dynamic set",但都没有取得进展。
英文:
Ive seen this and another question similar, but cannot get it to work https://stackoverflow.com/questions/71754003/using-terraforms-helm-release-how-do-i-set-array-or-list-values
My list is coming from a json file which is a list of allowed groups
locals {
app_groups = jsondecode(file("../../work/resources/gke/params/access_auths.json")).accessgroups[var.project][0].app_group
}
output "app_groups" {
value = local.app_groups
}
Gives -
app_groups = [
"bigquery-team",
"devops-team",
]
main.tf -
resource "helm_release" "oauth2proxy" {
name = "oauth2proxy"
chart = "../charts/oauth2proxy"
namespace = kubernetes_namespace.oauth2proxy.metadata.0.name
set {
name = "app_groups[0]"
value = "${local.app_groups}"
}
values = [
templatefile("../charts/oauth2proxy/oauth2proxy_values.yaml", {
projectID = var.project
clusterName = var.clusterName
})
]
}
In helm deployment.yml it needs to go into the -args when starting the container -
{{ range $v := .app_groups }}
- --allowed-group="{{ $v }}"
{{ end }}
But i get
Error: Incorrect attribute value type
on main.tf line 129, in resource "helm_release" "oauth2proxy":
129: value = "${local.app_groups}"
────────────────
│ local.app_groups is tuple with 2 elements
│ Inappropriate value for attribute "value": string required.
The thing is, it is a tuple, and want it to be a tuple, and i cant see how to tell terraform or helm that its supposed to be a tuple.
Ive tried various different "set" and "dynamic set" but not got anywhere with it.
答案1
得分: 5
value
期望是一个字符串。在 Helm 中,你可以使用{a, b, c}
语法来提供一个数组。要构建这个语法,你可以使用 join()
:
set {
name = "app_groups"
value = "{${join(",", local.app_groups)}}"
}
这应该可以解决问题,以{bigquery-team, devops-team}
的形式提供 app_groups
作为数组。我不确定是否需要引号,但这可以很容易地添加。
英文:
value
expects a string. In Helm you can provide an array using {a, b, c}
syntax. To build this syntax you can use join()
:
set {
name = "app_groups"
value = "{${join(",", local.app_groups)}}"
}
This should do the trick and provide app_groups
as an array in the form of {bigquery-team, devops-team}
. I am not sure if quoting is needed, but this could be added easily.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论