Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.

Commit

Permalink
break the node pool out of the gke-cluster module and move it to the …
Browse files Browse the repository at this point in the history
…example
  • Loading branch information
robmorgan committed Jan 17, 2019
1 parent 5a58c56 commit 61eb7c5
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 65 deletions.
64 changes: 63 additions & 1 deletion examples/gke-regional-public-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module "gke_cluster" {

project = "${var.project}"
region = "${var.region}"
name = "example-cluster"
name = "${var.cluster_name}"

network = "${google_compute_network.main.name}"
subnetwork = "${google_compute_subnetwork.main.name}"
Expand All @@ -33,6 +33,68 @@ module "gke_cluster" {
#service_account = "${var.compute_engine_service_account}"
}

# Node Pool

// Node Pool Resource
resource "google_container_node_pool" "node_pool" {
name = "main-pool"
project = "${var.project}"
region = "${var.region}"
cluster = "${var.cluster_name}"
version = "latest"
initial_node_count = "1"

autoscaling {
min_node_count = "1"
max_node_count = "5"
}

management {
auto_repair = "true"
auto_upgrade = "true"
}

node_config {
image_type = "COS"
machine_type = "n1-standard-1"

labels = {
all-pools-example = "true"
}

# for custom shutdown scripts etc
# metadata = ""


#[DEPRECATED] This field is in beta and will be removed from this provider. Use it in the the google-beta provider instead.
# See https://terraform.io/docs/providers/google/provider_versions.html for more details.
#taint = {
# key = "main-pool-example"
# value = "true"
# effect = "PREFER_NO_SCHEDULE"
#}

tags = ["main-pool-example"]
disk_size_gb = "30"
disk_type = "pd-standard"
#service_account = "${lookup(var.node_pools[count.index], "service_account", var.service_account)}"
preemptible = false
oauth_scopes = [
"https://www.googleapis.com/auth/cloud-platform",
]
}

lifecycle {
ignore_changes = ["initial_node_count"]
}

timeouts {
create = "30m"
update = "30m"
delete = "30m"
}
}

# Network

resource "random_string" "suffix" {
Expand Down
4 changes: 4 additions & 0 deletions examples/gke-regional-public-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ variable "region" {
# These parameters have reasonable defaults.
# ---------------------------------------------------------------------------------------------------------------------

variable "cluster_name" {
description = "The name of the Kubernetes cluster."
default = "example-cluster"
}

#variable "ip_range_pods" {
# description = "The secondary ip range to use for pods"
Expand Down
75 changes: 11 additions & 64 deletions modules/gke-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ resource "google_container_cluster" "cluster" {
# part of Create. This leaves us in our desired state- with a cluster master
# with no node pools.
remove_default_node_pool = true
initial_node_count = 1

initial_node_count = 1

logging_service = "${var.logging_service}"
monitoring_service = "${var.monitoring_service}"
Expand Down Expand Up @@ -68,58 +69,6 @@ resource "google_container_cluster" "cluster" {
}
}

// Node Pool Resource
resource "google_container_node_pool" "pools" {
count = "${length(var.node_pools)}"
name = "${lookup(var.node_pools[count.index], "name")}"
project = "${var.project}"
region = "${var.region}"
cluster = "${var.name}"
version = "${lookup(var.node_pools[count.index], "auto_upgrade", false) ? "" : lookup(var.node_pools[count.index], "version", local.node_version)}"
initial_node_count = "${lookup(var.node_pools[count.index], "initial_node_count", lookup(var.node_pools[count.index], "min_count", 1))}"

autoscaling {
min_node_count = "${lookup(var.node_pools[count.index], "min_count", 1)}"
max_node_count = "${lookup(var.node_pools[count.index], "max_count", 100)}"
}

management {
auto_repair = "${lookup(var.node_pools[count.index], "auto_repair", true)}"
auto_upgrade = "${lookup(var.node_pools[count.index], "auto_upgrade", true)}"
}

node_config {
image_type = "${lookup(var.node_pools[count.index], "image_type", "COS")}"
machine_type = "${lookup(var.node_pools[count.index], "machine_type", "n1-standard-2")}"
labels = "${merge(map("cluster_name", var.name), map("node_pool", lookup(var.node_pools[count.index], "name")), var.node_pools_labels["all"], var.node_pools_labels[lookup(var.node_pools[count.index], "name")])}"
metadata = "${merge(map("cluster_name", var.name), map("node_pool", lookup(var.node_pools[count.index], "name")), var.node_pools_metadata["all"], var.node_pools_metadata[lookup(var.node_pools[count.index], "name")])}"
taint = "${concat(var.node_pools_taints["all"], var.node_pools_taints[lookup(var.node_pools[count.index], "name")])}"
tags = ["${concat(list("gke-${var.name}"), list("gke-${var.name}-${lookup(var.node_pools[count.index], "name")}"), var.node_pools_tags["all"], var.node_pools_tags[lookup(var.node_pools[count.index], "name")])}"]

disk_size_gb = "${lookup(var.node_pools[count.index], "disk_size_gb", 100)}"
disk_type = "${lookup(var.node_pools[count.index], "disk_type", "pd-standard")}"

#service_account = "${lookup(var.node_pools[count.index], "service_account", var.service_account)}"
preemptible = "${lookup(var.node_pools[count.index], "preemptible", false)}"

oauth_scopes = [
"https://www.googleapis.com/auth/cloud-platform",
]
}

lifecycle {
ignore_changes = ["initial_node_count"]
}

timeouts {
create = "30m"
update = "30m"
delete = "30m"
}

depends_on = ["google_container_cluster.cluster"]
}

// TODO
// Add Data Source to get the latest k8s version
// Use this is k8s version is not set.
Expand All @@ -132,17 +81,15 @@ locals {
cluster_master_auth_map = "${concat(google_container_cluster.cluster.*.master_auth, list())}"

# cluster locals
cluster_type = "regional"
cluster_name = "${element(concat(google_container_cluster.cluster.*.name, list("")), 0)}"
cluster_location = "${element(concat(google_container_cluster.cluster.*.region, list("")), 0)}"
cluster_region = "${element(concat(google_container_cluster.cluster.*.region, list("")), 0)}"
cluster_endpoint = "${element(concat(google_container_cluster.cluster.*.endpoint, list("")), 0)}"
cluster_master_version = "${element(concat(google_container_cluster.cluster.*.master_version, list("")), 0)}"
cluster_min_master_version = "${element(concat(google_container_cluster.primary.*.min_master_version, list("")), 0)}"
cluster_logging_service = "${element(concat(google_container_cluster.cluster.*.logging_service, list("")), 0)}"
cluster_monitoring_service = "${element(concat(google_container_cluster.cluster.*.monitoring_service, list("")), 0)}"
cluster_node_pools_names = "${concat(google_container_node_pool.pools.*.name, list(""))}"
cluster_node_pools_versions = "${concat(google_container_node_pool.pools.*.version, list(""))}"
cluster_type = "regional"
cluster_name = "${element(concat(google_container_cluster.cluster.*.name, list("")), 0)}"
cluster_location = "${element(concat(google_container_cluster.cluster.*.region, list("")), 0)}"
cluster_region = "${element(concat(google_container_cluster.cluster.*.region, list("")), 0)}"
cluster_endpoint = "${element(concat(google_container_cluster.cluster.*.endpoint, list("")), 0)}"
cluster_master_version = "${element(concat(google_container_cluster.cluster.*.master_version, list("")), 0)}"
cluster_min_master_version = "${element(concat(google_container_cluster.cluster.*.min_master_version, list("")), 0)}"
cluster_logging_service = "${element(concat(google_container_cluster.cluster.*.logging_service, list("")), 0)}"
cluster_monitoring_service = "${element(concat(google_container_cluster.cluster.*.monitoring_service, list("")), 0)}"
}

data "google_compute_zones" "available" {
Expand Down

0 comments on commit 61eb7c5

Please sign in to comment.