Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: random zones only when zones are not provided #1709

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions autogen/main/main.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
Get available zones in region
*****************************************/
data "google_compute_zones" "available" {
count = local.zone_count == 0 ? 1 : 0

{% if beta_cluster %}
provider = google-beta
{% else %}
Expand All @@ -31,7 +33,9 @@ data "google_compute_zones" "available" {
}

resource "random_shuffle" "available_zones" {
input = data.google_compute_zones.available.names
count = local.zone_count == 0 ? 1 : 0

input = data.google_compute_zones.available[0].names
result_count = 3
}

Expand All @@ -43,7 +47,7 @@ locals {
location = var.regional ? var.region : var.zones[0]
region = var.regional ? var.region : join("-", slice(split("-", var.zones[0]), 0, 2))
// for regional cluster - use var.zones if provided, use available otherwise, for zonal cluster use var.zones with first element extracted
node_locations = var.regional ? coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result)) : slice(var.zones, 1, length(var.zones))
node_locations = var.regional ? coalescelist(compact(var.zones), try(sort(random_shuffle.available_zones[0].result),[])) : slice(var.zones, 1, length(var.zones))
// Kubernetes version
master_version_regional = var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.region.latest_master_version
master_version_zonal = var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.zone.latest_master_version
Expand Down Expand Up @@ -245,6 +249,6 @@ data "google_container_engine_versions" "zone" {
//
// data.google_container_engine_versions.zone: Cannot determine zone: set in this resource, or set provider-level zone.
//
location = local.zone_count == 0 ? data.google_compute_zones.available.names[0] : var.zones[0]
location = local.zone_count == 0 ? data.google_compute_zones.available[0].names[0] : var.zones[0]
project = var.project_id
}
2 changes: 1 addition & 1 deletion examples/simple_zonal_with_acm/acm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module "acm" {

secret_type = "ssh"

policy_bundles = ["https://github.com/GoogleCloudPlatform/acm-policy-controller-library/bundles/policy-essentials-v2022?ref=59f4695394285078f7c2029ec7d0f9ed1d6d700a"]
policy_bundles = ["https://github.com/GoogleCloudPlatform/acm-policy-controller-library/bundles/policy-essentials-v2022?ref=dd3f932eefa4c4c44c548144be1c2331d8594689"]
ericyz marked this conversation as resolved.
Show resolved Hide resolved

create_metrics_gcp_sa = true
}
10 changes: 7 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@
Get available zones in region
*****************************************/
data "google_compute_zones" "available" {
count = local.zone_count == 0 ? 1 : 0

provider = google

project = var.project_id
region = local.region
}

resource "random_shuffle" "available_zones" {
input = data.google_compute_zones.available.names
count = local.zone_count == 0 ? 1 : 0

input = data.google_compute_zones.available[0].names
result_count = 3
}

Expand All @@ -39,7 +43,7 @@ locals {
location = var.regional ? var.region : var.zones[0]
region = var.regional ? var.region : join("-", slice(split("-", var.zones[0]), 0, 2))
// for regional cluster - use var.zones if provided, use available otherwise, for zonal cluster use var.zones with first element extracted
node_locations = var.regional ? coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result)) : slice(var.zones, 1, length(var.zones))
node_locations = var.regional ? coalescelist(compact(var.zones), try(sort(random_shuffle.available_zones[0].result), [])) : slice(var.zones, 1, length(var.zones))
// Kubernetes version
master_version_regional = var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.region.latest_master_version
master_version_zonal = var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.zone.latest_master_version
Expand Down Expand Up @@ -175,6 +179,6 @@ data "google_container_engine_versions" "zone" {
//
// data.google_container_engine_versions.zone: Cannot determine zone: set in this resource, or set provider-level zone.
//
location = local.zone_count == 0 ? data.google_compute_zones.available.names[0] : var.zones[0]
location = local.zone_count == 0 ? data.google_compute_zones.available[0].names[0] : var.zones[0]
project = var.project_id
}
10 changes: 7 additions & 3 deletions modules/beta-autopilot-private-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@
Get available zones in region
*****************************************/
data "google_compute_zones" "available" {
count = local.zone_count == 0 ? 1 : 0

provider = google-beta

project = var.project_id
region = local.region
}

resource "random_shuffle" "available_zones" {
input = data.google_compute_zones.available.names
count = local.zone_count == 0 ? 1 : 0

input = data.google_compute_zones.available[0].names
result_count = 3
}

