Skip to content

Commit 6169fcb

Browse files
committed
Move root Terraform files to ./autogen/ directory, and set up submodule structure
1 parent a7122c3 commit 6169fcb

31 files changed

+1874
-186
lines changed

Makefile

Lines changed: 10 additions & 1 deletion
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 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 test_helpers 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,6 +71,10 @@ 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+
7478
# Integration tests
7579
.PHONY: test_integration
7680
test_integration:
@@ -85,6 +89,11 @@ test_integration:
8589
generate_docs:
8690
@source test/make.sh && generate_docs
8791

92+
.PHONY: generate
93+
generate:
94+
@pip install -r ./helpers/generate_modules/requirements.txt
95+
@./helpers/generate_modules/generate_modules.py
96+
8897
# Versioning
8998
.PHONY: version
9099
version:

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,25 @@ The project has the following folders and files:
198198

199199
- /: root folder
200200
- /examples: examples for using this module
201+
- /helpers: Helper scripts
202+
- /modules: Specific implementations of the module (see Submodules section of this file)
201203
- /scripts: Scripts for specific tasks on module (see Infrastructure section on this file)
202204
- /test: Folders with files for testing the module (see Testing section on this file)
203205
- /main.tf: main file for this module, contains all the resources to create
204206
- /variables.tf: all the variables for the module
205207
- /output.tf: the outputs of the module
206208
- /readme.MD: this file
207209

210+
## Submodules
211+
212+
To more cleanly handle cases where desired functionality would require complex duplication of Terraform resources (i.e. [PR 51](https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/pull/51)), this repository is divided into multiple submodules. To ensure backwards compatibility with the module before this change, using the root of the repository as the source of a module will default to the [./modules/public-cluster](`public-cluster`) submodule.
213+
214+
The following submodules currently exist:
215+
216+
- [./modules/public-cluster](`public-cluster`), which creates a GKE cluster with its nodes and endpoint publicly accessible.
217+
218+
Submodules, and the reverse-compatible wrapper for the root of the repository, are generated by running `make generate`. When making changes to this repository, please ensure that your change is made in the [./autogen](`autogen`) directory if it is expected to propagate to all submodules.
219+
208220
## Testing
209221

210222
### Requirements

auth.tf renamed to autogen/auth.tf

File renamed without changes.
File renamed without changes.
File renamed without changes.

dns.tf renamed to autogen/dns.tf

File renamed without changes.

