简体   繁体   中英

Terraform import Kubernetes secret

I am trying to import an existing kubernetes secret into my Terraform state.

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.

The resource looks like this:

resource "kubernetes_secret" "database-credentials" {
  metadata {
    name = "${var.name}-database-credentials"
  } 
  data = {
    username = "${var.name}_user"
    password = random_password.password.result
  }
  type = "Opaque"
}

Then, I try to import it with the following command: terraform import module.<module_name>.kubernetes_secret.database-credentials default/<existing-secret-name>

Now, the problem is that this command fails with the following error message:

Error: Error initializing PostgreSQL client: error detecting capabilities: error PostgreSQL version: pq: no PostgreSQL user name specified in startup packet

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. terraform apply works fine when I run it without the secret.

Could someone point me in the right direction please?

Just figured it out myself.

https://github.com/terraform-providers/terraform-provider-postgresql/issues/2#issuecomment-567887609

TLDR: add expected_version = "<YOUR_POSTGRES_VERSION>" to the postgres provider block.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM