hashicorp/nomad-pack

Dependency packs don't load variables

dkyanakiev opened this issue · 3 comments

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

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

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

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