title: Deployment invalid Terraform + Kubernetes: spec.template.spec.containers[0].envFrom: Invalid value: ""
body: <p>I'm experimenting with terraform to deploy k8s resources.</p>
  <p>I created a mongodb deployment</p>
  <pre><code>provider &quot;kubernetes&quot; {
    config_context = &quot;kubernetes-admin@kubernetes&quot;
  }
  
  resource &quot;kubernetes_namespace&quot; &quot;demo-namespace&quot; {
    metadata {
      name = &quot;my-demo-namespace&quot;
    }
  }
  // mongodb
  resource &quot;kubernetes_deployment&quot; &quot;mongodb&quot; {
    metadata {
      name = &quot;mongodb&quot;
      namespace = kubernetes_namespace.demo-namespace.metadata[0].name
      labels = {
        app = &quot;mongodb&quot;
      }
    }
  
    spec {
      replicas = 1
  
      selector {
        match_labels = {
          app = &quot;mongodb&quot;
        }
      }
  
      template {
        metadata {
          labels = {
            app = &quot;mongodb&quot;
          }
        }
  
        spec {
          container {
            image = &quot;mongo&quot;
            name  = &quot;mongodb&quot;
  
            env_from { 
              secret_ref {
                name = kubernetes_secret.scrt-mongodb.metadata[0].name
              }
              config_map_ref {
                name = kubernetes_config_map.cm-mongodb.metadata[0].name  
              }
            }
  
            resources {
              limits {
                cpu    = &quot;500m&quot;
                memory = &quot;1Gi&quot;
              }
              requests {
                cpu    = &quot;150m&quot;
                memory = &quot;256Mi&quot;
              }
            }
  
            liveness_probe {
              exec {
                command =  [&quot;bash&quot;, &quot;-c&quot;, &quot;mongo -u $MONGO_INITDB_ROOT_USERNAME -p $MONGO_INITDB_ROOT_PASSWORD --eval db.adminCommand(\&quot;ping\&quot;)&quot;]
              }
              initial_delay_seconds = 3
              period_seconds        = 1
            }
          }
        }
      }
    }
  }
  
  // mongodb configmap
  resource &quot;kubernetes_config_map&quot; &quot;cm-mongodb&quot; {
    metadata {
      name = &quot;cm-mongodb&quot;
      namespace = kubernetes_namespace.demo-namespace.metadata.0.name
    }
  
    // improve creds with secret
    data = {
      MONGO_INITDB_DATABASE = &quot;movies&quot;
    }
  }
  
  // monbodb secret
  resource &quot;kubernetes_secret&quot; &quot;scrt-mongodb&quot; {
    metadata {
      name = &quot;mongodb-creds&quot;
    }
  
    data = {
      MONGO_INITDB_ROOT_USERNAME = &quot;root-user&quot;
      MONGO_INITDB_ROOT_PASSWORD = &quot;secret&quot;
    }
  
    type = &quot;opaque&quot;
  }
  </code></pre>
  <p>This fails with:</p>
  <pre><code>kubernetes_config_map.cm-mongodb: Creation complete after 0s [id=my-demo-namespace/cm-mongodb]
  kubernetes_deployment.mongodb: Creating...
  
  Error: Failed to create deployment: Deployment.apps &quot;mongodb&quot; is invalid: spec.template.spec.containers[0].envFrom: Invalid value: &quot;&quot;: may not have more than one field specified at a time
  
    on template.tf line 12, in resource &quot;kubernetes_deployment&quot; &quot;mongodb&quot;:
    12: resource &quot;kubernetes_deployment&quot; &quot;mongodb&quot; {
  </code></pre>
  <p>What is wrong here?</p>