Expand All @@ -39,7 +43,7 @@ locals {
location = var.regional ? var.region : var.zones[0]
region = var.regional ? var.region : join("-", slice(split("-", var.zones[0]), 0, 2))
// for regional cluster - use var.zones if provided, use available otherwise, for zonal cluster use var.zones with first element extracted
node_locations = var.regional ? coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result)) : slice(var.zones, 1, length(var.zones))
node_locations = var.regional ? coalescelist(compact(var.zones), try(sort(random_shuffle.available_zones[0].result), [])) : slice(var.zones, 1, length(var.zones))
// Kubernetes version
master_version_regional = var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.region.latest_master_version
master_version_zonal = var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.zone.latest_master_version
Expand Down Expand Up @@ -143,6 +147,6 @@ data "google_container_engine_versions" "zone" {
//
// data.google_container_engine_versions.zone: Cannot determine zone: set in this resource, or set provider-level zone.
//
location = local.zone_count == 0 ? data.google_compute_zones.available.names[0] : var.zones[0]
location = local.zone_count == 0 ? data.google_compute_zones.available[0].names[0] : var.zones[0]
project = var.project_id
}
10 changes: 7 additions & 3 deletions modules/beta-autopilot-public-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@
Get available zones in region
*****************************************/
data "google_compute_zones" "available" {
count = local.zone_count == 0 ? 1 : 0

provider = google-beta

project = var.project_id
region = local.region
}

resource "random_shuffle" "available_zones" {
input = data.google_compute_zones.available.names
count = local.zone_count == 0 ? 1 : 0

input = data.google_compute_zones.available[0].names
result_count = 3
}

Expand All @@ -39,7 +43,7 @@ locals {
location = var.regional ? var.region : var.zones[0]
region = var.regional ? var.region : join("-", slice(split("-", var.zones[0]), 0, 2))
// for regional cluster - use var.zones if provided, use available otherwise, for zonal cluster use var.zones with first element extracted
node_locations = var.regional ? coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result)) : slice(var.zones, 1, length(var.zones))
node_locations = var.regional ? coalescelist(compact(var.zones), try(sort(random_shuffle.available_zones[0].result), [])) : slice(var.zones, 1, length(var.zones))
// Kubernetes version
master_version_regional = var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.region.latest_master_version
master_version_zonal = var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.zone.latest_master_version
Expand Down Expand Up @@ -142,6 +146,6 @@ data "google_container_engine_versions" "zone" {
//
// data.google_container_engine_versions.zone: Cannot determine zone: set in this resource, or set provider-level zone.
//
location = local.zone_count == 0 ? data.google_compute_zones.available.names[0] : var.zones[0]
location = local.zone_count == 0 ? data.google_compute_zones.available[0].names[0] : var.zones[0]
project = var.project_id
}
10 changes: 7 additions & 3 deletions modules/beta-private-cluster-update-variant/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@
Get available zones in region
*****************************************/
data "google_compute_zones" "available" {
count = local.zone_count == 0 ? 1 : 0

provider = google-beta

project = var.project_id
region = local.region
}

resource "random_shuffle" "available_zones" {
input = data.google_compute_zones.available.names
count = local.zone_count == 0 ? 1 : 0

input = data.google_compute_zones.available[0].names
result_count = 3
}

Expand All @@ -39,7 +43,7 @@ locals {
location = var.regional ? var.region : var.zones[0]
region = var.regional ? var.region : join("-", slice(split("-", var.zones[0]), 0, 2))
// for regional cluster - use var.zones if provided, use available otherwise, for zonal cluster use var.zones with first element extracted
node_locations = var.regional ? coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result)) : slice(var.zones, 1, length(var.zones))
node_locations = var.regional ? coalescelist(compact(var.zones), try(sort(random_shuffle.available_zones[0].result), [])) : slice(var.zones, 1, length(var.zones))
// Kubernetes version
master_version_regional = var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.region.latest_master_version
master_version_zonal = var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.zone.latest_master_version
Expand Down Expand Up @@ -203,6 +207,6 @@ data "google_container_engine_versions" "zone" {
//
// data.google_container_engine_versions.zone: Cannot determine zone: set in this resource, or set provider-level zone.
//
location = local.zone_count == 0 ? data.google_compute_zones.available.names[0] : var.zones[0]
location = local.zone_count == 0 ? data.google_compute_zones.available[0].names[0] : var.zones[0]
project = var.project_id
}
10 changes: 7 additions & 3 deletions modules/beta-private-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@
Get available zones in region
*****************************************/
data "google_compute_zones" "available" {
count = local.zone_count == 0 ? 1 : 0

provider = google-beta

project = var.project_id
region = local.region
}

