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

Variables are not accessible in pack #428

Closed
avandierast opened this issue Sep 27, 2023 · 3 comments
Closed

Variables are not accessible in pack #428

avandierast opened this issue Sep 27, 2023 · 3 comments
Assignees

Comments

@avandierast
Copy link

Hello :)

It seems that the last nightly version of nomad-pack is unable to use any variables.

Nomad pack version:

╰─ ./nomad-pack --version
Nomad Pack v0.0.1-techpreview.4 (a0933f5)

Issue

Any variables in packs are nil. The context does not have any pack variables.

╰─ ./nomad-pack render testbug
! Failed To Process Pack

    Error:   failed to render testbug/templates/testbug.nomad.tpl: template: testbug/templates/testbug.nomad.tpl:1:24: executing "testbug/templates/testbug.nomad.tpl" at <.testbug.value>:
nil pointer evaluating parser.PackContextable.value
    Context: 
        - Details: 
        - Filename: 
        - Position: 
        - Suggestions: 
        - Registry Name: <<local folder>>
        - Pack Name: testbug
        - Pack Ref: <<none>>
        - Pack Path: <path>/testbug

Reproduction steps

A simple pack with a simple variable:

╰─ cat testbug/variables.hcl 
variable "value" {
  description = "value"
  type        = string
  default     = "myvalue"
}

A template in that pack that try to read the variable:

╰─ cat testbug/templates/testbug.nomad.tpl 
[[ toPrettyJson .testbug.value ]]

If we try to look at the pack in the context:

╰─ cat testbug/templates/testbug.nomad.tpl
[[ toPrettyJson .my ]]

[[ toPrettyJson .testbug ]]

[[ toPrettyJson . ]]

We get null for the packs and in the context there is a lot of stuff but no variables:

╰─ ./nomad-pack render testbug            
testbug/testbug.nomad:

null

null

{
  "_self" : {
    "Pack" : {
      "Metadata" : {
        "App" : {
          "URL" : "",
          "Author" : ""
        },
        "Pack" : {
          "Name" : "testbug",
          "Alias" : "",
          "Description" : "testbug",
          "URL" : "",
          "Version" : "v0.1"
        },
        "Integration" : null,
        "Dependencies" : null
      },
      "TemplateFiles" : [
        {
          "Name" : "templates/testbug.nomad.tpl",
          "Path" : "<path>/testbug/templates/testbug.nomad.tpl",
          "Content" : "W1sgdG9QcmV0dHlKc29uIC5teSBdXQoKW1sgdG9QcmV0dHlKc29uIC50ZXN0YnVnIF1dCgpbWyB0b1ByZXR0eUpzb24gLiBdXQo="
        }
      ],
      "AuxiliaryFiles" : null,
      "RootVariableFile" : {
        "Name" : "variables.hcl",
        "Path" : "<path>/testbug/variables.hcl",
        "Content" : "dmFyaWFibGUgInZhbHVlIiB7CiAgZGVzY3JpcHRpb24gPSAidmFsdWUiCiAgdHlwZSAgICAgICAgPSBzdHJpbmcKICBkZWZhdWx0ICAgICA9ICJteXZhbHVlIgp9Cg=="
      },
      "OutputTemplateFile" : null
    }
  }
}

@angrycub
Copy link
Contributor

As of yesterday, we merged in a new pack template syntax to enable deeply nested dependencies (#403) However, there is follow-on work coming in #426 to change the override variable naming format. The documentation is incoming; however, you can preview the new syntax by using the nomad-pack generate command.

In order to run packs with the pervious syntax, you can pass the --parser-v1 flag to the render, plan, and run commands. Please let me know if your pack works using the parser-v1 flag. I'm going to make a note on the repo README as well.

@avandierast
Copy link
Author

Hello.
We have kept a previous nightly version of nomad-pack for our use.
I will try with --parser-v1 and let you know :)

@avandierast
Copy link
Author

It works well with the --parser-v1 🙏

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

No branches or pull requests

2 participants