Skip to content

Commit 075e9c2

Browse files
authored
Merge pull request #193 from SubatomicHero/feature/cluster_ipv4_cidr
Feature/cluster ipv4 cidr
2 parents f34320d + 2c38f12 commit 075e9c2

29 files changed

+179
-116
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ In either case, upgrading to module version `v1.0.0` will trigger a recreation o
116116
|------|-------------|:----:|:-----:|:-----:|
117117
| basic\_auth\_password | The password to be used with Basic Authentication. | string | `""` | no |
118118
| basic\_auth\_username | The username to be used with Basic Authentication. An empty value will disable Basic Authentication, which is the recommended configuration. | string | `""` | no |
119+
| cluster\_ipv4\_cidr | The IP address range of the kubernetes pods in this cluster. Default is an automatically assigned CIDR. | string | `""` | no |
119120
| description | The description of the cluster | string | `""` | no |
120121
| disable\_legacy\_metadata\_endpoints | Disable the /0.1/ and /v1beta1/ metadata server endpoints on the node. Changing this value will cause all node pools to be recreated. | string | `"true"` | no |
121122
| horizontal\_pod\_autoscaling | Enable horizontal pod autoscaling addon | string | `"true"` | no |
@@ -233,8 +234,10 @@ To more cleanly handle cases where desired functionality would require complex d
233234

234235
The root module is generated by running `make generate`. Changes to this repository should be made in the [`autogen`](/autogen) directory where appropriate.
235236

236-
Note: The correct sequence to update the repo using autogen functionality is the run `make generate && make generate_docs`. This
237-
will create the various Terraform files, and then generate the Terraform documentation using `terraform-docs`.
237+
Note: The correct sequence to update the repo using autogen
238+
functionality is the run `make generate && make generate_docs`. This
239+
will create the various Terraform files, and then generate the
240+
Terraform documentation using `terraform-docs`.
238241

239242
## Testing
240243

autogen/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ To more cleanly handle cases where desired functionality would require complex d
182182

183183
The root module is generated by running `make generate`. Changes to this repository should be made in the [`autogen`](/autogen) directory where appropriate.
184184

185+
Note: The correct sequence to update the repo using autogen
186+
functionality is the run `make generate && make generate_docs`. This
187+
will create the various Terraform files, and then generate the
188+
Terraform documentation using `terraform-docs`.
189+
185190
## Testing
186191

187192
### Requirements

autogen/cluster_regional.tf

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ resource "google_container_cluster" "primary" {
2626
description = "${var.description}"
2727
project = "${var.project_id}"
2828

29-
region = "${var.region}"
30-
node_locations = ["${coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result))}"]
31-
32-
network = "${replace(data.google_compute_network.gke_network.self_link, "https://www.googleapis.com/compute/v1/", "")}"
29+
region = "${var.region}"
30+
node_locations = ["${coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result))}"]
31+
cluster_ipv4_cidr = "${var.cluster_ipv4_cidr}"
32+
network = "${replace(data.google_compute_network.gke_network.self_link, "https://www.googleapis.com/compute/v1/", "")}"
3333

3434
network_policy {
3535
enabled = "${var.network_policy}"
@@ -74,6 +74,7 @@ resource "google_container_cluster" "primary" {
7474
disabled = "${var.network_policy ? 0 : 1}"
7575
}
7676
{% if beta_cluster %}
77+
7778
istio_config {
7879
disabled = "${var.istio ? 0 : 1}"
7980
}
@@ -114,12 +115,14 @@ resource "google_container_cluster" "primary" {
114115
}
115116
}
116117
{% if private_cluster %}
118+
117119
private_cluster_config {
118120
enable_private_endpoint = "${var.enable_private_endpoint}"
119121
enable_private_nodes = "${var.enable_private_nodes}"
120122
master_ipv4_cidr_block = "${var.master_ipv4_cidr_block}"
121123
}
122124
{% endif %}
125+
123126
remove_default_node_pool = "${var.remove_default_node_pool}"
124127
{% if beta_cluster %}
125128
database_encryption = ["${var.database_encryption}"]

autogen/cluster_zonal.tf

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ resource "google_container_cluster" "zonal_primary" {
2626
description = "${var.description}"
2727
project = "${var.project_id}"
2828

29-
zone = "${var.zones[0]}"
30-
node_locations = ["${slice(var.zones,1,length(var.zones))}"]
31-
32-
network = "${replace(data.google_compute_network.gke_network.self_link, "https://www.googleapis.com/compute/v1/", "")}"
29+
zone = "${var.zones[0]}"
30+
node_locations = ["${slice(var.zones,1,length(var.zones))}"]
31+
cluster_ipv4_cidr = "${var.cluster_ipv4_cidr}"
32+
network = "${replace(data.google_compute_network.gke_network.self_link, "https://www.googleapis.com/compute/v1/", "")}"
3333

3434
network_policy {
3535
enabled = "${var.network_policy}"
@@ -74,6 +74,7 @@ resource "google_container_cluster" "zonal_primary" {
7474
disabled = "${var.network_policy ? 0 : 1}"
7575
}
7676
{% if beta_cluster %}
77+
7778
istio_config {
7879
disabled = "${var.istio ? 0 : 1}"
7980
}
@@ -114,12 +115,14 @@ resource "google_container_cluster" "zonal_primary" {
114115
}
115116
}
116117
{% if private_cluster %}
118+
117119
private_cluster_config {
118120
enable_private_endpoint = "${var.enable_private_endpoint}"
119121
enable_private_nodes = "${var.enable_private_nodes}"
120122
master_ipv4_cidr_block = "${var.master_ipv4_cidr_block}"
121123
}
122124
{% endif %}
125+
123126
remove_default_node_pool = "${var.remove_default_node_pool}"
124127
{% if beta_cluster %}
125128
database_encryption = ["${var.database_encryption}"]

autogen/main.tf

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,19 @@ locals {
163163
cluster_master_auth_list_layer1 = "${local.cluster_type_output_master_auth[local.cluster_type]}"
164164
cluster_master_auth_list_layer2 = "${local.cluster_master_auth_list_layer1[0]}"
165165
cluster_master_auth_map = "${local.cluster_master_auth_list_layer2[0]}"
166-
167166
# cluster locals
168-
cluster_name = "${local.cluster_type_output_name[local.cluster_type]}"
169-
cluster_location = "${local.cluster_type_output_location[local.cluster_type]}"
170-
cluster_region = "${local.cluster_type_output_region[local.cluster_type]}"
171-
cluster_zones = "${sort(local.cluster_type_output_zones[local.cluster_type])}"
172-
cluster_endpoint = "${local.cluster_type_output_endpoint[local.cluster_type]}"
173-
cluster_ca_certificate = "${lookup(local.cluster_master_auth_map, "cluster_ca_certificate")}"
174-
cluster_master_version = "${local.cluster_type_output_master_version[local.cluster_type]}"
175-
cluster_min_master_version = "${local.cluster_type_output_min_master_version[local.cluster_type]}"
176-
cluster_logging_service = "${local.cluster_type_output_logging_service[local.cluster_type]}"
177-
cluster_monitoring_service = "${local.cluster_type_output_monitoring_service[local.cluster_type]}"
178-
cluster_node_pools_names = "${local.cluster_type_output_node_pools_names[local.cluster_type]}"
179-
cluster_node_pools_versions = "${local.cluster_type_output_node_pools_versions[local.cluster_type]}"
180-
167+
cluster_name = "${local.cluster_type_output_name[local.cluster_type]}"
168+
cluster_location = "${local.cluster_type_output_location[local.cluster_type]}"
169+
cluster_region = "${local.cluster_type_output_region[local.cluster_type]}"
170+
cluster_zones = "${sort(local.cluster_type_output_zones[local.cluster_type])}"
171+
cluster_endpoint = "${local.cluster_type_output_endpoint[local.cluster_type]}"
172+
cluster_ca_certificate = "${lookup(local.cluster_master_auth_map, "cluster_ca_certificate")}"
173+
cluster_master_version = "${local.cluster_type_output_master_version[local.cluster_type]}"
174+
cluster_min_master_version = "${local.cluster_type_output_min_master_version[local.cluster_type]}"
175+
cluster_logging_service = "${local.cluster_type_output_logging_service[local.cluster_type]}"
176+
cluster_monitoring_service = "${local.cluster_type_output_monitoring_service[local.cluster_type]}"
177+
cluster_node_pools_names = "${local.cluster_type_output_node_pools_names[local.cluster_type]}"
178+
cluster_node_pools_versions = "${local.cluster_type_output_node_pools_versions[local.cluster_type]}"
181179
cluster_network_policy_enabled = "${local.cluster_type_output_network_policy_enabled[local.cluster_type] ? false : true}"
182180
cluster_http_load_balancing_enabled = "${local.cluster_type_output_http_load_balancing_enabled[local.cluster_type] ? false : true}"
183181
cluster_horizontal_pod_autoscaling_enabled = "${local.cluster_type_output_horizontal_pod_autoscaling_enabled[local.cluster_type] ? false : true}"

autogen/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ output "service_account" {
112112
description = "The service account to default running nodes as if not overridden in `node_pools`."
113113
value = "${local.service_account}"
114114
}
115-
116115
{% if beta_cluster %}
116+
117117
output "istio_enabled" {
118118
description = "Whether Istio is enabled"
119119
value = "${local.cluster_istio_enabled}"
@@ -124,8 +124,8 @@ output "cloudrun_enabled" {
124124
value = "${local.cluster_cloudrun_enabled}"
125125
}
126126
{% endif %}
127-
128127
{% if private_cluster %}
128+
129129
output "pod_security_policy_enabled" {
130130
description = "Whether pod security policy is enabled"
131131
value = "${local.cluster_pod_security_policy_enabled}"

autogen/variables.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ variable "service_account" {
251251
description = "The service account to run nodes as if not overridden in `node_pools`. The default value will cause a cluster-specific service account to be created."
252252
default = "create"
253253
}
254-
255254
{% if private_cluster %}
255+
256256
variable "deploy_using_private_endpoint" {
257257
description = "(Beta) A toggle for Terraform and kubectl to connect to the master's internal IP address during deployment."
258258
default = "false"
@@ -273,8 +273,8 @@ variable "master_ipv4_cidr_block" {
273273
default = "10.0.0.0/28"
274274
}
275275
{% endif %}
276-
277276
{% if beta_cluster %}
277+
278278
variable "istio" {
279279
description = "(Beta) Enable Istio addon"
280280
default = false
@@ -315,3 +315,8 @@ variable "issue_client_certificate" {
315315
description = "Issues a client certificate to authenticate to the cluster endpoint. To maximize the security of your cluster, leave this option disabled. Client certificates don't automatically rotate and aren't easily revocable. WARNING: changing this after cluster creation is destructive!"
316316
default = "false"
317317
}
318+
319+
variable "cluster_ipv4_cidr" {
320+
default = ""
321+
description = "The IP address range of the kubernetes pods in this cluster. Default is an automatically assigned CIDR."
322+
}

cluster_regional.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ resource "google_container_cluster" "primary" {
2626
description = "${var.description}"
2727
project = "${var.project_id}"
2828

29-
region = "${var.region}"
30-
node_locations = ["${coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result))}"]
31-
32-
network = "${replace(data.google_compute_network.gke_network.self_link, "https://www.googleapis.com/compute/v1/", "")}"
29+
region = "${var.region}"
30+
node_locations = ["${coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result))}"]
31+
cluster_ipv4_cidr = "${var.cluster_ipv4_cidr}"
32+
network = "${replace(data.google_compute_network.gke_network.self_link, "https://www.googleapis.com/compute/v1/", "")}"
3333

3434
network_policy {
3535
enabled = "${var.network_policy}"
@@ -100,6 +100,7 @@ resource "google_container_cluster" "primary" {
100100
service_account = "${lookup(var.node_pools[0], "service_account", local.service_account)}"
101101
}
102102
}
103+
103104
remove_default_node_pool = "${var.remove_default_node_pool}"
104105
}
105106

cluster_zonal.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ resource "google_container_cluster" "zonal_primary" {
2626
description = "${var.description}"
2727
project = "${var.project_id}"
2828

29-
zone = "${var.zones[0]}"
30-
node_locations = ["${slice(var.zones,1,length(var.zones))}"]
31-
32-
network = "${replace(data.google_compute_network.gke_network.self_link, "https://www.googleapis.com/compute/v1/", "")}"
29+
zone = "${var.zones[0]}"
30+
node_locations = ["${slice(var.zones,1,length(var.zones))}"]
31+
cluster_ipv4_cidr = "${var.cluster_ipv4_cidr}"
32+
network = "${replace(data.google_compute_network.gke_network.self_link, "https://www.googleapis.com/compute/v1/", "")}"
3333

3434
network_policy {
3535
enabled = "${var.network_policy}"
@@ -100,6 +100,7 @@ resource "google_container_cluster" "zonal_primary" {
100100
service_account = "${lookup(var.node_pools[0], "service_account", local.service_account)}"
101101
}
102102
}
103+
103104
remove_default_node_pool = "${var.remove_default_node_pool}"
104105
}
105106

main.tf

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,18 @@ locals {
128128
cluster_master_auth_map = "${local.cluster_master_auth_list_layer2[0]}"
129129

130130
# cluster locals
131-
cluster_name = "${local.cluster_type_output_name[local.cluster_type]}"
132-
cluster_location = "${local.cluster_type_output_location[local.cluster_type]}"
133-
cluster_region = "${local.cluster_type_output_region[local.cluster_type]}"
134-
cluster_zones = "${sort(local.cluster_type_output_zones[local.cluster_type])}"
135-
cluster_endpoint = "${local.cluster_type_output_endpoint[local.cluster_type]}"
136-
cluster_ca_certificate = "${lookup(local.cluster_master_auth_map, "cluster_ca_certificate")}"
137-
cluster_master_version = "${local.cluster_type_output_master_version[local.cluster_type]}"
138-
cluster_min_master_version = "${local.cluster_type_output_min_master_version[local.cluster_type]}"
139-
cluster_logging_service = "${local.cluster_type_output_logging_service[local.cluster_type]}"
140-
cluster_monitoring_service = "${local.cluster_type_output_monitoring_service[local.cluster_type]}"
141-
cluster_node_pools_names = "${local.cluster_type_output_node_pools_names[local.cluster_type]}"
142-
cluster_node_pools_versions = "${local.cluster_type_output_node_pools_versions[local.cluster_type]}"
143-
131+
cluster_name = "${local.cluster_type_output_name[local.cluster_type]}"
132+
cluster_location = "${local.cluster_type_output_location[local.cluster_type]}"
133+
cluster_region = "${local.cluster_type_output_region[local.cluster_type]}"
134+
cluster_zones = "${sort(local.cluster_type_output_zones[local.cluster_type])}"
135+
cluster_endpoint = "${local.cluster_type_output_endpoint[local.cluster_type]}"
136+
cluster_ca_certificate = "${lookup(local.cluster_master_auth_map, "cluster_ca_certificate")}"
137+
cluster_master_version = "${local.cluster_type_output_master_version[local.cluster_type]}"
138+
cluster_min_master_version = "${local.cluster_type_output_min_master_version[local.cluster_type]}"
139+
cluster_logging_service = "${local.cluster_type_output_logging_service[local.cluster_type]}"
140+
cluster_monitoring_service = "${local.cluster_type_output_monitoring_service[local.cluster_type]}"
141+
cluster_node_pools_names = "${local.cluster_type_output_node_pools_names[local.cluster_type]}"
142+
cluster_node_pools_versions = "${local.cluster_type_output_node_pools_versions[local.cluster_type]}"
144143
cluster_network_policy_enabled = "${local.cluster_type_output_network_policy_enabled[local.cluster_type] ? false : true}"
145144
cluster_http_load_balancing_enabled = "${local.cluster_type_output_http_load_balancing_enabled[local.cluster_type] ? false : true}"
146145
cluster_horizontal_pod_autoscaling_enabled = "${local.cluster_type_output_horizontal_pod_autoscaling_enabled[local.cluster_type] ? false : true}"

modules/beta-private-cluster/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ In either case, upgrading to module version `v1.0.0` will trigger a recreation o
124124
| basic\_auth\_password | The password to be used with Basic Authentication. | string | `""` | no |
125125
| basic\_auth\_username | The username to be used with Basic Authentication. An empty value will disable Basic Authentication, which is the recommended configuration. | string | `""` | no |
126126
| cloudrun | (Beta) Enable CloudRun addon | string | `"false"` | no |
127+
| cluster\_ipv4\_cidr | The IP address range of the kubernetes pods in this cluster. Default is an automatically assigned CIDR. | string | `""` | no |
127128
| database\_encryption | Application-layer Secrets Encryption settings. Example: database_encryption = [{ state = "ENCRYPTED", key_name = "projects/my-project/locations/global/keyRings/my-ring/cryptoKeys/my-key" }] | list | `<list>` | no |
128129
| deploy\_using\_private\_endpoint | (Beta) A toggle for Terraform and kubectl to connect to the master's internal IP address during deployment. | string | `"false"` | no |
129130
| description | The description of the cluster | string | `""` | no |
@@ -252,6 +253,11 @@ To more cleanly handle cases where desired functionality would require complex d
252253

253254
The root module is generated by running `make generate`. Changes to this repository should be made in the [`autogen`](/autogen) directory where appropriate.
254255

256+
Note: The correct sequence to update the repo using autogen
257+
functionality is the run `make generate && make generate_docs`. This
258+
will create the various Terraform files, and then generate the
259+
Terraform documentation using `terraform-docs`.
260+
255261
## Testing
256262

257263
### Requirements

modules/beta-private-cluster/cluster_regional.tf

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ resource "google_container_cluster" "primary" {
2626
description = "${var.description}"
2727
project = "${var.project_id}"
2828

29-
region = "${var.region}"
30-
node_locations = ["${coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result))}"]
31-
32-
network = "${replace(data.google_compute_network.gke_network.self_link, "https://www.googleapis.com/compute/v1/", "")}"
29+
region = "${var.region}"
30+
node_locations = ["${coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result))}"]
31+
cluster_ipv4_cidr = "${var.cluster_ipv4_cidr}"
32+
network = "${replace(data.google_compute_network.gke_network.self_link, "https://www.googleapis.com/compute/v1/", "")}"
3333

3434
network_policy {
3535
enabled = "${var.network_policy}"
@@ -71,6 +71,7 @@ resource "google_container_cluster" "primary" {
7171
network_policy_config {
7272
disabled = "${var.network_policy ? 0 : 1}"
7373
}
74+
7475
istio_config {
7576
disabled = "${var.istio ? 0 : 1}"
7677
}
@@ -109,11 +110,13 @@ resource "google_container_cluster" "primary" {
109110
service_account = "${lookup(var.node_pools[0], "service_account", local.service_account)}"
110111
}
111112
}
113+
112114
private_cluster_config {
113115
enable_private_endpoint = "${var.enable_private_endpoint}"
114116
enable_private_nodes = "${var.enable_private_nodes}"
115117
master_ipv4_cidr_block = "${var.master_ipv4_cidr_block}"
116118
}
119+
117120
remove_default_node_pool = "${var.remove_default_node_pool}"
118121
database_encryption = ["${var.database_encryption}"]
119122
}

modules/beta-private-cluster/cluster_zonal.tf

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ resource "google_container_cluster" "zonal_primary" {
2626
description = "${var.description}"
2727
project = "${var.project_id}"
2828

29-
zone = "${var.zones[0]}"
30-
node_locations = ["${slice(var.zones,1,length(var.zones))}"]
31-
32-
network = "${replace(data.google_compute_network.gke_network.self_link, "https://www.googleapis.com/compute/v1/", "")}"
29+
zone = "${var.zones[0]}"
30+
node_locations = ["${slice(var.zones,1,length(var.zones))}"]
31+
cluster_ipv4_cidr = "${var.cluster_ipv4_cidr}"
32+
network = "${replace(data.google_compute_network.gke_network.self_link, "https://www.googleapis.com/compute/v1/", "")}"
3333

3434
network_policy {
3535
enabled = "${var.network_policy}"
@@ -71,6 +71,7 @@ resource "google_container_cluster" "zonal_primary" {
7171
network_policy_config {
7272
disabled = "${var.network_policy ? 0 : 1}"
7373
}
74+
7475
istio_config {
7576
disabled = "${var.istio ? 0 : 1}"
7677
}
@@ -109,11 +110,13 @@ resource "google_container_cluster" "zonal_primary" {
109110
service_account = "${lookup(var.node_pools[0], "service_account", local.service_account)}"
110111
}
111112
}
113+
112114
private_cluster_config {
113115
enable_private_endpoint = "${var.enable_private_endpoint}"
114116
enable_private_nodes = "${var.enable_private_nodes}"
115117
master_ipv4_cidr_block = "${var.master_ipv4_cidr_block}"
116118
}
119+
117120
remove_default_node_pool = "${var.remove_default_node_pool}"
118121
database_encryption = ["${var.database_encryption}"]
119122
}

0 commit comments

Comments
 (0)