如何使用 helm 提供程序覆盖 terraform 中的默认图表值?

问题描述 投票:0回答:1

我们在 Terraform 中使用 helm 提供程序来配置 istio 入口网关,该网关在后端使用此图表

下面是配置相同内容的 terraform 代码片段。请帮助覆盖默认图表值以创建内部负载均衡器而不是默认的外部负载均衡器。我们知道可以通过更新清单文件中的注释来完成。但不确定如何在 terraform 代码片段中执行相同的操作?

terraform {
  required_providers {
    helm = {
      source = "hashicorp/helm"
      version = ">= 1.0.0"
    }
  }
}

provider "helm" {
  kubernetes {
    config_path = "${var.kubeconfig_file}"
  }
}

resource "helm_release" "istio-ingress" {
  repository        = local.istio_charts_url
  chart             = "gateway"
  name              = "istio-ingress-gateway"
  namespace         = kubernetes_namespace.istio_system.metadata.0.name
  version           = ">= 1.12.1"
  timeout           = 500
  cleanup_on_fail   = true
  force_update      = false
  depends_on        = [helm_release.istiod]
}
kubernetes terraform kubernetes-helm istio
1个回答
5
投票

您可以使用

set
参数块 (https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release#set) 或
values
参数 (https: //registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release#values) 资源
helm_release
覆盖原始设置
values.yaml

应该看起来像:

resource "helm_release" "istio-ingress" {
  repository        = local.istio_charts_url
  chart             = "gateway"
  name              = "istio-ingress-gateway"
  namespace         = kubernetes_namespace.istio_system.metadata.0.name
  version           = ">= 1.12.1"
  timeout           = 500
  cleanup_on_fail   = true
  force_update      = false
  depends_on        = [helm_release.istiod]

  set {
    name  = "serviceAnnotations.cloud.google.com/load-balancer-type"
    value = "internal"
  }
}

resource "helm_release" "istio-ingress" {
  repository        = local.istio_charts_url
  chart             = "gateway"
  name              = "istio-ingress-gateway"
  namespace         = kubernetes_namespace.istio_system.metadata.0.name
  version           = ">= 1.12.1"
  timeout           = 500
  cleanup_on_fail   = true
  force_update      = false
  depends_on        = [helm_release.istiod]

  values = [
    file("${path.module}/custom-values.yaml")
  ]
}

并在代码中放置一个

custom-values.yaml
文件。

这篇文章解释得很好: https://getbetterdevops.io/terraform-with-helm/

希望这有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.