<p>I have the following ConfigMap which is having a variable called <code>VAR</code>. This variable should get the value from the workflow while accessing it as a volume</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: test-pod-cfg
data:
  test-pod.yaml: |-
    apiVersion: v1
    kind: Pod
    metadata:
      name: test-pod
    spec:
      containers:
        - name: test
          image: ubuntu
          command: [&quot;/busybox/sh&quot;, &quot;-c&quot;, &quot;echo $VAR&quot;]
</code></pre>
<p>Here is the argo workflow which is fetching script <code>test-pod.yaml</code> in ConfigMap and adding it as a volume to container. In this how to pass Environment variable <code>VAR</code> to the ConfigMap for replacing it dynamically</p>
<pre><code>apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  name: test-wf-
spec:
  entrypoint: main
  templates:
    - name: main
      container:
        image: &quot;ubuntu&quot;
        command: [&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;cat /mnt/vc/test&quot;]
        volumeMounts:
          - name: vc
            mountPath: &quot;/mnt/vc&quot;
      volumes:
        - name: vc
          configMap:
            name: test-pod-cfg
            items:
              - key: test-pod.yaml
                path: test
</code></pre>

dubru
<p>To mount the <code>ConfigMap</code> as a volume and make the environment variable VAR available to the container, you will need to add a volume to the pod's spec and set the environment variable in the container's spec.</p>
<p>In the volume spec, you will need to add the <code>ConfigMap</code> as a volume source and set the path to the file containing the environment variable. For example:</p>
<pre><code>spec:
  entrypoint: test-pod
  templates:
  - name: test-pod
    container:
      image: ubuntu
      command: [&quot;/busybox/sh&quot;, &quot;-c&quot;, &quot;echo $VAR&quot;]
      volumeMounts:
      - name: config
        mountPath: /etc/config
      env:
      - name: VAR
        valueFrom:
          configMapKeyRef:
            name: test-pod-cfg
            key: test-pod.yaml
    volumes:
    - name: config
      configMap:
        name: test-pod-cfg
</code></pre>
<p>The environment variable <code>VAR</code> will then be available in the container with the value specified in the ConfigMap.</p>
<p>For more information follow this <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#define-container-environment-variables-with-data-from-multiple-configmaps" rel="nofollow noreferrer">official doc</a>.</p>
