Skip to content

Commit ee437e3

Browse files
committed
Add support for private clusters
1 parent 5644f71 commit ee437e3

File tree

31 files changed

+1337
-60
lines changed

31 files changed

+1337
-60
lines changed

.kitchen.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ suites:
7272
backend: local
7373
provisioner:
7474
name: terraform
75+
- name: "simple_regional_private"
76+
driver:
77+
name: "terraform"
78+
command_timeout: 1800
79+
root_module_directory: test/fixtures/simple_regional_private
80+
verifier:
81+
name: terraform
82+
systems:
83+
- name: simple_regional_private
84+
backend: local
85+
provisioner:
86+
name: terraform
7587
- name: "simple_zonal"
7688
driver:
7789
name: "terraform"
@@ -84,6 +96,18 @@ suites:
8496
backend: local
8597
provisioner:
8698
name: terraform
99+
- name: "simple_zonal_private"
100+
driver:
101+
name: "terraform"
102+
command_timeout: 1800
103+
root_module_directory: test/fixtures/simple_zonal_private
104+
verifier:
105+
name: terraform
106+
systems:
107+
- name: simple_zonal_private
108+
backend: local
109+
provisioner:
110+
name: terraform
87111
- name: "stub_domains"
88112
driver:
89113
name: "terraform"

