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?