Skip to content

Commit

Permalink
Refactor/flatten duplicate resources terraform-google-modules#161
Browse files Browse the repository at this point in the history
Collapsed regional and zonal clusters into one cluster with location attribute instead usage of count, zones and regions.
Selection of latest nodes and master version same both for regional and zonal/multi-zonal clusters.
    For Master version in case or regional cluster following code check latest version by location (region),
and for zonal, location is var.zone[0]:
    latest_master_version       = data.google_container_engine_versions.master.latest_master_version
For Node version in case of regional cluster used latest master version of first of available zones, and in case of
zonal cluster - latest master version of var.zones[0] zone
    location = local.zone_count == 0 ? data.google_compute_zones.available.names[0] : var.zones[0]
Fixes terraform-google-modules#161
  • Loading branch information
kopachevsky committed Aug 15, 2019
1 parent ed58124 commit 687703b
Show file tree
Hide file tree
Showing 40 changed files with 1,113 additions and 2,715 deletions.
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ DOCKER_REPO_BASE_KITCHEN_TERRAFORM := ${DOCKER_ORG}/cft/kitchen-terraform:${DOCK
all: check generate_docs

.PHONY: check
check: check_shell check_python check_golang check_terraform check_docker check_base_files test_check_headers check_headers check_trailing_whitespace check_generate check_generate_docs
check: check_shell check_python check_golang check_terraform check_base_files test_check_headers check_headers check_trailing_whitespace check_generate check_generate_docs

# The .PHONY directive tells make that this isn't a real target and so
# the presence of a file named 'check_shell' won't cause this target to stop
Expand All @@ -47,10 +47,6 @@ check_golang:
check_terraform:
@source test/make.sh && check_terraform

.PHONY: check_docker
check_docker:
@source test/make.sh && docker

.PHONY: check_base_files
check_base_files:
@source test/make.sh && basefiles
Expand Down
32 changes: 13 additions & 19 deletions autogen/cluster_regional.tf → autogen/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{{ autogeneration_note }}

/******************************************
Create regional cluster
Create Container Cluster
*****************************************/
resource "google_container_cluster" "primary" {
{% if private_cluster or beta_cluster %}
Expand All @@ -26,18 +26,13 @@ resource "google_container_cluster" "primary" {
provider = google
{% endif %}

count = var.regional ? 1 : 0
name = var.name
description = var.description
project = var.project_id
resource_labels = var.cluster_resource_labels

region = var.region
node_locations = coalescelist(
compact(var.zones),
sort(random_shuffle.available_zones.result),
)

location = local.location
node_locations = local.node_locations
cluster_ipv4_cidr = var.cluster_ipv4_cidr
network = data.google_compute_network.gke_network.self_link

Expand All @@ -51,7 +46,7 @@ resource "google_container_cluster" "primary" {
}

subnetwork = data.google_compute_subnetwork.gke_subnetwork.self_link
min_master_version = local.kubernetes_version_regional
min_master_version = local.master_version

logging_service = var.logging_service
monitoring_service = var.monitoring_service
Expand Down Expand Up @@ -173,8 +168,8 @@ resource "google_container_cluster" "primary" {
enable_private_nodes = var.enable_private_nodes
master_ipv4_cidr_block = var.master_ipv4_cidr_block
}

{% endif %}

remove_default_node_pool = var.remove_default_node_pool
{% if beta_cluster %}

Expand All @@ -190,19 +185,19 @@ resource "google_container_cluster" "primary" {
}

/******************************************
Create regional node pools
Create Container Cluster node pools
*****************************************/
resource "google_container_node_pool" "pools" {
provider = google-beta
count = var.regional ? length(var.node_pools) : 0
count = length(var.node_pools)
name = var.node_pools[count.index]["name"]
project = var.project_id
region = var.region
cluster = google_container_cluster.primary[0].name
location = local.location
cluster = google_container_cluster.primary.name
version = lookup(var.node_pools[count.index], "auto_upgrade", false) ? "" : lookup(
var.node_pools[count.index],
"version",
local.node_version_regional,
local.node_version,
)
initial_node_count = lookup(
var.node_pools[count.index],
Expand All @@ -220,7 +215,7 @@ resource "google_container_node_pool" "pools" {

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

node_config {
Expand Down Expand Up @@ -278,7 +273,7 @@ resource "google_container_node_pool" "pools" {

oauth_scopes = concat(
var.node_pools_oauth_scopes["all"],
var.node_pools_oauth_scopes[var.node_pools[count.index]["name"]]
var.node_pools_oauth_scopes[var.node_pools[count.index]["name"]],
)

guest_accelerator = [
Expand Down Expand Up @@ -313,8 +308,7 @@ resource "google_container_node_pool" "pools" {
}
}

resource "null_resource" "wait_for_regional_cluster" {
count = var.regional ? 1 : 0
resource "null_resource" "wait_for_cluster" {

provisioner "local-exec" {
command = "${path.module}/scripts/wait-for-cluster.sh ${var.project_id} ${var.name}"
Expand Down
Loading

0 comments on commit 687703b

Please sign in to comment.