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

Dependency packs don't load variables #415

Open
dkyanakiev opened this issue Aug 29, 2023 · 3 comments
Open

Dependency packs don't load variables #415

dkyanakiev opened this issue Aug 29, 2023 · 3 comments

Comments

@dkyanakiev
Copy link

Hi,

I've started exploring nomad-packs recently and I'm testing whats possible with the current set of features and Im running into some basic, yet important components that I cant get to work.
What I'm trying to do is fairly standard and not that strange.
Have a separate pack that would be used across everything and we import it as dependency and use the templates from the common pack.
Simple right?

I've made that part of the setup:

dependency "shared-packs" {
  alias = "sp"
  source = "git@<>:dkyanakiev/shared-packs.git//packs/common"
}

Note: The alias is not a thing yet but thats the last test I had from one of the open MRs I was looking at

I reference a template I have like so: [[ template "constraints" .sp ]]
And it works - however the problem I'm running is that variables I have in my main pack are not passed down to my dependency template.

For example: I have a variable called environment which has logic built around it.

[[ define "constraints" -]]
[[- if (eq (var "environment" . ) "prod") -]]
  constraint {
    distinct_hosts = true
  }
[[- end ]]

I have that variable set in my main pack but the dependency pack never finds that variable. I know for a fact the logic works because when I play with the default variables in the shared-pack I can see how the template renders correctly but not when I actually expect to get the variable from the main template.

I tried setting the variable as default in the main pack or running with a var file - same result.
Documentation is limited so I cant follow if this is me missing something or this not working yet

@slonopotamus
Copy link
Contributor

slonopotamus commented Sep 6, 2023

I believe you need to explicitly pass variables to template. In Helm, it works the same way, template only has access to its arguments.

@dkyanakiev
Copy link
Author

Well you don't need to explicitly pass them when using the version from master

[[ template "region" . ]]

and

[[ define "region" -]]
[[- if not (eq .my.region "") -]]
  region = [[ .my.region | quote]]
[[- end -]]
[[- end -]]

With the region being imported via dependency - works like a charm. I was testing a build from - #403 since it looks like a good merge candidate and it had features in I wanted to look but ran into the issue above

@slonopotamus
Copy link
Contributor

Well, passing . also means "passing explicitly through arguments"

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

2 participants