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

Problems with nested YAML #424

Open
pop opened this issue Sep 22, 2021 · 3 comments
Open

Problems with nested YAML #424

pop opened this issue Sep 22, 2021 · 3 comments

Comments

@pop
Copy link

pop commented Sep 22, 2021

Description

Levant does not handle nested YAML well.

Given equivalent variables files in YAML and a JSON, Levant will successfully render with the JSON variables but fail to render with the JSON variables.

Relevant Nomad job specification file

Template file:

[[ range $serviceName := keys $.services ]]
[[ with $service := get $.services $serviceName ]]
  [[ $serviceName ]] health endpoint is [[ $service.health ]]
[[ end ]]
[[ end ]]

variables.json:

{
  "services": {
    "api": {
      "health": "/v1/health"
    },
    "backend": {
      "health": "/health"
    }
  }
}

variables.yaml:

services:
  api:
    health: /v1/health
  backend:
    health: /health

Output of levant version:

0.3.0

Output of consul version:

N/A

Output of nomad version:

N/A

Additional environment details:

I have a fork that very haphazardly resolves the issue. If this is a feature Levant would like to support I can clean up that fork and submit a pull request.

Debug log outputs from Levant:

Rendering w/ JSON variables is fine:

$ levant render -log-level=debug -var-file=variables.json template.hcl
2021-09-22T10:37:31-07:00 |DEBU| template/render: variable file extension .json detected
2021-09-22T10:37:31-07:00 |DEBU| template/render: no command line variables passed
2021-09-22T10:37:31-07:00 |DEBU| template/funcs: renaming "env" function to "levantEnv"
2021-09-22T10:37:31-07:00 |DEBU| template/funcs: renaming "add" function to "levantAdd"
2021-09-22T10:37:31-07:00 |DEBU| template/funcs: renaming "replace" function to "levantReplace"
2021-09-22T10:37:31-07:00 |INFO| helper/variable: using variable with key services and value map[api:map[health:/v1/health] backend:map[health:/health]] from file


  api health endpoint is /v1/health



  backend health endpoint is /health

Rendering w/ YAML variables fails:

$ levant render -log-level=debug -var-file=variables.yaml template.hcl
2021-09-22T10:37:05-07:00 |DEBU| template/render: variable file extension .yaml detected
2021-09-22T10:37:05-07:00 |DEBU| template/render: no command line variables passed
2021-09-22T10:37:05-07:00 |DEBU| template/funcs: renaming "env" function to "levantEnv"
2021-09-22T10:37:05-07:00 |DEBU| template/funcs: renaming "replace" function to "levantReplace"
2021-09-22T10:37:05-07:00 |DEBU| template/funcs: renaming "add" function to "levantAdd"
2021-09-22T10:37:05-07:00 |INFO| helper/variable: using variable with key services and value map[api:map[health:/v1/health] backend:map[health:/health]] from file
[ERROR] levant/command: template: jobTemplate:1:31: executing "jobTemplate" at <$.services>: wrong type for value; expected map[string]interface {}; got map[interface {}]interface {}
@pop
Copy link
Author

pop commented Sep 22, 2021

One workaround I've tried is using yq to convert my YAML vars into JSON vars before passing them to Levant. This works, but I expected Levant to support this out of the box.

@alistairking
Copy link

I'm having the same problem.

@JamesAwesome
Copy link

2022 and i'm still having this problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants