Terraform secret cannot reach/find GKE cluster

Hello

I am new with terraform and I would love to learn more about it, but I lack of knowledge and I might have missed something important. I stumbled upon this error

Error: Get "https://35.240.52.113/api/v1/namespaces/default/secrets/regcred": dial tcp 35.240.52.113:443: i/o timeout

Basically I troubleshooted my code and found out that my secret.tf file is working, but it doesnt “find” the cluster once created. I have to manually connect to it on GKE and THEN launch the code for a second time.

Here’s the code:


data "google_secret_manager_secret_version" "username-harbor" {
  provider = google-beta
  secret  = "username-harbor"
  version = "1"
}

data "google_secret_manager_secret_version" "password-harbor" {
  provider = google-beta
  secret  = "password-harbor"
  version = "1"
}

variable "registry_server" {
  default = "https://website.net"
}


resource "kubernetes_secret" "regcred" {
  metadata {
    name = "regcred"
    namespace = "default"
  }

  type = "kubernetes.io/dockerconfigjson"


  wait_for_service_account_token=false
  
  data = {
    ".dockerconfigjson" = jsonencode({
      auths = {
        "${var.registry_server}" = {
          "username" = data.google_secret_manager_secret_version.username-harbor.secret_data
          "password" = data.google_secret_manager_secret_version.password-harbor.secret_data
        }
      }
    })
  }
}

I didn’t find in the doc any way to specify “which cluster and where it’s located”

By “doc” i refer to this : Hashicorp-kubernetes-secret

I also created with terraform the k8s cluster, in the same tfstate, so i though it would detect it this way but no. I can’t seem to find out “how” to make the secret code find the cluster

Cameback for anyone who would be stuck at the same point as I was, I found the solution here :
stack overflow question

It’s not the same problem, but the solution is the same.

Thread can be closed.