Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to enforce (single) quote around yml string value #22847

Closed
t638403 opened this issue Sep 19, 2019 · 6 comments
Closed

Unable to enforce (single) quote around yml string value #22847

t638403 opened this issue Sep 19, 2019 · 6 comments

Comments

@t638403
Copy link

t638403 commented Sep 19, 2019

Download Terraform

sudo mkdir /opt/terraform
cd /opt/terraform
sudo wget https://releases.hashicorp.com/terraform/0.12.9/terraform_0.12.9_linux_amd64.zip
sudo unzip terraform_0.12.9_linux_amd64.zip
echo "export PATH=\$PATH:/opt/terraform" >> ~/.zshrc

Current Terraform Version

Terraform v0.12.9
+ provider.helm v0.10.2
+ provider.kubernetes v1.9.0

Use-cases

I have this terraform resource for elasticsearch on kubernetes.

resource "helm_release" "elasticsearch" {
    name      = "some name"
    chart     = "elastic/elasticsearch"
    set {
        name = "roles.master"
        value = "true"
    }
...
}

The values.yaml for helm renders this as

...
roles:
   master: true
...

Unfortunately helm is unable to render this into the statefulset.yaml template.

Error: rpc error: code = Unknown desc = render error in "elasticsearch/templates/statefulset.yaml": template: elasticsearch/templates/statefulset.yaml:188:17: executing "elasticsearch/templates/statefulset.yaml" at <eq .Values.roles.mas...>: error calling eq: incompatible types for comparison

I have tested directly with helm and when I wrap the true value in single quotes (master: 'true') helm becomes able to render it into the statefulset.yaml template. However I can not find a way to enforce this using terraform set.

Attempted Solutions

I have tried:

1:

set {
        name = "roles.master"
        value = "true"
    }

which results in master: true.

2:

set {
        name = "roles.master"
        value = "${true}"
    }

which results in master: true

3:

set {
        name = "roles.master"
        value = "'${true}'"
    }

which results in master: '''true'''

4:

set {
        name = "roles.master"
        value = <<EOF
true
EOF
    }

which results in

master: |
    true

5:

set {
        name = "roles.master"
        value = "\\\\'${var.es_node_roleMaster}\\\\'"
    }

which results in master: \'true\'

Proposal

Some function quote(string) which will enforce a single quote around the string.

References

The helm template:
https://github.com/elastic/helm-charts/blob/master/elasticsearch/templates/statefulset.yaml

@teamterraform
Copy link
Contributor

Hi @t638403!

We've asked the bot to consider this a Helm provider bug because the Helm provider seems to be trying to present an abstraction over the YAML but that abstraction is leaking here due to the lack of quoting. Having the Helm provider handle this quoting automatically would then provide the abstraction as intended, avoiding the need for the user to worry about how this value will ultimately be encoded in YAML.

Our bot will close this issue and open a new issue with the same content on your behalf in the Helm provider repository.

@teamterraform
Copy link
Contributor

(With that said, Terraform already has a function jsonencode which can produce a JSON-quoted version of a string value. Since YAML is a superset of JSON, jsonencode should be a sufficient workaround for the moment, with the caveat that if this bug is later fixed upstream you'll probably end up with a double-quoted value.)

@ghost
Copy link

ghost commented Sep 19, 2019

This issue has been automatically migrated to hashicorp/terraform-provider-helm#341 because it looks like an issue with that provider. If you believe this is not an issue with the provider, please reply to hashicorp/terraform-provider-helm#341.

@davidschrooten
Copy link

davidschrooten commented Sep 20, 2019

try https://www.terraform.io/docs/configuration/functions/format.html

e.g. in terraform console:

> format("'%v'", true)
'true'

@t638403
Copy link
Author

t638403 commented Sep 23, 2019

@teamterraform and @davidq2q thanks for the response!

Finally I was able to use set_string in stead of set:

set_string {
        name = "roles.master"
        value = true   
}

@ghost
Copy link

ghost commented Oct 20, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Oct 20, 2019
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants