title: Terraform import Kubernetes secret
body: <p>I am trying to import an existing kubernetes secret into my Terraform state.</p>
  
  <p>The secret resource should be located in a module, together with postgres resources. The idea is that I create the postgres user credentials and put them straight in a K8S secret.</p>
  
  <p>The resource looks like this: </p>
  
  <pre><code>resource "kubernetes_secret" "database-credentials" {
    metadata {
      name = "${var.name}-database-credentials"
    } 
    data = {
      username = "${var.name}_user"
      password = random_password.password.result
    }
    type = "Opaque"
  }
  </code></pre>
  
  <p>Then, I try to import it with the following command:
  <code>terraform import module.&lt;module_name&gt;.kubernetes_secret.database-credentials default/&lt;existing-secret-name&gt;</code></p>
  
  <p>Now, the problem is that this command fails with the following error message: </p>
  
  <pre><code>Error: Error initializing PostgreSQL client: error detecting capabilities: error PostgreSQL version: pq: no PostgreSQL user name specified in startup packet
  </code></pre>
  
  <p>I have no idea why the PostgreSQL client needs to do anything here or why it fails. There are postgres resources defined above the kubernetes secret resource config but I just want to import a k8s secret. I have defined all necessary environment variables needed. <code>terraform apply</code> works fine when I run it without the secret.</p>
  
  <p>Could someone point me in the right direction please?</p>