Skip to content

set JSON with type=string #618

Not planned
Not planned
@jfcoz

Description

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 #330 (comment)

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

Activity

jrhouston

jrhouston commented on Nov 18, 2020

@jrhouston
Contributor

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 ,)
mlapish

mlapish commented on Nov 19, 2020

@mlapish

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
# #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"}}"
}

kaskavalci

kaskavalci commented on May 4, 2021

@kaskavalci

Issue #669 also concerns the same problem. Just adding here for linking to the active issue with a workaround.

koalalorenzo

koalalorenzo commented on May 27, 2021

@koalalorenzo

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

villesau

villesau commented on Aug 12, 2021

@villesau

Neither adding space or #330 (comment) 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"), ",", "\\,")}"

dev-ago

dev-ago commented on Oct 25, 2021

@dev-ago

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

github-actions

github-actions commented on Nov 15, 2022

@github-actions

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!

villesau

villesau commented on Nov 15, 2022

@villesau

Still valid.

eoneoff

eoneoff commented on Feb 3, 2023

@eoneoff

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.

5 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      set JSON with type=string · Issue #618 · hashicorp/terraform-provider-helm