autogen/main.tf

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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+
Get available zones in region
19+
*****************************************/
20+
data "google_compute_zones" "available" {
21+
project = "${var.project_id}"
22+
region = "${var.region}"
23+
}
24+
25+
resource "random_shuffle" "available_zones" {
26+
input = ["${data.google_compute_zones.available.names}"]
27+
result_count = 3
28+
}
29+
30+
locals {
31+
kubernetes_version = "${var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.region.latest_node_version}"
32+
node_version = "${var.node_version != "" ? var.node_version : local.kubernetes_version}"
33+
custom_kube_dns_config = "${length(keys(var.stub_domains)) > 0 ? true : false}"
34+
network_project_id = "${var.network_project_id != "" ? var.network_project_id : var.project_id}"
35+
36+
cluster_type = "${var.regional ? "regional" : "zonal"}"
37+
38+
cluster_type_output_name = {
39+
regional = "${element(concat(google_container_cluster.primary.*.name, list("")), 0)}"
40+
zonal = "${element(concat(google_container_cluster.zonal_primary.*.name, list("")), 0)}"
41+
}
42+
43+
cluster_type_output_location = {
44+
regional = "${element(concat(google_container_cluster.primary.*.region, list("")), 0)}"
45+
zonal = "${element(concat(google_container_cluster.zonal_primary.*.zone, list("")), 0)}"
46+
}
47+
48+
cluster_type_output_region = {
49+
regional = "${element(concat(google_container_cluster.primary.*.region, list("")), 0)}"
50+
zonal = "${var.region}"
51+
}
52+
53+
cluster_type_output_regional_zones = "${concat(google_container_cluster.primary.*.additional_zones, list(list()))}"
54+
cluster_type_output_zonal_zones = "${concat(slice(var.zones,1,length(var.zones)), list(list()))}"
55+
56+
cluster_type_output_zones = {
57+
regional = "${local.cluster_type_output_regional_zones[0]}"
58+
zonal = "${concat(google_container_cluster.zonal_primary.*.zone, local.cluster_type_output_zonal_zones[0])}"
59+
}
60+
61+
cluster_type_output_endpoint = {
62+
regional = "${element(concat(google_container_cluster.primary.*.endpoint, list("")), 0)}"
63+
zonal = "${element(concat(google_container_cluster.zonal_primary.*.endpoint, list("")), 0)}"
64+
}
65+
66+
cluster_type_output_master_auth = {
67+
regional = "${concat(google_container_cluster.primary.*.master_auth, list())}"
68+
zonal = "${concat(google_container_cluster.zonal_primary.*.master_auth, list())}"
69+
}
70+
71+
cluster_type_output_master_version = {
72+
regional = "${element(concat(google_container_cluster.primary.*.master_version, list("")), 0)}"
73+
zonal = "${element(concat(google_container_cluster.zonal_primary.*.master_version, list("")), 0)}"
74+
}
75+
76+
cluster_type_output_min_master_version = {
77+
regional = "${element(concat(google_container_cluster.primary.*.min_master_version, list("")), 0)}"
78+
zonal = "${element(concat(google_container_cluster.zonal_primary.*.min_master_version, list("")), 0)}"
79+
}
80+
81+
cluster_type_output_logging_service = {
82+
regional = "${element(concat(google_container_cluster.primary.*.logging_service, list("")), 0)}"
83+
zonal = "${element(concat(google_container_cluster.zonal_primary.*.logging_service, list("")), 0)}"
84+
}
85+
86+
cluster_type_output_monitoring_service = {
87+
regional = "${element(concat(google_container_cluster.primary.*.monitoring_service, list("")), 0)}"
88+
zonal = "${element(concat(google_container_cluster.zonal_primary.*.monitoring_service, list("")), 0)}"
89+
}
90+
91+
cluster_type_output_network_policy_enabled = {
92+
regional = "${element(concat(google_container_cluster.primary.*.addons_config.0.network_policy_config.0.disabled, list("")), 0)}"
93+
zonal = "${element(concat(google_container_cluster.zonal_primary.*.addons_config.0.network_policy_config.0.disabled, list("")), 0)}"
94+
}
95+
96+
cluster_type_output_http_load_balancing_enabled = {
97+
regional = "${element(concat(google_container_cluster.primary.*.addons_config.0.http_load_balancing.0.disabled, list("")), 0)}"
98+
zonal = "${element(concat(google_container_cluster.zonal_primary.*.addons_config.0.http_load_balancing.0.disabled, list("")), 0)}"
99+
}
100+
101+
cluster_type_output_horizontal_pod_autoscaling_enabled = {
102+
regional = "${element(concat(google_container_cluster.primary.*.addons_config.0.horizontal_pod_autoscaling.0.disabled, list("")), 0)}"
103+
zonal = "${element(concat(google_container_cluster.zonal_primary.*.addons_config.0.horizontal_pod_autoscaling.0.disabled, list("")), 0)}"
104+
}
105+
106+
cluster_type_output_kubernetes_dashboard_enabled = {
107+
regional = "${element(concat(google_container_cluster.primary.*.addons_config.0.kubernetes_dashboard.0.disabled, list("")), 0)}"
108+
zonal = "${element(concat(google_container_cluster.zonal_primary.*.addons_config.0.kubernetes_dashboard.0.disabled, list("")), 0)}"
109+
}
110+
111+
cluster_type_output_node_pools_names = {
112+
regional = "${concat(google_container_node_pool.pools.*.name, list(""))}"
113+
zonal = "${concat(google_container_node_pool.zonal_pools.*.name, list(""))}"
114+
}
115+
116+
cluster_type_output_node_pools_versions = {
117+
regional = "${concat(google_container_node_pool.pools.*.version, list(""))}"
118+
zonal = "${concat(google_container_node_pool.zonal_pools.*.version, list(""))}"
119+
}
120+
121+
cluster_master_auth_list_layer1 = "${local.cluster_type_output_master_auth[local.cluster_type]}"
122+
cluster_master_auth_list_layer2 = "${local.cluster_master_auth_list_layer1[0]}"
123+
cluster_master_auth_map = "${local.cluster_master_auth_list_layer2[0]}"
124+
125+
# cluster locals
126+
cluster_name = "${local.cluster_type_output_name[local.cluster_type]}"
127+
cluster_location = "${local.cluster_type_output_location[local.cluster_type]}"
128+
cluster_region = "${local.cluster_type_output_region[local.cluster_type]}"
129+
cluster_zones = "${sort(local.cluster_type_output_zones[local.cluster_type])}"
130+
cluster_endpoint = "${local.cluster_type_output_endpoint[local.cluster_type]}"
131+
cluster_ca_certificate = "${lookup(local.cluster_master_auth_map, "cluster_ca_certificate")}"
132+
cluster_master_version = "${local.cluster_type_output_master_version[local.cluster_type]}"
133+
cluster_min_master_version = "${local.cluster_type_output_min_master_version[local.cluster_type]}"
134+
cluster_logging_service = "${local.cluster_type_output_logging_service[local.cluster_type]}"
135+
cluster_monitoring_service = "${local.cluster_type_output_monitoring_service[local.cluster_type]}"
136+
cluster_node_pools_names = "${local.cluster_type_output_node_pools_names[local.cluster_type]}"
137+
cluster_node_pools_versions = "${local.cluster_type_output_node_pools_versions[local.cluster_type]}"
138+
139+
cluster_network_policy_enabled = "${local.cluster_type_output_network_policy_enabled[local.cluster_type] ? false : true}"
140+
cluster_http_load_balancing_enabled = "${local.cluster_type_output_http_load_balancing_enabled[local.cluster_type] ? false : true}"
141+
cluster_horizontal_pod_autoscaling_enabled = "${local.cluster_type_output_horizontal_pod_autoscaling_enabled[local.cluster_type] ? false : true}"
142+
cluster_kubernetes_dashboard_enabled = "${local.cluster_type_output_kubernetes_dashboard_enabled[local.cluster_type] ? false : true}"
143+
}
144+
145+
/******************************************
146+
Get available container engine versions
147+
*****************************************/
148+
data "google_container_engine_versions" "region" {
149+
zone = "${data.google_compute_zones.available.names[0]}"
150+
project = "${var.project_id}"
151+
}

