'Error while deploying Terraform with Helm provider to GKE - data.google_container_cluster.primary.master_auth is null
I'm writing an Azure build pipeline with multi-stages to conduct several Terraform tasks. In one of the stages, I deployed a GKE cluster thru terraform apply and save the .tfstate file into an artifact[succeed]. In the next stage, the .tfstate artifact is downloaded back and then I tried to deploy helm charts via terraform tasks(in a different folder) [failed].
This is how I configured the Helm provider.
data "google_container_cluster" "primary" {
name = data.terraform_remote_state.gke.outputs.kubernetes_cluster_name
location = data.terraform_remote_state.gke.outputs.region
project = data.terraform_remote_state.gke.outputs.project_id
}
provider "helm" {
kubernetes {
host = data.terraform_remote_state.gke.outputs.kubernetes_cluster_host
token = data.google_client_config.default.access_token
cluster_ca_certificate = base64decode(data.google_container_cluster.primary.master_auth[0].cluster_ca_certificate)
}
}
When terraform plan, it gives me error, data.google_container_cluster.primary.master_auth is null. However, in the .tfstate file, there's resource google_container_cluster and the master_auth field is not null. Does anyone know what went wrong? Big thanks!
P.S. I basically followed these two tutorials:
- https://learn.hashicorp.com/tutorials/terraform/helm-provider?in=terraform/kubernetes&_ga=2.111641793.432052200.1643062490-1307148832.1641408491
- https://learn.hashicorp.com/tutorials/terraform/kubernetes-provider
Update
I've finally realized the issue is the location of the cluster. The cluster deployed is based on zone, not region. Once change it to location = data.terraform_remote_state.gke.outputs.zone, resource google_container_cluster can be retrieved correctly.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
