terraform-provider-helm: error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go value of type

Terraform, Provider, Kubernetes and Helm Versions

Terraform version: 1.1.7
Provider version: 2.4.1
Kubernetes version: 1.20

Affected Resource(s)

  • helm_release
  • helm_repository

Terraform Configuration Files

resource "kubernetes_namespace" "cluster-autoscaler" {
  count = var.ca_arn == null ? 0 : 1
  metadata {
    name = "cluster-autoscaler"
  }
}

resource "helm_release" "cluster-autoscaler" {
  count     = var.ca_arn == null ? 0 : 1
  name      = "cluster-autoscaler"
  namespace = "cluster-autoscaler"

  repository = "https://kubernetes.github.io/autoscaler"
  chart      = "cluster-autoscaler"

  values = ["ca-values.yml"]

  set {
    name  = "autoDiscovery.clusterName"
    value = var.cluster_name
  }
  set {
    #escapes required to break interpolation of fields for domain style annotations
    name  = "rbac.serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn"
    value = var.ca_arn
  }
  set {
    name  = "awsRegion"
    value = var.region
  }
}

ca-values.yaml:

extraArgs:
  logtostderr: true
  stderrthreshold: info
  v: 4
  skip-nodes-with-local-storage: false
  expander: least-waste
  balance-similar-node-groups: true  
  skip-nodes-with-system-pods: false 
rbac:
  create: true
  pspEnabled: false
  serviceAccount:
    create: true
    name: cluster-autoscaler
replicaCount: 1
resources: 
  limits:
    cpu: 100m
    memory: 600Mi
  requests:
    cpu: 100m
    memory: 600Mi
securityContext:
  runAsNonRoot: true
  runAsUser: 65534
  fsGroup: 65534

tfvars

Debug Output

Nothing related could be found in the log.

Panic Output

No panic was found

Steps to Reproduce

  1. terraform apply

set:

ca_arn: to any string region: set it to any valid aws region or probably anything at all cluster-name: set it to anything

Expected Behavior

cluster-autoscaler should be deployed

Actual Behavior

 ---> error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go value of type map[string]interface {} ca-values.yml
│
│   helm_release.cluster-autoscaler[0],

Important Factoids

AWS EKS is used here.

If I disable values attribute and run an apply, it works, enabling values attribute then and re-running also works. It only fails when running against a vanilla setup

References

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 23
  • Comments: 17

Most upvoted comments

I was having the same issue. But set the annotations values like this and it worked.

  set {
      name = "serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn"
      value = "${aws_iam_role.this.arn}"
      type = "string"
  }

@blue928 I have notifications turned off here, but the solution was to do it like this:

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

This can be fixed by setting: tostring(var.ca_arn)

still getting the same error

@gothrek22 Could you please paste your solution? I’m also getting this error and consider it a bug. No matter what I do, I cannot get annotations to work.

I’m using the Bitnami Drupal helm chart, and per the helm chart documentation for Drupal, the default value for ingress.annotations is {}

set {
    name = "ingress.annotations"
    value = "cert-manager.io/cluster-issuer: letsencrypt-prod"
  }

or

set {
    name = "ingress.annotations.cert-manager.io/cluster-issuer"
    value = "letsencrypt-prod"
  }

The above does not work. I get this error: (note, I’ve tried every way to escape it that I know as well)

Error: YAML parse error on drupal/templates/ingress.yaml: error unmarshaling JSON: while decoding JSON: json: cannot unmarshal array into Go struct field .metadata.annotations of type map[string]string

The bitnami default values.yaml file has the correct annotations syntax for let’s encrypt, so when I try to use the values block I still get errors:

  values = [
    "${path.module}/values.yaml"
  ]

#### bitnami default yaml section
ingress:
...
   annotations:
     kubernetes.io/ingress.class: nginx
     cert-manager.io/cluster-issuer: cluster-issuer-name
  

That throws this error:

Error: ---> error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go value of type map[string]interface {} .terraform/modules/helm-app-module/values.yaml

If the default values in a bitnami chart throw an error, and that’s not a bug, what are the correct ways to set these types of values via the set{} block in helm_release or via values.yaml?