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

Special character with yamlencode with helm values

Open klemen-df opened this issue 2 years ago • 2 comments

Terraform, Provider, Kubernetes and Helm Versions

Terraform version: 1.1.9
Provider version: 2.5.1
Kubernetes version: aks v1.22.6

Affected Resource(s)

  • helm_release

Terraform Configuration Files

    set {
      name = "config"
      value = yamlencode({
        modules = {
          http_2xx = {
            prober  = "http"
            timeout = "5s"
            http = {
              valid_http_versions   = ["HTTP/2.0"]
              follow_redirects      = false
              preferred_ip_protocol = "ip4"
              method                = "HEAD"
              fail_if_not_ssl       = true
              enable_http2          = true
            }
          }
        }
      })
    }

Debug Output

      + set {
          + name  = "config"
          + value = <<-EOT
                "modules":
                  "http_2xx":
                    "http":
                      "enable_http2": true
                      "fail_if_not_ssl": true
                      "follow_redirects": false
                      "method": "HEAD"
                      "preferred_ip_protocol": "ip4"
                      "valid_http_versions":
                      - "HTTP/2.0"
                    "prober": "http"
                    "timeout": "5s"
            EOT
        }

Steps to Reproduce

  1. terraform apply

Expected Behavior

"modules":
  "http_2xx":
    "http":
      "enable_http2": true
      "fail_if_not_ssl": true
      "follow_redirects": false
      "method": "HEAD"
      "preferred_ip_protocol": "ip4"
      "valid_http_versions":
      - "HTTP/2.0"
    "prober": "http"
    "timeout": "5s"

Actual Behavior

|
  "modules":
    "http_2xx":
      "http":
        "enable_http2": true
        "fail_if_not_ssl": true
        "follow_redirects": false
        "method": "HEAD"
        "preferred_ip_protocol": "ip4"
        "valid_http_versions":
        - "HTTP/2.0"
      "prober": "http"
      "timeout": "5s"

klemen-df avatar Sep 08 '22 14:09 klemen-df

Hi @KlemenDanfoss – I'm not sure if I understand your issue. Is the special character you are referring to the pipe | at the start of your second snippet? This character is used in YAML for multi-line strings. By using yamlencode you are creating a string value that contains YAML rather than specifying YAML directly, so that might be why you are seeing it appear with the | character once it's rendered.

jrhouston avatar Sep 14 '22 04:09 jrhouston

Hi, yes, I'm talking about the pipe at the start of my second snippet.

So, basically, yamlencode is not the right way to go to define a 'multiline variable'?

klemen-df avatar Sep 14 '22 09:09 klemen-df

@KlemenDanfoss yeah, you might want to try using the values attribute instead, which accepts arbitrary YAML like this:

values = [
  yamlencode({ 
    config = {
      modules = {
        http_2xx = {
          prober  = "http"
          timeout = "5s"
          http = {
            valid_http_versions   = ["HTTP/2.0"]
            follow_redirects      = false
            preferred_ip_protocol = "ip4"
            method                = "HEAD"
            fail_if_not_ssl       = true
            enable_http2          = true
          }
        }
      }
    }
  })
]

jrhouston avatar Oct 12 '22 20:10 jrhouston

Hi,

thanks for the reply. I understand, I also found this.

If this doesn't 'work' then maybe we could add this to documentation (somehow) so other people don't get confused as well.

klemen-df avatar Oct 13 '22 05:10 klemen-df

I'm facing a related issue. I'm trying to parameterize a value in a chart which uses Helm provider.

Excerpt from my code:

  helm_config = {
    chart = ...
    values = [
      yamlencode({
        spawnerUiConfig = {
          spawnerFormDefaults = {
            image = {
              ...
            }
          }
        }
      })
    ]
  }

I'm trying to render the value like this:

apiVersion: v1
kind: ConfigMap
data:
  spawner_ui_config.yaml: |
    {{ .Values.spawnerUiConfig }}

But this is what is applied:

data:
  spawner_ui_config.yaml: |
    map[spawnerFormDefaults:map[image:map[

Desired output would be this:

data:
  spawner_ui_config.yaml: |
    spawnerFormDefaults:
      image:

Any ideas how to get rendered this YAML correctly?

nichoio avatar Nov 25 '22 14:11 nichoio

I'm facing a related issue. I'm trying to parameterize a value in a chart which uses Helm provider.

Excerpt from my code:

  helm_config = {
    chart = ...
    values = [
      yamlencode({
        spawnerUiConfig = {
          spawnerFormDefaults = {
            image = {
              ...
            }
          }
        }
      })
    ]
  }

I'm trying to render the value like this:

apiVersion: v1
kind: ConfigMap
data:
  spawner_ui_config.yaml: |
    {{ .Values.spawnerUiConfig }}

But this is what is applied:

data:
  spawner_ui_config.yaml: |
    map[spawnerFormDefaults:map[image:map[

Desired output would be this:

data:
  spawner_ui_config.yaml: |
    spawnerFormDefaults:
      image:

Any ideas how to get rendered this YAML correctly?

Hi, I'm facing same issue, did you solve it?

yossigilad avatar May 22 '23 10:05 yossigilad

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 May 22 '24 00:05 github-actions[bot]