Skip to content

Commit d148c88

Browse files
committed
Remove modules/ directory, and instead generate templates directly from ./autogen
1 parent eb88453 commit d148c88

28 files changed

+658
-328
lines changed

Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ DOCKER_TAG_KITCHEN_TERRAFORM ?= ${DOCKER_TAG_BASE_KITCHEN_TERRAFORM}
2424
DOCKER_IMAGE_KITCHEN_TERRAFORM := cft/kitchen-terraform_terraform-google-kubernetes-engine
2525

2626
# All is the first target in the file so it will get picked up when you just run 'make' on its own
27-
all: check_shell check_python check_golang check_terraform check_docker check_base_files test_check_headers check_headers check_trailing_whitespace test_helpers generate_docs
27+
all: check_shell check_python check_golang check_terraform check_docker check_base_files test_check_headers check_headers check_trailing_whitespace generate_docs
2828

2929
# The .PHONY directive tells make that this isn't a real target and so
3030
# the presence of a file named 'check_shell' won't cause this target to stop
@@ -71,10 +71,6 @@ check_headers:
7171
@echo "Checking file headers"
7272
@python test/verify_boilerplate.py
7373

74-
.PHONY: test_helpers
75-
test_helpers:
76-
./test/helpers/generate_modules/test_generate_modules.py
77-
7874
# Integration tests
7975
.PHONY: test_integration
8076
test_integration:

auth.tf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
Retrieve authentication token
19+
*****************************************/
20+
data "google_client_config" "default" {}
21+
22+
/******************************************
23+
Configure provider
24+
*****************************************/
25+
provider "kubernetes" {
26+
load_config_file = false
27+
host = "https://${local.cluster_endpoint}"
28+
token = "${data.google_client_config.default.access_token}"
29+
cluster_ca_certificate = "${base64decode(local.cluster_ca_certificate)}"
30+
}

cluster_regional.tf

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
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" {
21+
count = "${var.regional ? 1 : 0}"
22+
name = "${var.name}"
23+
description = "${var.description}"
24+
project = "${var.project_id}"
25+
26+
region = "${var.region}"
27+
additional_zones = ["${coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result))}"]
28+
29+
network = "${replace(data.google_compute_network.gke_network.self_link, "https://www.googleapis.com/compute/v1/", "")}"
30+
subnetwork = "${replace(data.google_compute_subnetwork.gke_subnetwork.self_link, "https://www.googleapis.com/compute/v1/", "")}"
31+
min_master_version = "${local.kubernetes_version}"
32+
33+
logging_service = "${var.logging_service}"
34+
monitoring_service = "${var.monitoring_service}"
35+
36+
master_authorized_networks_config = "${var.master_authorized_networks_config}"
37+
38+
addons_config {
39+
http_load_balancing {
40+
disabled = "${var.http_load_balancing ? 0 : 1}"
41+
}
42+
43+
horizontal_pod_autoscaling {
44+
disabled = "${var.horizontal_pod_autoscaling ? 0 : 1}"
45+
}
46+
47+
kubernetes_dashboard {
48+
disabled = "${var.kubernetes_dashboard ? 0 : 1}"
49+
}
50+
51+
network_policy_config {
52+
disabled = "${var.network_policy ? 0 : 1}"
53+
}
54+
}
55+
56+
ip_allocation_policy {
57+
cluster_secondary_range_name = "${var.ip_range_pods}"
58+
services_secondary_range_name = "${var.ip_range_services}"
59+
}
60+
61+
maintenance_policy {
62+
daily_maintenance_window {
63+
start_time = "${var.maintenance_start_time}"
64+
}
65+
}
66+
67+
lifecycle {
68+
ignore_changes = ["node_pool"]
69+
}
70+
71+
timeouts {
72+
create = "30m"
73+
update = "30m"
74+
delete = "30m"
75+
}
76+
77+
node_pool {
78+
name = "default-pool"
79+
80+
node_config {
81+
service_account = "${lookup(var.node_pools[0], "service_account", var.service_account)}"
82+
}
83+
}
84+
85+
remove_default_node_pool = "${var.remove_default_node_pool}"
86+
}
87+
88+
/******************************************
89+
Create regional node pools
90+
*****************************************/
91+
resource "google_container_node_pool" "pools" {
92+
count = "${var.regional ? 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+
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")])}"
115+
taint = "${concat(var.node_pools_taints["all"], var.node_pools_taints[lookup(var.node_pools[count.index], "name")])}"
116+
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")])}"]
117+
118+
disk_size_gb = "${lookup(var.node_pools[count.index], "disk_size_gb", 100)}"
119+
disk_type = "${lookup(var.node_pools[count.index], "disk_type", "pd-standard")}"
120+
service_account = "${lookup(var.node_pools[count.index], "service_account", var.service_account)}"
121+
preemptible = "${lookup(var.node_pools[count.index], "preemptible", false)}"
122+
123+
oauth_scopes = [
124+
"https://www.googleapis.com/auth/cloud-platform",
125+
]
126+
}
127+
128+
lifecycle {
129+
ignore_changes = ["initial_node_count"]
130+
}
131+
132+
timeouts {
133+
create = "30m"
134+
update = "30m"
135+
delete = "30m"
136+
}
137+
138+
depends_on = ["google_container_cluster.primary"]
139+
}
140+
141+
resource "null_resource" "wait_for_regional_cluster" {
142+
count = "${var.regional ? 1 : 0}"
143+
144+
provisioner "local-exec" {
145+
command = "${path.module}/scripts/wait-for-cluster.sh ${var.project_id} ${var.name}"
146+
}
147+
148+
provisioner "local-exec" {
149+
when = "destroy"
150+
command = "${path.module}/scripts/wait-for-cluster.sh ${var.project_id} ${var.name}"
151+
}
152+
153+
depends_on = ["google_container_cluster.primary", "google_container_node_pool.pools"]
154+
}

