google-cloud-platformgoogle-kubernetes-engineterraform-provider-gcpgoogle-anthos

Cloud Run For Anthos With Terraform


We would like to achieve is create a Kubernetes cluster in Google Cloud Platform that enables Cloud Run addon; then instantiate the cluster with a custom helm chart release, all this via Terraform

From terraform documentation, only show how to create kubernetes cluster but not how to install Cloud Run.

resource "google_container_cluster" "primary" {
    name     = "my-gke-cluster"
    location = "us-central1"

    # We can't create a cluster with no node pool defined, but we want to only use
    # separately managed node pools. So we create the smallest possible default
    # node pool and immediately delete it.
    remove_default_node_pool = true
    initial_node_count       = 1
}

resource "google_container_node_pool" "primary_preemptible_nodes" {
    name       = "my-node-pool"
    location   = "us-central1"
    cluster    = google_container_cluster.primary.name
    node_count = 1

    node_config {
        preemptible  = true
        machine_type = "e2-medium"

        # Google recommends custom service accounts that have cloud-platform scope and permissions granted via IAM Roles.
        service_account = google_service_account.default.email
        oauth_scopes    = [
        "https://www.googleapis.com/auth/cloud-platform"
        ]
    }
}

What should we change inorder for terraform to create a cluster that has Istio and KNative installed in the master node


Solution

  • You can use the addons_config block with a cloudrun_config block:

    addons_config {
      cloudrun_config {
        disabled = false
      }
    }
    

    Or if you want to use an internal load balancer for CloudRun, then

    addons_config {
      cloudrun_config {
        disabled = false
        load_balancer_type=LOAD_BALANCER_TYPE_INTERNAL
      }
    }