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

set JSON with type=string

Open jfcoz opened this issue 4 years ago • 11 comments

Terraform Version and Provider Version

Terraform v0.12.29
+ provider.helm v1.3.2

Provider Version

+ provider.helm v1.3.2

Affected Resource(s)

  • helm_release

Terraform Configuration Files

  set {
          name  = "podAnnotations.ad\\.datadoghq\\.com/velero\\.instances"
          type  = "string"
          value = "[{\"metrics\":[\"velero*\"],\"namespace\":\"velero\",\"prometheus_url\":\"http://%%host%%:8085/metrics\"}]"
}

Debug Output

module.velero_backup.helm_release.velero: Modifying... [id=velero]

Error: failed parsing key "podAnnotations.ad\\.datadoghq\\.com/velero\\.instances" with value '[{"prometheus_url": "http://%%host%%:8085/metrics", "namespace": "velero", "metrics": ["velero*"]}]', key " \"namespace\": \"velero\"" has no value (cannot end with ,)

Expected Behavior

Provider should only use value as string and not try to parse it.

Workaround

Replace comma like in https://github.com/hashicorp/terraform-provider-helm/issues/330#issuecomment-544706935

References

  • https://github.com/hashicorp/terraform-provider-helm/issues/435
  • https://github.com/hashicorp/terraform-provider-helm/issues/330#issuecomment-544706935

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

jfcoz avatar Nov 09 '20 16:11 jfcoz

Thanks for opening this @jfcoz. This looks like a problem with the strvals package that Helm provides – we just call through to that package to parse the set operations in the the format of key=value that is used on the CLI.

I was able to reproduce this on the helm cli too:

helm install test-rls bitnami/apache --set-string 'podAnnotations.ad\.datadoghq\.com/velero\.instances=[{"metrics":["velero*"],"namespace":"velero","prometheus_url":"http://%%host%%:8085/metrics"}]'
Error: failed parsing --set-string data: key "\"namespace\":\"velero\"" has no value (cannot end with ,)

jrhouston avatar Nov 18 '20 21:11 jrhouston

I have the same issue as this trying to set a json string for backend-config on service for google ingress. I found putting a space in the front of the string allows it to be accepted and doesn't impact the annotation.

set { type = "auto" name = "controller.service.annotations.beta\.cloud\.google\.com/backend-config" # this has space because of provider bug and how it treats json # https://github.com/hashicorp/terraform-provider-helm/issues/618 # luckily it doens't seem to have negative impact on ingress creation # having a space in the annotation value = " {"ports": {"443": "cloud-armor-${var.ingress_class_suffix}-backend-config"}}" }

mlapish avatar Nov 19 '20 13:11 mlapish

Issue https://github.com/hashicorp/terraform-provider-helm/issues/669 also concerns the same problem. Just adding here for linking to the active issue with a workaround.

kaskavalci avatar May 04 '21 15:05 kaskavalci

I have found the same issue trying to set a JSON. adding a space does not work anymore :(

koalalorenzo avatar May 27 '21 12:05 koalalorenzo

Neither adding space or https://github.com/hashicorp/terraform-provider-helm/issues/330#issuecomment-544706935 works for me. In our case the value is sensitive so setting as values is not an optimal workaround either.

E: Actually, when I use both workarounds together it goes trough: value = " ${replace(file("${path.root}/some-json.json"), ",", "\\,")}"

villesau avatar Aug 12 '21 16:08 villesau

Unfortunately I have the same problem, has anyone here already found a solution?

dev-ago avatar Oct 25 '21 21:10 dev-ago

Marking this issue as stale due to inactivity. If this issue receives no comments in the next 30 days it will automatically be closed. If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. This helps our maintainers find and focus on the active issues. Maintainers may also remove the stale label at their discretion. Thank you!

github-actions[bot] avatar Nov 15 '22 00:11 github-actions[bot]

Still valid.

villesau avatar Nov 15 '22 07:11 villesau

Still valid. There are two problems here: the one with the braces (used to pass the lists), which can be resolved by initial space or escaping the braces and the one with comma (which is used to pass multiple values at once), which can be resolved by escaping the comma. In my case

set {
      name = "cassandra.replication"
      value = replace(var.cassandra_replication, "/([}{,])/", "\\$1") 
}

saved the day. The problem is that such behavior is caused by helm, giving an option to pass a collection or multiple values as a command line parameter. It is supposed to be so and even is described in the The Format Limitations of --set documentation section. I can propose, that type="string" could have not just convert the values to string, but automatically escape the curly braces and commas.

eoneoff avatar Feb 03 '23 14:02 eoneoff

thanks @eoneoff, this worked!

adrian-gierakowski avatar May 08 '23 16:05 adrian-gierakowski

As explained by @eoneoff this is pretty much how helm behave, when using --set it is not parsing strings how we are used to.

A full discussion can be found there https://github.com/helm/helm/issues/4030 and another option has been created to solve this issue, you need to use the --set-literal, if this provider could implement this option as well that would allow anybody to set multiple values easily with a big json string or using jsonencode like so:

set {
  name = "something"
  value = jsonencode([
    {
      stuff = "content"
      other_stuff = ["wow"]
    }
  ])
}

Vedrillan avatar Dec 27 '23 14:12 Vedrillan