Skip to content

Commit f28ec9f

Browse files
authored
Merge pull request #247 from paulpalamarchuk/region_var_became_optional
Changed `region` variable
2 parents aa048e1 + c286bfc commit f28ec9f

File tree

20 files changed

+34
-19
lines changed

20 files changed

+34
-19
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Extending the adopted spec, each change should have a link to its corresponding
88

99
## [Unreleased]
1010

11+
### Changed
12+
13+
* Made `region` variable optional for zonal clusters [#247]
14+
1115
### Added
1216

1317
* Added [private](https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/tree/master/modules/private-cluster-update-variant) and [beta private](https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/tree/master/modules/beta-private-cluster-update-variant) variants which allow node pools to be created before being destroyed. [#256]
@@ -200,6 +204,7 @@ In either case, upgrading to module version `v1.0.0` will trigger a recreation o
200204
[v0.3.0]: https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/compare/v0.2.0...v0.3.0
201205
[v0.2.0]: https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/compare/v0.1.0...v0.2.0
202206

207+
[#247]: https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/pull/247
203208
[#256]: https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/pull/256
204209
[#248]: https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/pull/248
205210
[#228]: https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/pull/228

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ In either case, upgrading to module version `v1.0.0` will trigger a recreation o
165165
| node\_version | The Kubernetes version of the node pools. Defaults kubernetes_version (master) variable and can be overridden for individual node pools by setting the `version` key on them. Must be empyty or set the same as master at cluster creation. | string | `""` | no |
166166
| non\_masquerade\_cidrs | List of strings in CIDR notation that specify the IP address ranges that do not use IP masquerading. | list(string) | `<list>` | no |
167167
| project\_id | The project ID to host the cluster in (required) | string | n/a | yes |
168-
| region | The region to host the cluster in (required) | string | n/a | yes |
168+
| region | The region to host the cluster in (optional if zonal cluster / required if regional) | string | `"null"` | no |
169169
| regional | Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!) | bool | `"true"` | no |
170170
| remove\_default\_node\_pool | Remove default node pool while setting up the cluster | bool | `"false"` | no |
171171
| service\_account | The service account to run nodes as if not overridden in `node_pools`. The create_service_account variable default value (true) will cause a cluster-specific service account to be created. | string | `""` | no |

autogen/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ data "google_compute_zones" "available" {
2727
{% endif %}
2828

2929
project = var.project_id
30-
region = var.region
30+
region = local.region
3131
}
3232

3333
resource "random_shuffle" "available_zones" {
@@ -38,6 +38,7 @@ resource "random_shuffle" "available_zones" {
3838
locals {
3939
// location
4040
location = var.regional ? var.region : var.zones[0]
41+
region = var.region == null ? join("-", slice(split("-", var.zones[0]), 0, 2)) : var.region
4142
// for regional cluster - use var.zones if provided, use available otherwise, for zonal cluster use var.zones with first element extracted
4243
node_locations = var.regional ? coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result)) : slice(var.zones, 1, length(var.zones))
4344
// kuberentes version

autogen/networks.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ data "google_compute_subnetwork" "gke_subnetwork" {
3535
{% endif %}
3636

3737
name = var.subnetwork
38-
region = var.region
38+
region = local.region
3939
project = local.network_project_id
4040
}

autogen/variables.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ variable "regional" {
4040

4141
variable "region" {
4242
type = string
43-
description = "The region to host the cluster in (required)"
43+
description = "The region to host the cluster in (optional if zonal cluster / required if regional)"
44+
default = null
4445
}
4546

4647
variable "zones" {

main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ data "google_compute_zones" "available" {
2323
provider = google
2424

2525
project = var.project_id
26-
region = var.region
26+
region = local.region
2727
}
2828

2929
resource "random_shuffle" "available_zones" {
@@ -34,6 +34,7 @@ resource "random_shuffle" "available_zones" {
3434
locals {
3535
// location
3636
location = var.regional ? var.region : var.zones[0]
37+
region = var.region == null ? join("-", slice(split("-", var.zones[0]), 0, 2)) : var.region
3738
// for regional cluster - use var.zones if provided, use available otherwise, for zonal cluster use var.zones with first element extracted
3839
node_locations = var.regional ? coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result)) : slice(var.zones, 1, length(var.zones))
3940
// kuberentes version

modules/beta-private-cluster/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ In either case, upgrading to module version `v1.0.0` will trigger a recreation o
188188
| non\_masquerade\_cidrs | List of strings in CIDR notation that specify the IP address ranges that do not use IP masquerading. | list(string) | `<list>` | no |
189189
| pod\_security\_policy\_config | enabled - Enable the PodSecurityPolicy controller for this cluster. If enabled, pods must be valid under a PodSecurityPolicy to be created. | list | `<list>` | no |
190190
| project\_id | The project ID to host the cluster in (required) | string | n/a | yes |
191-
| region | The region to host the cluster in (required) | string | n/a | yes |
191+
| region | The region to host the cluster in (optional if zonal cluster / required if regional) | string | `"null"` | no |
192192
| regional | Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!) | bool | `"true"` | no |
193193
| remove\_default\_node\_pool | Remove default node pool while setting up the cluster | bool | `"false"` | no |
194194
| resource\_usage\_export\_dataset\_id | The dataset id for which network egress metering for this cluster will be enabled. If enabled, a daemonset will be created in the cluster to meter network egress traffic. | string | `""` | no |

modules/beta-private-cluster/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ data "google_compute_zones" "available" {
2323
provider = google-beta
2424

2525
project = var.project_id
26-
region = var.region
26+
region = local.region
2727
}
2828

2929
resource "random_shuffle" "available_zones" {
@@ -34,6 +34,7 @@ resource "random_shuffle" "available_zones" {
3434
locals {
3535
// location
3636
location = var.regional ? var.region : var.zones[0]
37+
region = var.region == null ? join("-", slice(split("-", var.zones[0]), 0, 2)) : var.region
3738
// for regional cluster - use var.zones if provided, use available otherwise, for zonal cluster use var.zones with first element extracted
3839
node_locations = var.regional ? coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result)) : slice(var.zones, 1, length(var.zones))
3940
// kuberentes version

modules/beta-private-cluster/networks.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ data "google_compute_subnetwork" "gke_subnetwork" {
2727
provider = google-beta
2828

2929
name = var.subnetwork
30-
region = var.region
30+
region = local.region
3131
project = local.network_project_id
3232
}

modules/beta-private-cluster/variables.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ variable "regional" {
4040

4141
variable "region" {
4242
type = string
43-
description = "The region to host the cluster in (required)"
43+
description = "The region to host the cluster in (optional if zonal cluster / required if regional)"
44+
default = null
4445
}
4546

4647
variable "zones" {

modules/beta-public-cluster/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ In either case, upgrading to module version `v1.0.0` will trigger a recreation o
179179
| non\_masquerade\_cidrs | List of strings in CIDR notation that specify the IP address ranges that do not use IP masquerading. | list(string) | `<list>` | no |
180180
| pod\_security\_policy\_config | enabled - Enable the PodSecurityPolicy controller for this cluster. If enabled, pods must be valid under a PodSecurityPolicy to be created. | list | `<list>` | no |
181181
| project\_id | The project ID to host the cluster in (required) | string | n/a | yes |
182-
| region | The region to host the cluster in (required) | string | n/a | yes |
182+
| region | The region to host the cluster in (optional if zonal cluster / required if regional) | string | `"null"` | no |
183183
| regional | Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!) | bool | `"true"` | no |
184184
| remove\_default\_node\_pool | Remove default node pool while setting up the cluster | bool | `"false"` | no |
185185
| resource\_usage\_export\_dataset\_id | The dataset id for which network egress metering for this cluster will be enabled. If enabled, a daemonset will be created in the cluster to meter network egress traffic. | string | `""` | no |

modules/beta-public-cluster/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ data "google_compute_zones" "available" {
2323
provider = google-beta
2424

2525
project = var.project_id
26-
region = var.region
26+
region = local.region
2727
}
2828

2929
resource "random_shuffle" "available_zones" {
@@ -34,6 +34,7 @@ resource "random_shuffle" "available_zones" {
3434
locals {
3535
// location
3636
location = var.regional ? var.region : var.zones[0]
37+
region = var.region == null ? join("-", slice(split("-", var.zones[0]), 0, 2)) : var.region
3738
// for regional cluster - use var.zones if provided, use available otherwise, for zonal cluster use var.zones with first element extracted
3839
node_locations = var.regional ? coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result)) : slice(var.zones, 1, length(var.zones))
3940
// kuberentes version

modules/beta-public-cluster/networks.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ data "google_compute_subnetwork" "gke_subnetwork" {
2727
provider = google-beta
2828

2929
name = var.subnetwork
30-
region = var.region
30+
region = local.region
3131
project = local.network_project_id
3232
}

modules/beta-public-cluster/variables.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ variable "regional" {
4040

4141
variable "region" {
4242
type = string
43-
description = "The region to host the cluster in (required)"
43+
description = "The region to host the cluster in (optional if zonal cluster / required if regional)"
44+
default = null
4445
}
4546

4647
variable "zones" {

modules/private-cluster/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ In either case, upgrading to module version `v1.0.0` will trigger a recreation o
174174
| node\_version | The Kubernetes version of the node pools. Defaults kubernetes_version (master) variable and can be overridden for individual node pools by setting the `version` key on them. Must be empyty or set the same as master at cluster creation. | string | `""` | no |
175175
| non\_masquerade\_cidrs | List of strings in CIDR notation that specify the IP address ranges that do not use IP masquerading. | list(string) | `<list>` | no |
176176
| project\_id | The project ID to host the cluster in (required) | string | n/a | yes |
177-
| region | The region to host the cluster in (required) | string | n/a | yes |
177+
| region | The region to host the cluster in (optional if zonal cluster / required if regional) | string | `"null"` | no |
178178
| regional | Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!) | bool | `"true"` | no |
179179
| remove\_default\_node\_pool | Remove default node pool while setting up the cluster | bool | `"false"` | no |
180180
| service\_account | The service account to run nodes as if not overridden in `node_pools`. The create_service_account variable default value (true) will cause a cluster-specific service account to be created. | string | `""` | no |

modules/private-cluster/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ data "google_compute_zones" "available" {
2323
provider = google
2424

2525
project = var.project_id
26-
region = var.region
26+
region = local.region
2727
}
2828

2929
resource "random_shuffle" "available_zones" {
@@ -34,6 +34,7 @@ resource "random_shuffle" "available_zones" {
3434
locals {
3535
// location
3636
location = var.regional ? var.region : var.zones[0]
37+
region = var.region == null ? join("-", slice(split("-", var.zones[0]), 0, 2)) : var.region
3738
// for regional cluster - use var.zones if provided, use available otherwise, for zonal cluster use var.zones with first element extracted
3839
node_locations = var.regional ? coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result)) : slice(var.zones, 1, length(var.zones))
3940
// kuberentes version

modules/private-cluster/networks.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ data "google_compute_subnetwork" "gke_subnetwork" {
2727
provider = google
2828

2929
name = var.subnetwork
30-
region = var.region
30+
region = local.region
3131
project = local.network_project_id
3232
}

modules/private-cluster/variables.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ variable "regional" {
4040

4141
variable "region" {
4242
type = string
43-
description = "The region to host the cluster in (required)"
43+
description = "The region to host the cluster in (optional if zonal cluster / required if regional)"
44+
default = null
4445
}
4546

4647
variable "zones" {

networks.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ data "google_compute_subnetwork" "gke_subnetwork" {
2727
provider = google
2828

2929
name = var.subnetwork
30-
region = var.region
30+
region = local.region
3131
project = local.network_project_id
3232
}

variables.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ variable "regional" {
4040

4141
variable "region" {
4242
type = string
43-
description = "The region to host the cluster in (required)"
43+
description = "The region to host the cluster in (optional if zonal cluster / required if regional)"
44+
default = null
4445
}
4546

4647
variable "zones" {

0 commit comments

Comments
 (0)