Difference between revisions of "Terraform resource: google container node pool"

From wikieduonline
Jump to navigation Jump to search
Line 3: Line 3:
  
 
== Official example ==
 
== Official example ==
<pre>
 
resource "google_service_account" "default" {
 
  account_id  = "service-account-id"
 
  display_name = "Service Account"
 
}
 
  
resource "google_container_cluster" "primary" {
+
resource "google_service_account" "default" {
  name    = "my-gke-cluster"
+
  account_id  = "service-account-id"
  location = "us-central1"
+
  display_name = "Service Account"
 
+
}
  # 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
+
resource "google_container_cluster" "primary" {
  # node pool and immediately delete it.
+
  name    = "my-gke-cluster"
  remove_default_node_pool = true
+
  location = "us-central1"
  initial_node_count      = 1
+
}
+
  # 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
resource "google_container_node_pool" "primary_preemptible_nodes" {
+
  # node pool and immediately delete it.
  name      = "my-node-pool"
+
  remove_default_node_pool = true
  cluster    = google_container_cluster.primary.id
+
  initial_node_count      = 1
  node_count = 1
+
}
 
+
  node_config {
+
resource "google_container_node_pool" "primary_preemptible_nodes" {
    preemptible  = true
+
  name      = "my-node-pool"
    machine_type = "e2-medium"
+
  cluster    = google_container_cluster.primary.id
 
+
  node_count = 1
    # Google recommends custom service accounts that have cloud-platform scope and permissions granted via IAM Roles.
+
    service_account = google_service_account.default.email
+
  node_config {
    oauth_scopes = [
+
    preemptible  = true
      "https://www.googleapis.com/auth/cloud-platform"
+
    [[machine_type]] = "[[e2-medium]]"  
    ]
+
  }
+
    # Google recommends custom service accounts that have cloud-platform scope and  
}
+
permissions granted via IAM Roles.
</pre>
+
    service_account = google_service_account.default.email
 +
    oauth_scopes = [
 +
      "https://www.googleapis.com/auth/cloud-platform"
 +
    ]
 +
  }
 +
}
  
  

Revision as of 11:18, 5 December 2023

https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_node_pool

google_container_node_pool

Official example

resource "google_service_account" "default" {
  account_id   = "service-account-id"
  display_name = "Service Account"
}

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"
  cluster    = google_container_cluster.primary.id
  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"
    ]
  }
}


Related

See also

Advertising: