Skip to content

Merging exploded maps #1499

@shovelwagon

Description

@shovelwagon

I'm pretty excited to use consul-template. One nice to have would be a helper function to merge exploded maps. This would allow one take a hierarchical approach to applying configuration set(s).

Current situation:

I've got the same application deployed in various configurations. In order to achieve bootstraping these apps, from consul k/v based attributes, I'd have to duplicate configuration for each permutation.

my-application-permu-1
|__ port
|__ app_dir
|__ some_remote_service

my-application-permu-2
|__ port
|__ app_dir
|__ some_remote_service

my-application-permu-3
|__ port
|__ app_dir
|__ some_remote_service

Use case:

Below is an example of how one might create a hierarchical override approach. Essentially, base would be applied first and then overrides over top.

my-application
|___ base
       |__ port
       |__ app_dir
       |__ some_remote_service
|___ overides
       |___ my-application-permu-2
              |__ some_remote_service
       |___ my-application-permu-3
              |__ some_remote_service

Template example:

{{- $base := tree "my-application/base" | explode }}
{{- $config := tree "my-application/base/overrides/my-application-permu-2" | explode | mergeMapWithOverride $base}}

some_config_block={
  {{- range $k, $v := $config }}
  {{ $k }}={{ $v }}
  {{- end }}
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions