<p>I have the following <code>ConfigMap</code>. I'm trying to split the two datasources out into two separate files, and merge them at &quot;build time&quot; using Kustomize.</p>
<p>But I just can't figure out how to do that?</p>
<p>This is what I have:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: grafana-datasources
  namespace: grafana
data:
  datasources.yaml: |-
    apiVersion: 1
    datasources:
      - name: prometheus
        type: prometheus
        access: proxy
        url: http://prometheus:9090
        isDefault: true
        version: 1
      - name: Azure Monitor
        type: grafana-azure-monitor-datasource
        access: proxy
        version: 1
</code></pre>
<p>The parts I want to split into separate files (and later merge into a ConfigMap) are:</p>
<pre><code>      - name: prometheus
        type: prometheus
        access: proxy
        url: http://prometheus:9090
        isDefault: true
        version: 1
</code></pre>
<p>And:</p>
<pre><code>      - name: Azure Monitor
        type: grafana-azure-monitor-datasource
        access: proxy
        version: 1
</code></pre>

<p>You have to create two separate files for datasource.
Create directory to put the base configuration:</p>
<pre><code>$ mkdir -p $DEMO_HOME/base
</code></pre>
<p>First datasource should look like this:</p>
<pre><code>$ cat &lt;&lt;EOF &gt;$DEMO_HOME/base/datasource1.yaml
</code></pre>
<pre><code>  apiVersion: 1
    datasources:
      - name: prometheus
        type: prometheus
        access: proxy
        url: http://prometheus:9090
        isDefault: true
        version: 1
</code></pre>
<p>Second datasource should look like this:</p>
<pre><code>$ cat &lt;&lt;EOF &gt;$DEMO_HOME/base/datasource2.yaml
</code></pre>
<pre><code>  apiVersion: 1
    datasources:
      - name: Azure Monitor
        type: grafana-azure-monitor-datasource
        access: proxy
        version: 1
</code></pre>
<pre><code>    $ cat &lt;&lt;EOF &gt;$DEMO_HOME/base/kustomization.yaml
</code></pre>
<p>Then in kustomization file pass info about configmap and add files:</p>
<pre><code>$ cat &lt;&lt;EOF &gt;$DEMO_HOME/base/kustomization.yaml
</code></pre>
<pre><code>configMapGenerator:
- name: my-configmap
  files:
  - datasource1.yaml
  - datasource2.yaml
EOF

</code></pre>
<p>Finally you can generate the configMaps for development:</p>
<pre><code>$ kustomize build $DEMO_HOME/base
</code></pre>
<p>Please take a look: <a href="https://github.com/kubernetes-sigs/kustomize/blob/master/examples/combineConfigs.md#create-and-use-the-overlay-for-development" rel="nofollow noreferrer">kustomize-operation</a>, <a href="https://github.com/kubernetes-sigs/kustomize/issues/897" rel="nofollow noreferrer">kustomize</a>.</p>
<p><strong>EDIT:</strong></p>
<p>You can also split ConfigMap into two separate ConfigMaps which both of them will include one file.
First one with <code>datasources1.yaml</code> and second one with <code>datasources2.yaml</code>.</p>
