<p>I have one yaml file  that contains the following:</p>

<pre><code>...
volumeMounts:
      - mountPath: /var/lib/grafana
        name: grafana-storage
      - mountPath: /etc/grafana/provisioning/datasources
        name: grafana-datasources
        readOnly: false
...
</code></pre>

<p>and another file in witch the grafana-datasource volume is specified:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
    name: grafana-datasources
    namespace: ccx-data-pipeline
    labels:
        grafana_datasource: '1'
data:
    prometheus.yaml: |-
        {
            "apiVersion": 1,
            "datasources": [
                {
                    "access":"proxy",
                    "editable": true,
                    "name": "prometheus-ccx-service",
                    "orgId": 1,
                    "type": "prometheus",
                    "url": "http://prometheus-service:9090",
                    "version": 1
                }
            ]
        }
</code></pre>

<p>the point is that </p>

<pre><code>"url": "http://prometheus-service:9090" 
</code></pre>

<p>can't be hard coded but must be parametrized (ideally with an environment variable). It would be great to do like so:</p>

<pre><code>"url": "${ENDPOINT}"
</code></pre>

<p>but it doesn't work, probably due to the |- syntax. Is there an elegant way to achieve this?</p>

JoulinRouge
<p>It's not possible directly in kubernetes. ConfigMap treats underlying file as generic <code>data</code> type and can't template it, since it doesn't recognize its type (.yaml, .conf etc) </p>

<p>What you can do:</p>

<ol>
<li>apply some sort of templating to your .yaml file in advance (e.g. via Jinja2 template)</li>
<li>generate different ConfigMaps from different files depending on your environments (staging, prod). </li>
<li>generate ConfigMaps dynamically with <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#create-a-configmap-from-generator" rel="nofollow noreferrer">kustomize</a></li>
</ol>
