Merge "Deep-merge service meta with pillar data"
diff --git a/telegraf/map.jinja b/telegraf/map.jinja
index c49db55..3ca3e3e 100644
--- a/telegraf/map.jinja
+++ b/telegraf/map.jinja
@@ -17,16 +17,18 @@
},
}, merge=salt['pillar.get']('telegraf:remote_agent')) %}
-{%- set service_grains = {'telegraf': {'agent': {'input': {}}, 'remote_agent': {'input':{}}}} %}
+{# Collect configuration from */meta/telegraf.yml #}
+{%- set telegraf_grains = {'telegraf': {'agent': {'input': {}}, 'remote_agent': {'input':{}}}} %}
{%- for service_name, service in pillar.items() %}
{%- if service.get('_support', {}).get('telegraf', {}).get('enabled', False) %}
{%- set grains_fragment_file = service_name+'/meta/telegraf.yml' %}
{%- macro load_grains_file() %}{% include grains_fragment_file ignore missing %}{% endmacro %}
{%- set grains_yaml = load_grains_file()|load_yaml %}
{%- if grains_yaml is mapping %}
- {%- set service_grains = salt['grains.filter_by']({'default': service_grains}, merge={'telegraf': grains_yaml}) %}
+ {%- set telegraf_grains = salt['grains.filter_by']({'default': telegraf_grains}, merge={'telegraf': grains_yaml}) %}
{%- endif %}
{%- endif %}
{%- endfor %}
-{%- set telegraf_grains = salt['grains.filter_by']({'default': service_grains}, merge={'telegraf': {'agent': agent}}) %}
-{%- set telegraf_grains = salt['grains.filter_by']({'default': service_grains}, merge={'telegraf': {'remote_agent': remote_agent}}) %}
+
+{# Deep-merge the service configuration with the pillar data #}
+{%- do salt['defaults.merge'](telegraf_grains, {'telegraf': {'agent': agent, 'remote_agent': remote_agent}}) %}