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

Handle map types better for toJson #84

Open
yorinasub17 opened this issue Dec 7, 2021 · 0 comments
Open

Handle map types better for toJson #84

yorinasub17 opened this issue Dec 7, 2021 · 0 comments
Labels
bug Something isn't working p:high priority

Comments

@yorinasub17
Copy link
Contributor

Describe the bug
For certain map types, toJson fails to render valid json.

To Reproduce

boilerplate.yml

variables:
  - name: FirewallRules
    description: List of firewall rule.
    type: list
    default: [] 

_input_vars.yml

FirewallRules:
  - "name"                   : "densbx-allow-internal"
    "deny"                   : [ ]
    "log_config":
      - "metadata : INCLUDE_ALL_METADATA"
    "allow":
      - protocol: "tcp"
        ports:
          - 22
          - 443
      - protocol: "udp"
        ports:
          - 53
      - protocol: "icmp"
        ports:
  - "name"                   : "densbx-allow-internal"
    "deny"                   : [ ]
    "log_config":
      - "metadata : INCLUDE_ALL_METADATA"
    "allow":
      - protocol: "tcp"
        ports:
          - 22
          - 443
      - protocol: "udp"
        ports:
          - 53
      - protocol: "icmp"
        ports:

template.hcl

inputs = {
  rules = [    
    {{- range $rule, $config := .FirewallRules }}
    {
      {{ range $key, $value := $config }}      
      {{ $key }} = jsondecode("{{ $value | toJson }}")     
      {{- end }}
    },
    {{- end -}}
  ]
}

Expected behavior
When rendering this out, we should get valid json output for each entry, but the allow key results in an empty list:

actual rendered:

inputs = {
  rules = [
    {
      allow = jsondecode("")      
      deny = jsondecode("[]")      
      log_config = jsondecode("["metadata : INCLUDE_ALL_METADATA"]")      
      name = jsondecode(""densbx-allow-internal"")
    },
    {
      allow = jsondecode("")      
      deny = jsondecode("[]")      
      log_config = jsondecode("["metadata : INCLUDE_ALL_METADATA"]")      
      name = jsondecode(""densbx-allow-internal"")
    },]
}

Currently we can work around it by using yaml at the top e.g.

inputs = {
  rules = yamldecode(<<EOF
{{ .FirewallRules | toYaml }}
EOF
)
}

But we should figure out why json rendering doesn't work.

@yorinasub17 yorinasub17 added the bug Something isn't working label Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p:high priority
Projects
None yet
Development

No branches or pull requests

2 participants