cluster_regional.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*****************************************/
2020
resource "google_container_cluster" "primary" {
2121
provider = "google-beta"
22-
count = "${var.regional ? 1 : 0}"
22+
count = "${(local.cluster_deployment_type == "regional") ? 1 : 0}"
2323
name = "${var.name}"
2424
description = "${var.description}"
2525
project = "${var.project_id}"
@@ -34,7 +34,7 @@ resource "google_container_cluster" "primary" {
3434
logging_service = "${var.logging_service}"
3535
monitoring_service = "${var.monitoring_service}"
3636

37-
master_authorized_networks_config = "${var.master_authorized_networks_config}"
37+
master_authorized_networks_config = ["${var.master_authorized_networks_config}"]
3838

3939
addons_config {
4040
http_load_balancing {
@@ -89,7 +89,7 @@ resource "google_container_cluster" "primary" {
8989
*****************************************/
9090
resource "google_container_node_pool" "pools" {
9191
provider = "google-beta"
92-
count = "${var.regional ? length(var.node_pools) : 0}"
92+
count = "${(local.cluster_deployment_type == "regional") ? length(var.node_pools) : 0}"
9393
name = "${lookup(var.node_pools[count.index], "name")}"
9494
project = "${var.project_id}"
9595
region = "${var.region}"
@@ -138,7 +138,7 @@ resource "google_container_node_pool" "pools" {
138138
}
139139

140140
resource "null_resource" "wait_for_regional_cluster" {
141-
count = "${var.regional ? 1 : 0}"
141+
count = "${(local.cluster_deployment_type == "regional") ? 1 : 0}"
142142

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

cluster_regional_private.tf

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/******************************************
18+
Create regional cluster
19+
*****************************************/
20+
resource "google_container_cluster" "primary_private" {
21+
provider = "google-beta"
22+
count = "${(local.cluster_deployment_type == "regional_private") ? 1 : 0}"
23+
name = "${var.name}"
24+
description = "${var.description}"
25+
project = "${var.project_id}"
26+
27+
region = "${var.region}"
28+
additional_zones = ["${coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result))}"]
29+
30+
network = "${data.google_compute_network.gke_network.self_link}"
31+
subnetwork = "${data.google_compute_subnetwork.gke_subnetwork.self_link}"
32+
min_master_version = "${local.kubernetes_version}"
33+
34+
logging_service = "${var.logging_service}"
35+
monitoring_service = "${var.monitoring_service}"
36+
37+
master_authorized_networks_config = ["${var.master_authorized_networks_config}"]
38+
39+
addons_config {
40+
http_load_balancing {
41+
disabled = "${var.http_load_balancing ? 0 : 1}"
42+
}
43+
44+
horizontal_pod_autoscaling {
45+
disabled = "${var.horizontal_pod_autoscaling ? 0 : 1}"
46+
}
47+
48+
kubernetes_dashboard {
49+
disabled = "${var.kubernetes_dashboard ? 0 : 1}"
50+
}
51+
52+
network_policy_config {
53+
disabled = "${var.network_policy ? 0 : 1}"
54+
}
55+
}
56+
57+
ip_allocation_policy {
58+
cluster_secondary_range_name = "${var.ip_range_pods}"
59+
services_secondary_range_name = "${var.ip_range_services}"
60+
}
61+
62+
maintenance_policy {
63+
daily_maintenance_window {
64+
start_time = "${var.maintenance_start_time}"
65+
}
66+
}
67+
68+
lifecycle {
69+
ignore_changes = ["node_pool"]
70+
}
71+
72+
timeouts {
73+
create = "30m"
74+
update = "30m"
75+
delete = "30m"
76+
}
77+
78+
node_pool {
79+
name = "default-pool"
80+
81+
node_config {
82+
service_account = "${lookup(var.node_pools[0], "service_account", var.service_account)}"
83+
}
84+
}
85+
}
86+
87+
/******************************************
88+
Create regional node pools
89+
*****************************************/
90+
resource "google_container_node_pool" "pools_private" {
91+
provider = "google-beta"
92+
count = "${(local.cluster_deployment_type == "regional_private") ? length(var.node_pools) : 0}"
93+
name = "${lookup(var.node_pools[count.index], "name")}"
94+
project = "${var.project_id}"
95+
region = "${var.region}"
96+
cluster = "${var.name}"
97+
version = "${lookup(var.node_pools[count.index], "auto_upgrade", false) ? "" : lookup(var.node_pools[count.index], "version", local.node_version)}"
98+
initial_node_count = "${lookup(var.node_pools[count.index], "min_count", 1)}"
99+
100+
autoscaling {
101+
min_node_count = "${lookup(var.node_pools[count.index], "min_count", 1)}"
102+
max_node_count = "${lookup(var.node_pools[count.index], "max_count", 100)}"
103+
}
104+
105+
management {
106+
auto_repair = "${lookup(var.node_pools[count.index], "auto_repair", true)}"
107+
auto_upgrade = "${lookup(var.node_pools[count.index], "auto_upgrade", true)}"
108+
}
109+
110+
node_config {
111+
image_type = "${lookup(var.node_pools[count.index], "image_type", "COS")}"
112+
machine_type = "${lookup(var.node_pools[count.index], "machine_type", "n1-standard-2")}"
113+
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")])}"
114+
taint = "${concat(var.node_pools_taints["all"], var.node_pools_taints[lookup(var.node_pools[count.index], "name")])}"
115+
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")])}"
116+
117+
disk_size_gb = "${lookup(var.node_pools[count.index], "disk_size_gb", 100)}"
118+
disk_type = "${lookup(var.node_pools[count.index], "disk_type", "pd-standard")}"
119+
service_account = "${lookup(var.node_pools[count.index], "service_account", var.service_account)}"
120+
preemptible = "${lookup(var.node_pools[count.index], "preemptible", false)}"
121+
122+
oauth_scopes = [
123+
"https://www.googleapis.com/auth/cloud-platform",
124+
]
125+
}
126+
127+
lifecycle {
128+
ignore_changes = ["initial_node_count"]
129+
}
130+
131+
timeouts {
132+
create = "30m"
133+
update = "30m"
134+
delete = "30m"
135+
}
136+
137+
depends_on = ["google_container_cluster.primary_private"]
138+
}
139+
140+
resource "null_resource" "wait_for_private_regional_cluster" {
141+
count = "${(local.cluster_deployment_type == "regional_private") ? 1 : 0}"
142+
143+
provisioner "local-exec" {
144+
command = "${path.module}/scripts/wait-for-cluster.sh ${var.project_id} ${var.name}"
145+
}
146+
147+
provisioner "local-exec" {
148+
when = "destroy"
149+
command = "${path.module}/scripts/wait-for-cluster.sh ${var.project_id} ${var.name}"
150+
}
151+
152+
depends_on = ["google_container_cluster.primary_private", "google_container_node_pool.pools_private"]
153+
}

cluster_zonal.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*****************************************/
2020
resource "google_container_cluster" "zonal_primary" {
2121
provider = "google-beta"
22-
count = "${var.regional ? 0 : 1}"
22+
count = "${(local.cluster_deployment_type == "zonal") ? 1 : 0}"
2323
name = "${var.name}"
2424
description = "${var.description}"
2525
project = "${var.project_id}"
@@ -34,7 +34,7 @@ resource "google_container_cluster" "zonal_primary" {
3434
logging_service = "${var.logging_service}"
3535
monitoring_service = "${var.monitoring_service}"
3636

37-
master_authorized_networks_config = "${var.master_authorized_networks_config}"
37+
master_authorized_networks_config = ["${var.master_authorized_networks_config}"]
3838

3939
addons_config {
4040
http_load_balancing {
@@ -89,7 +89,7 @@ resource "google_container_cluster" "zonal_primary" {
8989
*****************************************/
9090
resource "google_container_node_pool" "zonal_pools" {
9191
provider = "google-beta"
92-
count = "${var.regional ? 0 : length(var.node_pools)}"
92+
count = "${(local.cluster_deployment_type == "zonal") ? length(var.node_pools) : 0}"
9393
name = "${lookup(var.node_pools[count.index], "name")}"
9494
project = "${var.project_id}"
9595
zone = "${var.zones[0]}"
@@ -138,7 +138,7 @@ resource "google_container_node_pool" "zonal_pools" {
138138
}
139139

140140
resource "null_resource" "wait_for_zonal_cluster" {
141-
count = "${var.regional ? 0 : 1}"
141+
count = "${(local.cluster_deployment_type == "zonal") ? 1 : 0}"
142142

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

0 commit comments

Comments
 (0)