hashicorp / terraform-provider-helm

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

postrender does not have any effect in helm_template #1472

Open RemkoMolier opened 2 weeks ago

RemkoMolier commented 2 weeks ago

Terraform, Provider, Kubernetes and Helm Versions

Terraform version: v1.9.5
Provider version: v2.15.0
Kubernetes version: N/A

Affected Resource(s)

Terraform Configuration Files

data "helm_template" "cilium" {
  namespace  = "kube-system"
  name       = "cilium"
  repository = "https://helm.cilium.io"
  chart      = "cilium"
  # renovate: datasource=helm depName=cilium registryUrl=https://helm.cilium.io
  version      = "1.16.0"
  kube_version = var.kubernetes_version
  api_versions = []
  values       = [file("values.yaml")]
  postrender {
    binary_path = "${path.module}/postrender"
  }
}

values.yaml:

---
ipam:
  mode: kubernetes
securityContext:
  capabilities:
    ciliumAgent: [CHOWN, KILL, NET_ADMIN, NET_RAW, IPC_LOCK, SYS_ADMIN, SYS_RESOURCE, DAC_OVERRIDE, FOWNER, SETGID, SETUID]
    cleanCiliumState: [NET_ADMIN, SYS_ADMIN, SYS_RESOURCE]
cgroup:
  autoMount:
    enabled: false
  hostRoot: /sys/fs/cgroup
k8sServiceHost: localhost
k8sServicePort: 7445
kubeProxyReplacement: true

postrender:

#!/bin/bash

yq '.metadata.annotations."meta.helm.sh/release-name"="cilium" | .metadata.annotations."meta.helm.sh/release-namespace"="kube-system" | .metadata.labels."app.kubernetes.io/managed-by" = "Helm"' <&0

Debug Output

N/A

Panic Output

N/A

Steps to Reproduce

  1. terraform plan

Expected Behavior

Postrender to be executed by the helm template and the output should have been adapted

Actual Behavior

Postrender is not executed by the helm template and the output is not adapted accordingly.

Important Factoids

N/A

References

N/A

Community Note

arybolovlev commented 1 week ago

Hi @RemkoMolier,

Does your post-render script work when you execute it with Helm CLI? What is the difference in output when you execute it with and without your post-render script?

Thanks.

RemkoMolier commented 1 week ago

Hi @arybolovlev,

yes it does. It, amongst side effects like reformatting and removal of comments , adds two annotations and one label to each of the configurations.

These are the first couple of lines from the diff (after formatting the outputs with yamlfmt):

`diff 1d0 < # Source: cilium/templates/cilium-agent/serviceaccount.yaml 6a6,10

annotations: meta.helm.sh/release-name: cilium meta.helm.sh/release-namespace: kube-system labels: app.kubernetes.io/managed-by: Helm `

Regards,

Remko

arybolovlev commented 1 week ago

Hi @RemkoMolier,

Thank you! It looks like we have the postrender attribute in the helm_template data source schema, but it has not been implemented.

RemkoMolier commented 2 days ago

Hi @arybolovlev thank you.

Is there anything I can do to help?

Regards,

Remko