将列表传递给Helm使用Terraform的`helm_release`提供程序。

huangapple go评论90阅读模式
英文:

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文件,其中包含一组允许的群组

  1. app_groups = jsondecode(file("../../work/resources/gke/params/access_auths.json")).accessgroups[var.project][0].app_group
  2. }
  3. output "app_groups" {
  4. value = local.app_groups
  5. }

结果 -

  1. "bigquery-team",
  2. "devops-team",
  3. ]

main.tf -

  1. name = "oauth2proxy"
  2. chart = "../charts/oauth2proxy"
  3. namespace = kubernetes_namespace.oauth2proxy.metadata.0.name
  4. set {
  5. name = "app_groups[0]"
  6. value = "${local.app_groups}"
  7. }
  8. values = [
  9. templatefile("../charts/oauth2proxy/oauth2proxy_values.yaml", {
  10. projectID = var.project
  11. clusterName = var.clusterName
  12. })
  13. ]
  14. }

在helm deployment.yml中,它需要在启动容器时进入-args -

  1. - --allowed-group="{{ $v }}"
  2. {{ end }}

但我得到了错误:

  1. on main.tf line 129, in resource "helm_release" "oauth2proxy":
  2. 129: value = "${local.app_groups}"
  3. ────────────────
  4. local.app_groups is tuple with 2 elements
  5. 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

  1. locals {
  2. app_groups = jsondecode(file("../../work/resources/gke/params/access_auths.json")).accessgroups[var.project][0].app_group
  3. }
  4. output "app_groups" {
  5. value = local.app_groups
  6. }

Gives -

  1. app_groups = [
  2. "bigquery-team",
  3. "devops-team",
  4. ]

main.tf -

  1. resource "helm_release" "oauth2proxy" {
  2. name = "oauth2proxy"
  3. chart = "../charts/oauth2proxy"
  4. namespace = kubernetes_namespace.oauth2proxy.metadata.0.name
  5. set {
  6. name = "app_groups[0]"
  7. value = "${local.app_groups}"
  8. }
  9. values = [
  10. templatefile("../charts/oauth2proxy/oauth2proxy_values.yaml", {
  11. projectID = var.project
  12. clusterName = var.clusterName
  13. })
  14. ]
  15. }

In helm deployment.yml it needs to go into the -args when starting the container -

  1. {{ range $v := .app_groups }}
  2. - --allowed-group="{{ $v }}"
  3. {{ end }}

But i get

  1. Error: Incorrect attribute value type
  2. on main.tf line 129, in resource "helm_release" "oauth2proxy":
  3. 129: value = "${local.app_groups}"
  4. ────────────────
  5. local.app_groups is tuple with 2 elements
  6. 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()

  1. set {
  2. name = "app_groups"
  3. value = "{${join(",", local.app_groups)}}"
  4. }

这应该可以解决问题,以{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():

  1. set {
  2. name = "app_groups"
  3. value = "{${join(",", local.app_groups)}}"
  4. }

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.

huangapple
  • 本文由 发表于 2023年3月31日 23:38:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75900361.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定