hashicorp / hashicorp/nomad-pack
Deep Merge Map type
- Dominant language
- Go
- Stars
- 447
- Forks
- 65
- PR merge metrics
- No merged PRs in 30d
Description
Currently, pack merge variables in a last override wins model. For example:
```hcl
variable "env" {
description = "Environment variables"
type = map(string)
default = {}
}
```
given two override files
`defaults.hcl`:
```hcl
env = {
"foo" = "bar",
"bar" = "biz"
}
```
`production.hcl`:
```hcl
env = {
"foo" = "newval",
}
```
When rendering `-f defaults.hcl -f production.hcl`, the result of `env` is:
```
env = {
"foo" = "newval"
}
```
Imagine the following process. A service owner declares one override file per environment and a common override file that all environments share. When deploying, it declares the common override file and the environment-specific file.
With this setup, the env `bar` needs to be redeclared on every environment file, making the reuse useless. The other alternative is to transform `bar` into a separate variable, but imagine that the service has more than 50 env variables. To maintain the reusability, the pack would need to declare 50 variables, and it would end up with a very poor template:
```hcl
env {
"FOO" = .my.foo
"BAR" = .my.bar
....
}
```
Instead of:
```hcl
env {
[[- range $k,$v := .my.env ]]
[[ $k ]] = [[ $v | quote ]]
[[- end ]]
}
```
It would be beneficial to perform a deep merge, at least for `map(string)` types. That is what [helm](https://github.com/helm/helm/issues/3486#issuecomment-581619753) does as an example.
Contributor guide
Assessment
This issue has not been assessed yet.