<p>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: <a href="https://www.youtube.com/watch?v=Vcv6GapxUCI" rel="nofollow noreferrer">https://www.youtube.com/watch?v=Vcv6GapxUCI</a>. Here is a link to the Github repo from the tutorial if you would like to see how the main.tf file is structured: <a href="https://github.com/alexandarp/terraform-gke" rel="nofollow noreferrer">https://github.com/alexandarp/terraform-gke</a>.</p>
<p>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.</p>
<p>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!</p>

<p>Yes, use <code>provider &quot;kubernetes&quot; {}</code></p>
<p>See a working example below for your reference. In this example, I am creating an example namespace using <code>resource &quot;kubernetes_namespace&quot; &quot;example&quot; {}</code>.</p>
<p>You will be using <code>resource &quot;kubernetes_deployment&quot; &quot;example&quot; {}</code> and <code>resource &quot;kubernetes_service&quot; &quot;example&quot; {}</code>. See the docs <a href="https://www.terraform.io/docs/providers/kubernetes/guides/getting-started.html" rel="nofollow noreferrer">here</a> for more details.</p>
<blockquote>
<p>main.tf</p>
</blockquote>
<pre><code>provider &quot;google&quot; {
  credentials = file(&quot;account.json&quot;)
  project     = &quot;my-project-id&quot;
  region      = &quot;us-central1&quot;
}

# Create GKE Cluster
resource &quot;google_container_cluster&quot; &quot;primary&quot; {
  name               = &quot;marcellus-wallace&quot;
  location           = &quot;us-central1-a&quot;
  initial_node_count = 1

  master_auth {
    username = &quot;&quot;
    password = &quot;&quot;

    client_certificate_config {
      issue_client_certificate = false
    }
  }

  node_config {
    oauth_scopes = [
      &quot;https://www.googleapis.com/auth/logging.write&quot;,
      &quot;https://www.googleapis.com/auth/monitoring&quot;,
    ]

    metadata = {
      disable-legacy-endpoints = &quot;true&quot;
    }

    labels = {
      foo = &quot;bar&quot;
    }

    tags = [&quot;foo&quot;, &quot;bar&quot;]
  }

  timeouts {
    create = &quot;30m&quot;
    update = &quot;40m&quot;
  }
}

data &quot;google_client_config&quot; &quot;default&quot; {}

data &quot;google_container_cluster&quot; &quot;my_cluster&quot; {
  name     = &quot;${google_container_cluster.primary.name}&quot;
  location = &quot;us-central1-a&quot;
}

# Kubernetes Provider
provider &quot;kubernetes&quot; {
  config_context_cluster = &quot;${google_container_cluster.primary.name}&quot;
  load_config_file       = false
  host                   = &quot;https://${data.google_container_cluster.my_cluster.endpoint}&quot;
  token                  = &quot;${data.google_client_config.default.access_token}&quot;
  cluster_ca_certificate = &quot;${base64decode(data.google_container_cluster.my_cluster.master_auth.0.cluster_ca_certificate)}&quot;
}

# Deploy resources on GKE
resource &quot;kubernetes_namespace&quot; &quot;example&quot; {
  metadata {
    annotations = {
      name = &quot;example-annotation&quot;
    }

    labels = {
      mylabel = &quot;label-value&quot;
    }

    name = &quot;terraform-example-namespace&quot;
  }
}
</code></pre>