resource "random_shuffle" "available_zones" {
input = data.google_compute_zones.available.names
count = local.zone_count == 0 ? 1 : 0

input = data.google_compute_zones.available[0].names
result_count = 3
}

Expand All @@ -39,7 +43,7 @@ locals {
location = var.regional ? var.region : var.zones[0]
region = var.regional ? var.region : join("-", slice(split("-", var.zones[0]), 0, 2))
// for regional cluster - use var.zones if provided, use available otherwise, for zonal cluster use var.zones with first element extracted
node_locations = var.regional ? coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result)) : slice(var.zones, 1, length(var.zones))
node_locations = var.regional ? coalescelist(compact(var.zones), try(sort(random_shuffle.available_zones[0].result), [])) : slice(var.zones, 1, length(var.zones))
// Kubernetes version
master_version_regional = var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.region.latest_master_version
master_version_zonal = var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.zone.latest_master_version
Expand Down Expand Up @@ -203,6 +207,6 @@ data "google_container_engine_versions" "zone" {
//
// data.google_container_engine_versions.zone: Cannot determine zone: set in this resource, or set provider-level zone.
//
location = local.zone_count == 0 ? data.google_compute_zones.available.names[0] : var.zones[0]
location = local.zone_count == 0 ? data.google_compute_zones.available[0].names[0] : var.zones[0]
project = var.project_id
}
10 changes: 7 additions & 3 deletions modules/beta-public-cluster-update-variant/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@
Get available zones in region
*****************************************/
data "google_compute_zones" "available" {
count = local.zone_count == 0 ? 1 : 0

provider = google-beta

project = var.project_id
region = local.region
}

resource "random_shuffle" "available_zones" {
input = data.google_compute_zones.available.names
count = local.zone_count == 0 ? 1 : 0

input = data.google_compute_zones.available[0].names
result_count = 3
}

Expand All @@ -39,7 +43,7 @@ locals {
location = var.regional ? var.region : var.zones[0]
region = var.regional ? var.region : join("-", slice(split("-", var.zones[0]), 0, 2))
// for regional cluster - use var.zones if provided, use available otherwise, for zonal cluster use var.zones with first element extracted
node_locations = var.regional ? coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result)) : slice(var.zones, 1, length(var.zones))
node_locations = var.regional ? coalescelist(compact(var.zones), try(sort(random_shuffle.available_zones[0].result), [])) : slice(var.zones, 1, length(var.zones))
// Kubernetes version
master_version_regional = var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.region.latest_master_version
master_version_zonal = var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.zone.latest_master_version
Expand Down Expand Up @@ -202,6 +206,6 @@ data "google_container_engine_versions" "zone" {
//
// data.google_container_engine_versions.zone: Cannot determine zone: set in this resource, or set provider-level zone.
//
location = local.zone_count == 0 ? data.google_compute_zones.available.names[0] : var.zones[0]
location = local.zone_count == 0 ? data.google_compute_zones.available[0].names[0] : var.zones[0]
project = var.project_id
}
10 changes: 7 additions & 3 deletions modules/beta-public-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@
Get available zones in region
*****************************************/
data "google_compute_zones" "available" {
count = local.zone_count == 0 ? 1 : 0

provider = google-beta

project = var.project_id
region = local.region
}

resource "random_shuffle" "available_zones" {
input = data.google_compute_zones.available.names
count = local.zone_count == 0 ? 1 : 0

input = data.google_compute_zones.available[0].names
result_count = 3
}

Expand All @@ -39,7 +43,7 @@ locals {
location = var.regional ? var.region : var.zones[0]
region = var.regional ? var.region : join("-", slice(split("-", var.zones[0]), 0, 2))
// for regional cluster - use var.zones if provided, use available otherwise, for zonal cluster use var.zones with first element extracted
node_locations = var.regional ? coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result)) : slice(var.zones, 1, length(var.zones))
node_locations = var.regional ? coalescelist(compact(var.zones), try(sort(random_shuffle.available_zones[0].result), [])) : slice(var.zones, 1, length(var.zones))
// Kubernetes version
master_version_regional = var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.region.latest_master_version
master_version_zonal = var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.zone.latest_master_version
Expand Down Expand Up @@ -202,6 +206,6 @@ data "google_container_engine_versions" "zone" {
//
// data.google_container_engine_versions.zone: Cannot determine zone: set in this resource, or set provider-level zone.
//
location = local.zone_count == 0 ? data.google_compute_zones.available.names[0] : var.zones[0]
location = local.zone_count == 0 ? data.google_compute_zones.available[0].names[0] : var.zones[0]
project = var.project_id
}
10 changes: 7 additions & 3 deletions modules/private-cluster-update-variant/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@
Get available zones in region
*****************************************/
data "google_compute_zones" "available" {
count = local.zone_count == 0 ? 1 : 0

provider = google

project = var.project_id
region = local.region
}

resource "random_shuffle" "available_zones" {
input = data.google_compute_zones.available.names
count = local.zone_count == 0 ? 1 : 0

input = data.google_compute_zones.available[0].names
result_count = 3
}

Expand All @@ -39,7 +43,7 @@ locals {
location = var.regional ? var.region : var.zones[0]
region = var.regional ? var.region : join("-", slice(split("-", var.zones[0]), 0, 2))
// for regional cluster - use var.zones if provided, use available otherwise, for zonal cluster use var.zones with first element extracted
node_locations = var.regional ? coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result)) : slice(var.zones, 1, length(var.zones))
node_locations = var.regional ? coalescelist(compact(var.zones), try(sort(random_shuffle.available_zones[0].result), [])) : slice(var.zones, 1, length(var.zones))
// Kubernetes version
master_version_regional = var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.region.latest_master_version
master_version_zonal = var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.zone.latest_master_version
Expand Down Expand Up @@ -176,6 +180,6 @@ data "google_container_engine_versions" "zone" {
//
// data.google_container_engine_versions.zone: Cannot determine zone: set in this resource, or set provider-level zone.
//
location = local.zone_count == 0 ? data.google_compute_zones.available.names[0] : var.zones[0]
location = local.zone_count == 0 ? data.google_compute_zones.available[0].names[0] : var.zones[0]
project = var.project_id
}
10 changes: 7 additions & 3 deletions modules/private-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@
Get available zones in region
*****************************************/
data "google_compute_zones" "available" {
count = local.zone_count == 0 ? 1 : 0

provider = google

project = var.project_id
region = local.region
}

resource "random_shuffle" "available_zones" {
input = data.google_compute_zones.available.names
count = local.zone_count == 0 ? 1 : 0

input = data.google_compute_zones.available[0].names
result_count = 3
}

Expand All @@ -39,7 +43,7 @@ locals {
location = var.regional ? var.region : var.zones[0]
region = var.regional ? var.region : join("-", slice(split("-", var.zones[0]), 0, 2))
// for regional cluster - use var.zones if provided, use available otherwise, for zonal cluster use var.zones with first element extracted
node_locations = var.regional ? coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result)) : slice(var.zones, 1, length(var.zones))
node_locations = var.regional ? coalescelist(compact(var.zones), try(sort(random_shuffle.available_zones[0].result), [])) : slice(var.zones, 1, length(var.zones))
// Kubernetes version
master_version_regional = var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.region.latest_master_version
master_version_zonal = var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.zone.latest_master_version
Expand Down Expand Up @@ -176,6 +180,6 @@ data "google_container_engine_versions" "zone" {
//
// data.google_container_engine_versions.zone: Cannot determine zone: set in this resource, or set provider-level zone.
//
location = local.zone_count == 0 ? data.google_compute_zones.available.names[0] : var.zones[0]
location = local.zone_count == 0 ? data.google_compute_zones.available[0].names[0] : var.zones[0]
project = var.project_id
}
3 changes: 3 additions & 0 deletions test/integration/beta_cluster/testdata/TestBetaCluster.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
"enableComponents": [
"SYSTEM_COMPONENTS"
]
},
"managedPrometheusConfig": {
"enabled": true
}
},
"monitoringService": "monitoring.googleapis.com/kubernetes",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"addonsConfig": {
"configConnectorConfig": {},
"dnsCacheConfig": {},
"gcePersistentDiskCsiDriverConfig": {},
"gcePersistentDiskCsiDriverConfig": {
"enabled": true
},
"gcpFilestoreCsiDriverConfig": {},
"gkeBackupAgentConfig": {},
"horizontalPodAutoscaling": {},
Expand Down
Loading