<p>Hello iam trying to insert a Kubernetes ConfigMap inside the cert-manager Helm Chart. The Helm Chart gets defined with a values.yaml.</p>
<p>The needed ConfigMap is already defined with the corresponding data inside the same namespace as my Helm Chart.</p>
<pre><code>resource &quot;helm_release&quot; &quot;certmanager&quot; {
name       = &quot;cert-manager&quot;
repository = &quot;https://charts.jetstack.io&quot;
chart      = &quot;cert-manager&quot;
namespace  = kubernetes_namespace.certmanager.metadata.0.name
version    = local.helm_cert_manager_version

values = [
  file(&quot;./config/cert-manager-values.yml&quot;)
]
}

# !! ConfigMap is defined with Terraform !! #
resource &quot;kubernetes_config_map&quot; &quot;example&quot; {
 metadata {
    name      = &quot;test-config&quot;
    namespace = kubernetes_namespace.certmanager.metadata.0.name
 }
 data = {
   &quot;test_ca&quot; = &quot;${data.google_secret_manager_secret_version.test_crt.secret_data}&quot;
 }
}
</code></pre>
<p>The data of the ConfigMap should be mounted to the path /etc/ssl/certs inside my Helm Chart.</p>
<p>I think down below is the rigth spot to mount the data?</p>
<pre><code>...
volumes: []
volumeMounts: []
..
</code></pre>
<p>Do you have any idea how to mount that ConfigMap over /etc/ssl/certs within the cert-manager Chart?</p>

leonms.dev
<p>Based on your question, there could be two things you could do:</p>
<ol>
<li>Pre-populate the <code>./config/cert-manager-values.yml</code> file with the values you want.</li>
<li>Use the <code>templatefile</code> [1] built-in function and pass the values dynamically.</li>
</ol>
<p>In the first case, the changes to the file would probably have to be as follows:</p>
<pre class="lang-yaml prettyprint-override"><code>...
volumes:
  - name: config-map-volume
    configMap:
        name: test-config
volumeMounts:
  - name: config-map-volume
    mountPath: /etc/ssl/certs
...
</code></pre>
<p>Make sure the indentation is correct since this is YML. In the second case, you could do something like this in the <code>helm_release</code> resource:</p>
<pre><code>resource &quot;helm_release&quot; &quot;certmanager&quot; {
  name       = &quot;cert-manager&quot;
  repository = &quot;https://charts.jetstack.io&quot;
  chart      = &quot;cert-manager&quot;
  namespace  = kubernetes_namespace.certmanager.metadata.0.name
  version    = local.helm_cert_manager_version

  values = [templatefile(&quot;./config/cert-manager-values.yml&quot;, {
    config_map_name   = kubernetes_config_map.example.metadata[0].name
    volume_mount_path = &quot;/etc/ssl/certs&quot;
  })]
}
</code></pre>
<p>In this case, you would also have to use template variables as placeholders inside of the <code>cert-manager-values.yml</code> file:</p>
<pre><code>...
volumes:
  - name: config-map-volume
    configMap:
        name: ${config_map_name}
volumeMounts:
  - name: config-map-volume
    mountPath: ${mount_path}
...
</code></pre>
<p>Note that the first option might not work as expected due to Terraform parallelism which tries to create as many resources as possible. If the ConfigMap is not created before the chart is applied it might fail.</p>
<hr />
<p>[1] <a href="https://www.terraform.io/language/functions/templatefile" rel="nofollow noreferrer">https://www.terraform.io/language/functions/templatefile</a></p>
