terraform-provider-helm icon indicating copy to clipboard operation
terraform-provider-helm copied to clipboard

--set-file functionality

Open afedulov opened this issue 4 years ago • 11 comments
trafficstars

Description

Some charts explicitly rely on configuration being provided via the --set-file option:

https://github.com/helm/charts/blob/master/stable/grafana/templates/dashboards-json-configmap.yaml

There was already an issue with a proposed workaround, but as you can see in the example chart above, it is not universally applicable: https://github.com/hashicorp/terraform-provider-helm/issues/240

afedulov avatar Nov 23 '20 11:11 afedulov

I would really appreciate if someone could maybe provide some insights into how to workaround this limitation.

afedulov avatar Feb 16 '21 19:02 afedulov

@afedulov you could use the file function to work around this

aareet avatar Feb 17 '21 17:02 aareet

any update on this? i'm also running into this with data dog helm chart because they allow --set-file only.

nkorandla01 avatar Mar 12 '22 00:03 nkorandla01

Ran into this issue too. Surprised that the set_file is not supported yet. Does the helm provider has a totally different architecture than the helm itself? Otherwise, why is that, such a native feature is not supported yet? Would the internal of the set_file not be as simple as this:

  • use set_file like
    set_file {
        name = a.b
        file = <the-file-path>
    }
    
  • then the helm provider pass it to the helm just like we pass the following command option to the helm.
    --set-file "a.b=<the-file-path>"
    

That's it.

ckyoog avatar Apr 22 '22 21:04 ckyoog

Oh, just realized that the helm provider has never been working with file-path. Even for the values file, it also needs the user to make the values file inlined. Maybe this explains why the set_file has not been supported -- the helm provider doesn't know how to handle file-path, or intends not to.

ckyoog avatar Apr 22 '22 21:04 ckyoog

Hello,

Sorry to dig up this post but the issue is still opened and no solution found. For exemple, Linkerd requires need files for the installation.

helm install linkerd2 \
  --set-file identityTrustAnchorsPEM=ca.crt \
  --set-file identity.issuer.tls.crtPEM=issuer.crt \
  --set-file identity.issuer.tls.keyPEM=issuer.key \
  --set identity.issuer.crtExpiry=$exp \
  linkerd/linkerd2

What is the reason to not implement set-file in terraform provider?

Thank you and have a nice day!

Tchoupinax avatar Jun 26 '22 11:06 Tchoupinax

@afedulov you could use the file function to work around this

This works fine, thanks!

An example based on linkerd:

resource "kubernetes_namespace_v1" "linkerd" {
  metadata {
    annotations = {
      "linkerd.io/inject" = "disabled"
    }

    labels = {
      "linkerd.io/is-control-plane"          = "true"
      "config.linkerd.io/admission-webhooks" = "disabled"
      "linkerd.io/control-plane-ns"          = "linkerd"
    }

    name = "linkerd"
  }
}

resource "helm_release" "linkerd" {
  name       = "linkerd2"
  repository = "https://helm.linkerd.io/stable"
  chart      = "linkerd2"
  version    = "2.11.4"
  namespace  = kubernetes_namespace_v1.linkerd.metadata[0].name

  set {
    name  = "installNamespace"
    value = "false"
  }

  set {
    name  = "identityTrustAnchorsPEM"
    value = file("linkerd/ca.crt")
  }

  set {
    name  = "identity.issuer.tls.crtPEM"
    value = file("linkerd/issuer.crt")
  }

  set {
    name  = "identity.issuer.tls.keyPEM"
    value = file("linkerd/issuer.key")
  }
}

Note - terraform fails to install linkerd with helm if namespace is not create in advance.

kristjankullerkann avatar Jul 18 '22 07:07 kristjankullerkann

Hello,

I have the same need, but with non utf8 binary file(namely, a pdf file). Works fine with Helm's --set-file, but terraform provider's set complains :

set {
    name  = "app.document"
    value = file("document.pdf")
  }
Call to function "file" failed: contents of "document.pdf" are not valid UTF-8; use the filebase64 function to obtain the Base64 encoded contents or the
│ other file functions (e.g. filemd5, filesha256) to obtain file hashing results instead.

Any thought ?

julienmuller-forge avatar Jun 13 '23 14:06 julienmuller-forge

@julienmuller-forge Terraform has some built in functions you can try to convert file type: https://developer.hashicorp.com/terraform/language/functions

DigitalCreationsCo avatar Jun 26 '23 05:06 DigitalCreationsCo

how can i set one key to 3 value like below

OPTION 1: set { name = "env.plugins" value = "xxxx,yyyy,zzzz" type = "string" }

OPTION 2: set { name = "env.plugins" value = "{xxxx,yyyy,zzzz}" type = "string" }

OPTION 3: set { name = "env.plugins[0]" value = "XXXX" type = "string" } set { name = "env.plugins[1]" value = "YYYY" type = "string" } set { name = "env.plugins[2]" value = "ZZZZZ" type = "string" }

the above 3 options do not work correctly and i get error when i try to terraform apply

thank you

smtarslanturk avatar Jul 28 '23 22:07 smtarslanturk

Function file does not always work, see issue

Anbu42 avatar Sep 01 '23 08:09 Anbu42