Skip to content
New issue

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

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

Already on GitHub? # to your account

HCL Variable Values mixes key-value and JSON format #23926

Open
hashworks opened this issue Sep 6, 2024 · 3 comments
Open

HCL Variable Values mixes key-value and JSON format #23926

hashworks opened this issue Sep 6, 2024 · 3 comments
Labels
stage/accepted Confirmed, and intend to work on. No timeline committment though. theme/hcl theme/ui type/bug

Comments

@hashworks
Copy link

Nomad version

1.8.0

Issue

If you deploy a job with variables provided by both -var-file=foo.json and NOMAD_VAR_name environment variables the HCL Variable Values section in the WebUI will show both the correct key-value format (env variables) and JSON (-var-file). If one tries to edit the job definition and plan it, it results in the following error:

Failed to parse job: unable to parse var content: input.hcl:10,1-2: Argument or block definition required; An argument or block definition is required here.

The user then has to replace the JSON with the key-value format to fix this.

Reproduction steps

Deploy a job with both env and -var-file:

echo '{
    "domain": "example.com",
    "issuer": "https://auth.example.com/realms/example"
}' > foo.json

export NOMAD_VAR_version="3.3.1"
export NOMAD_VAR_commit_author="user <user@example.com>"

nomad run -var-file=foo.json some-job.hcl

Afterward open the job in the WebUI, edit the definition and try to plan your change.

Expected Result

The HCL Variable Values section should only show variables in the key-value format:

version="3.3.1"
commit_author="user <user@example.com>"
domain="example.com"
issuer="https://auth.example.com/realms/example"

Actual Result

It adds the JSON from -var-file=foo.json:

version="3.3.1"

commit_author="user <user@example.com>"
{
    "domain": "example.com",
    "issuer": "https://auth.example.com/realms/example"
}

image

@hashworks
Copy link
Author

Note: I've checked the 1.8.{1,2,3} changelogs, they don't seem to include a fix for the bug I'm seeing.

@tgross tgross added the theme/ui label Sep 6, 2024
@jrasell
Copy link
Member

jrasell commented Sep 18, 2024

Hi @hashworks and thanks for raising this issue with the reproduction steps. I have used these to reproduce this locally using main at 4d6856a30619572ef43d0e6ffb803ddb459c4856. I'll move this issue to our backlog for roadmapping.

@jrasell jrasell added theme/hcl stage/accepted Confirmed, and intend to work on. No timeline committment though. labels Sep 18, 2024
@RSWilli
Copy link

RSWilli commented Sep 18, 2024

@jrasell I think the reason for this is purely in the UI, as far as I can see:

_newDefinitionVariables += specification.Variables;

_newDefinitionVariables is the string that gets used in the job editor component:

https://github.com/hashicorp/nomad/blob/main/ui/app/templates/components/job-editor/edit.hbs#L73-L94

But the Variables returns the content of the varfile. If I understand it correctly then the fix would be to do the following:

_newDefinitionVariables += jsonToHcl(JSON.parse(specification.Variables));

But that would require that the Variables field only returns JSON. If it returns the contents of the var file then there would have to be support for other formats.


An alternative would be to not concat the variables but instead use different input fields that get sent separately to the backend.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
stage/accepted Confirmed, and intend to work on. No timeline committment though. theme/hcl theme/ui type/bug
Projects
Status: Needs Roadmapping
Status: Backlog
Development

No branches or pull requests

4 participants