masq.tf renamed to autogen/masq.tf

File renamed without changes.
File renamed without changes.

autogen/outputs.tf

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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+
output "name" {
18+
description = "Cluster name"
19+
value = "${local.cluster_name}"
20+
}
21+
22+
output "type" {
23+
description = "Cluster type (regional / zonal)"
24+
value = "${local.cluster_type}"
25+
}
26+
27+
output "location" {
28+
description = "Cluster location (region if regional cluster, zone if zonal cluster)"
29+
value = "${local.cluster_location}"
30+
}
31+
32+
output "region" {
33+
description = "Cluster region"
34+
value = "${local.cluster_region}"
35+
}
36+
37+
output "zones" {
38+
description = "List of zones in which the cluster resides"
39+
value = "${local.cluster_zones}"
40+
}
41+
42+
output "endpoint" {
43+
sensitive = true
44+
description = "Cluster endpoint"
45+
value = "${local.cluster_endpoint}"
46+
}
47+
48+
output "min_master_version" {
49+
description = "Minimum master kubernetes version"
50+
value = "${local.cluster_min_master_version}"
51+
}
52+
53+
output "logging_service" {
54+
description = "Logging service used"
55+
value = "${local.cluster_logging_service}"
56+
}
57+
58+
output "monitoring_service" {
59+
description = "Monitoring service used"
60+
value = "${local.cluster_monitoring_service}"
61+
}
62+
63+
output "master_authorized_networks_config" {
64+
description = "Networks from which access to master is permitted"
65+
value = "${var.master_authorized_networks_config}"
66+
}
67+
68+
output "master_version" {
69+
description = "Current master kubernetes version"
70+
value = "${local.cluster_master_version}"
71+
}
72+
73+
output "ca_certificate" {
74+
sensitive = true
75+
description = "Cluster ca certificate (base64 encoded)"
76+
value = "${local.cluster_ca_certificate}"
77+
}
78+
79+
output "network_policy_enabled" {
80+
description = "Whether network policy enabled"
81+
value = "${local.cluster_network_policy_enabled}"
82+
}
83+
84+
output "http_load_balancing_enabled" {
85+
description = "Whether http load balancing enabled"
86+
value = "${local.cluster_http_load_balancing_enabled}"
87+
}
88+
89+
output "horizontal_pod_autoscaling_enabled" {
90+
description = "Whether horizontal pod autoscaling enabled"
91+
value = "${local.cluster_horizontal_pod_autoscaling_enabled}"
92+
}
93+
94+
output "kubernetes_dashboard_enabled" {
95+
description = "Whether kubernetes dashboard enabled"
96+
value = "${local.cluster_kubernetes_dashboard_enabled}"
97+
}
98+
99+
output "node_pools_names" {
100+
description = "List of node pools names"
101+
value = "${local.cluster_node_pools_names}"
102+
}
103+
104+
output "node_pools_versions" {
105+
description = "List of node pools versions"
106+
value = "${local.cluster_node_pools_versions}"
107+
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)