Skip to content

Instantly share code, notes, and snippets.

@TylerWanner
Last active September 23, 2021 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TylerWanner/5a7888e7a31f844a24c3f20198ea645f to your computer and use it in GitHub Desktop.
Save TylerWanner/5a7888e7a31f844a24c3f20198ea645f to your computer and use it in GitHub Desktop.
Demo GKE Cluster Specs
terraform {
backend "local" {
path = "../states/cluster.tfstate"
}
}
resource "google_container_cluster" "cluster" {
name = "demo-cluster"
release_channel {
channel = "REGULAR"
}
remove_default_node_pool = true
# 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.
initial_node_count = 1
# Setting an empty username and password explicitly disables basic auth
master_auth {
username = ""
password = ""
client_certificate_config {
issue_client_certificate = false
}
}
logging_service = "logging.googleapis.com/kubernetes"
monitoring_service = "monitoring.googleapis.com/kubernetes"
}
resource "google_container_node_pool" "nodes" {
lifecycle {
create_before_destroy = true
ignore_changes = [
# https://registry.terraform.io/providers/hashicorp/google/3.35.0/docs/resources/container_node_pool#initial_node_count
initial_node_count
]
}
name_prefix = "pool"
location = google_container_cluster.cluster.location
cluster = google_container_cluster.cluster.name
initial_node_count = 2
management {
auto_repair = true
auto_upgrade = true
}
autoscaling {
min_node_count = 2
max_node_count = 4
}
node_config {
preemptible = true
metadata = {
disable-legacy-endpoints = "true"
}
workload_metadata_config {
node_metadata = "SECURE"
}
machine_type = "e2-standard-2"
}
}
output cluster_endpoint {
value = google_container_cluster.cluster.endpoint
}
output cacert {
value = google_container_cluster.cluster.master_auth[0].cluster_ca_certificate
}
output project {
value = var.project
}
output zone {
value = var.zone
}
output cluster_name {
value = google_container_cluster.cluster.name
}
provider google {
project = var.project
zone = var.zone
}
variable "zone" {}
variable "project" {}
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "3.85.0"
}
}
required_version = ">= 1"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment