hashicorp / terraform-provider-helm

Terraform Helm provider
https://www.terraform.io/docs/providers/helm/
Mozilla Public License 2.0
998 stars 369 forks source link

How to set {} multiline string as a value? #1284

Open CiucurDaniel opened 1 year ago

CiucurDaniel commented 1 year ago

Terraform version, Kubernetes provider version and Kubernetes version

Terraform version: 1.6.2
Helm Provider version: 2.11.0
Kubernetes version: 1.27

Terraform configuration

resource "helm_release" "vault" {
  name      = "vault"
  chart     = local.vault_chart_path
  namespace = "vault"

  values = [
    file("./vault-values.yaml"),
    yamlencode({ chart_hash : local.chart_hash, })
  ]

  set {
    name = "server.ha.config"
    type = "string"
    value = templatefile("../helm-charts/vault-ha-config/vault-ha-config.hcl", {
      pgusername   = "someuser"
      pgpassword   = "somepassword"
      pgserverfqdn = "some server"
      pgdatabase   = "vault"
    })
  }

  depends_on = [kubernetes_manifest.vault_psql_init_job]
}

Values file portion which I try to overwrite:

server:
  ha:
    enabled: true
    replicas: 1

    # config is a raw string of default configuration when using a Stateful
    # deployment. Default is to use a Consul for its HA storage backend.
    # This should be HCL.
    config: |
      ui = true

      storage "postgresql" {
        connection_url = "postgres://{pgusername}:{pgpassword}@{pgfqdn}/{pgdatabase}"
        table = "vault_kv_store"
        ha_enabled = "true"
        ha_table = "vault_ha_locks"
      }

Question

As you can see under server.ha.config we have a HCL file. I try to replace that config with a file that I templated (in order to add the secrets) but it fails with error:

Error: error getting values: failed parsing key "server.ha.config" with value ui = true                                                                 
│                                                                                                                                                         
│ storage "postgresql" {                                                                                                                                  
│   connection_url = "postgres://{pgusername}:{pgpassword}{pgserverfqdn}/{pgdatabase}"                                                                    
│   table = "vault_kv_store"                                                                                                                              
│   ha_enabled = "true"                                                                                                                                   
│   ha_table = "vault_ha_locks"                                                                                                                           
│ }    

... rest of file                                                                                

How can we use set { } in order to set a multiline string in the values file?

CiucurDaniel commented 1 year ago

Ok so if I just try to set a single line string it works:

set {
    name = "server.ha.config"
    type = "string"
    value = "this works"
  }

Then the question still remains how can I set a multiline string value?

CiucurDaniel commented 1 year ago

This issue might be changed to a BUG it seems the provider has a hard time setting that value as it's a HCL. We should be able to use set to set different string values such as my use case or as another example setting the content of a config map data which a a script or HCL.

gnusey commented 7 months ago

@CiucurDaniel did you ever find a workaround?

pjanuario commented 3 months ago

FYI, I just stumbled on this while using the following:

Terraform version: 1.6.4
Helm Provider version: 2.14.0
Kubernetes version: 1.30

While running the following snippet

resource "helm_release" "this" {
  name        = var.release_name
  chart       = "chart-1.0.0.tgz"
  namespace   = var.namespace
  lint        = true
  atomic      = true

  set {
    name  = "config.app-conf.properties"
    type  = "string"
    value = <<EOF
hostname=xpto
user=user
password=pass
dbname=dbname
EOF
  }
}

The chart uses a template for secrets that expect the value app-conf to be a string but seems to arrive as map

│ Error: malformed chart or values:
│   templates/: template: chart/templates/secret-files.yaml:11:26: executing "chart/templates/secret-files.yaml" at <b64enc>: wrong type for value; expected string; got map[string]interface {}
│
│   with helm_release.this,
│   on main.tf line 11, in resource "helm_release" "this":
│   11: resource "helm_release" "this" {