Skip to content

Instantly share code, notes, and snippets.

@mr-pascal
Last active November 26, 2022 13:51
Show Gist options
  • Save mr-pascal/b0722b184aab46f1a027191ec2d9b45c to your computer and use it in GitHub Desktop.
Save mr-pascal/b0722b184aab46f1a027191ec2d9b45c to your computer and use it in GitHub Desktop.
# google_client_config and kubernetes provider must be explicitly specified like the following.
# Retrieve an access token as the Terraform runner
data "google_client_config" "default" {}
# GKE cluster
resource "google_container_cluster" "primary" {
name = "my-gke"
project = var.project
location = var.region
# 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
networking_mode = "VPC_NATIVE"
ip_allocation_policy {}
}
# Separately Managed Node Pool
resource "google_container_node_pool" "primary_nodes" {
project = var.project
name = "${google_container_cluster.primary.name}-node-pool"
location = var.region
cluster = google_container_cluster.primary.name
node_count = 1
node_config {
oauth_scopes = [
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
]
labels = {
env = var.project
}
preemptible = true
machine_type = "e2-small"
tags = ["gke-node"]
metadata = {
disable-legacy-endpoints = "true"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment