I have my cluster created and if I try to describe it with the command:
gcloud --project=<project> container clusters --region=us-central1-f describe <name> --format=json | jq .
the response looks like:
{
"addonsConfig": {
"gcePersistentDiskCsiDriverConfig": {
"enabled": true
},
"kubernetesDashboard": {
"disabled": true
},
"networkPolicyConfig": {
"disabled": true
}
},
as you see not all the addons are described. addons like horizontal pod autoscaling and http loadbalancing are not returned. This make problematic importing to the Terraform an existing GKE cluster. Do you have any idea why the API is not complete?
Hello @Salvo,
Welcome to Google Cloud Community!
I was able to reproduce this in both formats and I got the same results having addons enabled. I am not really sure if this is the expected behavior and for better understanding of your concern and better solution to be provided, I suggest contacting Google Cloud Support so they can look into the environment you are running and match the best solution.
Thanks!
The reason why the gcloud container clusters describe API does not return all addons is because the API is designed to be used for managing GKE clusters, not for exporting cluster configurations. Some addons, such as horizontal pod autoscaling and HTTP load balancing, are managed by Kubernetes itself, not by GKE.
To export a complete GKE cluster configuration to Terraform, you can use the following steps:
gcloud container clusters get-addons <cluster-name>
gcloud container clusters get-addons <cluster-name> --addons <addon-name>
Save the output of the previous command to a file.
In your Terraform configuration, create a kubernetes_cluster resource and set the addons property to the output of the previous step.
Here is an example of a Terraform configuration that exports a GKE cluster configuration:
resource "kubernetes_cluster" "default" { name = "my-cluster" location = "us-central1-f" addons = { horizontal_pod_autoscaling = { enabled = true } http_load_balancing = { enabled = true } } }
Once you have created the Terraform configuration, you can use the terraform import command to import the existing GKE cluster into Terraform.