hashicorp / terraform-provider-helm

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

Incorrect indentation in rendered tf map variable #1526

Open ikarlashov opened 3 weeks ago

ikarlashov commented 3 weeks ago

Terraform, Provider, Kubernetes and Helm Versions

Terraform version: v1.3.9
Provider version: 2.16.1
Kubernetes version: 1.28

Affected Resource(s)

helm_release

Terraform Configuration Files

locals {
  ebs_tags = {
    a = "one"
    b = "two"
    c = "three"
  }
}

helm_release "ebs_csi_driver" {
...
values = [
....
  extraVolumeTags:
    ${yamlencode(local.ebs_tags)}
....
]
}

Debug Output

│ Error: ---> error converting YAML to JSON: yaml: line 6: did not find expected key controller:
│   extraVolumeTags:
│     "a": "one"
│ "b": "two"
│ "c": "three"

Steps to Reproduce

Declare a map of strings in terraform and pass it to helm_release.

Expected Behavior

controller:
  extraVolumeTags: 
     a: one
     b: two
     c: three

Actual Behavior

   extraVolumeTags:
     "a": "one"
 "b": "two"
 "c": "three"

Important Factoids

I also tried to declare a map of strings in different ways, including passing a YAML formatted map with <<YAML. Additionally, I rendered the map inside values by iterating through the Terraform map variable. However, nothing worked. The outcome is always the same: only the first line of the map is correctly indented. Also:

variable "ebs_tags" {
  type = map(string)
  default = {
    a = "one"
    b = "two"
    c = "three"
  }
}

# https://github.com/kubernetes-sigs/aws-ebs-csi-driver
resource "helm_release" "ebs_csi_driver" {
  count = var.enable_ebs_csi_driver ? 1 : 0

  name        = "aws-ebs-csi-driver"
  namespace   = "kube-system"
  chart       = "aws-ebs-csi-driver"
  version     = "2.35.1"
  repository  = "https://kubernetes-sigs.github.io/aws-ebs-csi-driver"
  max_history = 5

  set {
    name = "controller.extraVolumeTags"
    value = "${jsonencode(var.ebs_tags)}"
  }

Results in:

│ Error: YAML parse error on aws-ebs-csi-driver/templates/controller.yaml: error converting YAML to JSON: yaml: line 81: did not find expected '-' indicator
│ 
│   with module.eks.helm_release.ebs_csi_driver[0],
│   on ../../k8s-system-aws-ebs-csi-driver.tf line 100, in resource "helm_release" "ebs_csi_driver":
│  100: resource "helm_release" "ebs_csi_driver" {
│ 

And rendered as:

controller:
  extraVolumeTags:
  - '"a":"one"'
  - '"b":"two"'
  - '"c":"three"'

References

Helm template that renders extraVolumeTags dict.

Community Note

ikarlashov commented 3 days ago

Could someone please look into the issue?