<p>I am creating a kubernetes configMap using '--from-env-file' option to store the file contents as environment variables.</p>

<pre><code>kubectl create configmap env --from-env-file=env.properties -n namespace
</code></pre>

<p>When I create a terraform resource as below, the created configMap contains a file, not environment variables.</p>

<pre><code>resource "kubernetes_config_map" "env" {
  metadata {
    name = "env-config"
    namespace = var.namespace
  }
  data = {
    "env.properties"   = "${file("${path.module}/env.properties")}"
  }
}
</code></pre>

<p>How to create configMap with file content as environment variables using terraform-kubernetes-provider resource ?</p>

user691197
<p>If <code>env.properties</code> looks like this:</p>

<pre><code>$ cat env.properties
enemies=aliens
lives=3
allowed="true"
</code></pre>

<p>Then <code>kubectl create configmap env --from-env-file=env.properties -n namespace</code> would result in something like this:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: env
  namespace: namespace
data:
  allowed: '"true"'
  enemies: aliens
  lives: "3"
</code></pre>

<p>But what you're doing with Terraform would result in something more like this:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: env
  namespace: namespace
data:
  env.properties: |
    enemies=aliens
    lives=3
    allowed="true"
</code></pre>

<p>Based on the <a href="https://www.terraform.io/docs/providers/kubernetes/r/config_map.html" rel="nofollow noreferrer">Terraform docs</a> it appears that what you're looking for, i.e. some native support for <code>--from-env-file</code> behaviour within the Terraform provider, is not possible.</p>

<p>The <code>ConfigMap</code> format that you get doing it the Terraform way could still be useful, you might just have to change how you're pulling the data from the <code>ConfigMap</code> into your pods/deployments. If you can share more details, and even a simplified/sanitized example of your pods/deployments where you're consuming the config map, it may be possible to describe how to change those to make use of the different style of <code>ConfigMap</code>. See more <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/" rel="nofollow noreferrer">here</a>.</p>
