Creating GKE cluster and Ingress app with one apply

Hello,

I am fairly new to Terraform and am attempting to set-up a GCP GKE cluster and then connect it to an Ingress application. I was able to successfully do so following this tutorial: https://www.youtube.com/watch?v=Vcv6GapxUCI. Here is a link to the Github repo from the tutorial if you would like to see how the main.tf file is structured: https://github.com/alexandarp/terraform-gke.

However, this method involves using Terraform to create the GKE cluster first then separately use the gcloud command line command to get the cluster credentials and then run several “kubectl apply” commands to create the Ingress application from a set of .yaml files. So basically, it becomes a two-step process of creating the GKE cluster and then separately creating an Ingress application.

My question is: is it possible to do both steps using only one “terraform apply” command? That is, have one Terraform file that both creates the GKE cluster and then also creates the Ingress application as well? Again, I am fairly new to Terraform, so if this is out of the scope of its capabilities, I understand! Any direction on where to move with this problem would be greatly appreciated!

Hi @paulwwstorm

Welcome to Terraform forums, it is a great technology for infrastructure.

Take a look at the following question about executing commands after infrastructure creation:

There is a Terraform provider for Kubernetes that you could use, but I would suggest that you write a different Terraform definition for that, as your GKE should have a longer and different life than the ingress app:

https://www.terraform.io/docs/providers/kubernetes/index.html

So actually not a single Terraform apply.

Thank you, Javier! I will look over the links you provided. Really appreciate the guidance.