cluster_zonal.tf

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
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 zonal cluster
19+
*****************************************/
20+
resource "google_container_cluster" "zonal_primary" {
21+
count = "${var.regional ? 0 : 1}"
22+
name = "${var.name}"
23+
description = "${var.description}"
24+
project = "${var.project_id}"
25+
26+
zone = "${var.zones[0]}"
27+
additional_zones = ["${slice(var.zones,1,length(var.zones))}"]
28+
29+
network = "${replace(data.google_compute_network.gke_network.self_link, "https://www.googleapis.com/compute/v1/", "")}"
30+
subnetwork = "${replace(data.google_compute_subnetwork.gke_subnetwork.self_link, "https://www.googleapis.com/compute/v1/", "")}"
31+
min_master_version = "${local.kubernetes_version}"
32+
33+
logging_service = "${var.logging_service}"
34+
monitoring_service = "${var.monitoring_service}"
35+
36+
master_authorized_networks_config = "${var.master_authorized_networks_config}"
37+
38+
addons_config {
39+
http_load_balancing {
40+
disabled = "${var.http_load_balancing ? 0 : 1}"
41+
}
42+
43+
horizontal_pod_autoscaling {
44+
disabled = "${var.horizontal_pod_autoscaling ? 0 : 1}"
45+
}
46+
47+
kubernetes_dashboard {
48+
disabled = "${var.kubernetes_dashboard ? 0 : 1}"
49+
}
50+
51+
network_policy_config {
52+
disabled = "${var.network_policy ? 0 : 1}"
53+
}
54+
}
55+
56+
ip_allocation_policy {
57+
cluster_secondary_range_name = "${var.ip_range_pods}"
58+
services_secondary_range_name = "${var.ip_range_services}"
59+
}
60+
61+
maintenance_policy {
62+
daily_maintenance_window {
63+
start_time = "${var.maintenance_start_time}"
64+
}
65+
}
66+
67+
lifecycle {
68+
ignore_changes = ["node_pool"]
69+
}
70+
71+
timeouts {
72+
create = "30m"
73+
update = "30m"
74+
delete = "30m"
75+
}
76+
77+
node_pool {
78+
name = "default-pool"
79+
80+
node_config {
81+
service_account = "${lookup(var.node_pools[0], "service_account", var.service_account)}"
82+
}
83+
}
84+
85+
remove_default_node_pool = "${var.remove_default_node_pool}"
86+
}
87+
88+
/******************************************
89+
Create zonal node pools
90+
*****************************************/
91+
resource "google_container_node_pool" "zonal_pools" {
92+
count = "${var.regional ? 0 : length(var.node_pools)}"
93+
name = "${lookup(var.node_pools[count.index], "name")}"
94+
project = "${var.project_id}"
95+
zone = "${var.zones[0]}"
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", false)}"
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+
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")])}"
115+
taint = "${concat(var.node_pools_taints["all"], var.node_pools_taints[lookup(var.node_pools[count.index], "name")])}"
116+
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")])}"]
117+
118+
disk_size_gb = "${lookup(var.node_pools[count.index], "disk_size_gb", 100)}"
119+
disk_type = "${lookup(var.node_pools[count.index], "disk_type", "pd-standard")}"
120+
service_account = "${lookup(var.node_pools[count.index], "service_account", var.service_account)}"
121+
preemptible = "${lookup(var.node_pools[count.index], "preemptible", false)}"
122+
123+
oauth_scopes = [
124+
"https://www.googleapis.com/auth/cloud-platform",
125+
]
126+
}
127+
128+
lifecycle {
129+
ignore_changes = ["initial_node_count"]
130+
}
131+
132+
timeouts {
133+
create = "30m"
134+
update = "30m"
135+
delete = "30m"
136+
}
137+
138+
depends_on = ["google_container_cluster.zonal_primary"]
139+
}
140+
141+
resource "null_resource" "wait_for_zonal_cluster" {
142+
count = "${var.regional ? 0 : 1}"
143+
144+
provisioner "local-exec" {
145+
command = "${path.module}/scripts/wait-for-cluster.sh ${var.project_id} ${var.name}"
146+
}
147+
148+
provisioner "local-exec" {
149+
when = "destroy"
150+
command = "${path.module}/scripts/wait-for-cluster.sh ${var.project_id} ${var.name}"
151+
}
152+
153+
depends_on = ["google_container_cluster.zonal_primary", "google_container_node_pool.zonal_pools"]
154+
}

0 commit comments

Comments
 (0)