Hello,
I am working on building a Nomad Pack and am having troubles reading a global variable from inside a range.
Extract from variables.hcl:
variable "redis_database" {
type = string
}
variable "redisdetails" {
type = list(object({
redis_host = string
redis_password = string
}))
default = []
}
If I do this, it works fine:
/* [[ var "redis_database" . ]] is the database to use*/
[[ range var "networks" . ]]
template {
data = <<<EOH
THE_REDIS_HOST=[[ .redis_host ]]
THE_REDIS_PASSWORD=[[ .redis_password ]]
EOH
}
[[ end ]]
But as soon as I reference a variable from the pack, it gives me an exotic error:
! Failed To Process Pack
Error: wrong type for value; expected parser.PackContextable; got map[string]interface {}
Context:
- Filename: mypack/templates/_redisdb.tpl
- Position: 7,17
- Registry Name: <<local folder>>
- Pack Name: mypack
- Pack Ref: <<none>>
- Pack Path: /home/davidtek/packs/mypack
- Deployment Name: mypack
[[ range var "networks" . ]]
/* [[ var "redis_database" . ]] is the database to use*/
template {
data = <<<EOH
THE_REDIS_HOST=[[ .redis_host ]]
THE_REDIS_PASSWORD=[[ .redis_password ]]
EOH
}
[[ end ]]
It would seem that invoking range has changed the scope of variables and I can no longer access the variables from the pack.
I tried using the name of the pack:
[[ var "redis_database" .mypack ]]
But this doesn’t work either.
How do I access the global variable scope from within the scope of a range ?
Thanks,
David