Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixed

- [AWS] Persisted the selected availability zone to prevent unintended cluster rebuilds when AWS zone or instance-type offerings change. (PR #458)
- [GCP] Persisted the selected zone to prevent unintended instance and disk rebuilds when the available zone list changes, and rejected unavailable zones instead of silently selecting another zone.
- [GCP] Kept all instances and managed disks in one zone offering every requested instance type, including autoscaling nodes, and validated the stored zone against current offerings. Requires Google provider 5.15 or later.

## [16.1.2] 2026-11-04

Expand Down
17 changes: 14 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1171,18 +1171,29 @@ assigned number.

Defines the name of the specific geographical location where the cluster resources will be hosted.

**Requirement**: Must be a valid Google Cloud region. Refer to [Google Cloud documentation](https://cloud.google.com/compute/docs/regions-zones#available)
**Requirement**: Must be a Google Cloud region with an available zone offering
all selected instance types. Custom N1 machine types are checked by
family. Refer to [Google Cloud documentation](https://cloud.google.com/compute/docs/regions-zones#available)
for the list of available regions and their characteristics.

#### 5.3.3 zone (optional)

**default value**: None

Defines the name of the zone within the region where the cluster resources will be hosted.
Defines the zone within the region where all cluster instances and managed disks
will be hosted. If omitted, a zone offering all selected instance types is chosen
at random. The selected zone is stored in Terraform state and retained when zone
or machine-type offerings change. An unavailable or incompatible zone causes an
error instead of selecting another zone.

**Requirement**: Must be a valid Google Cloud zone. Refer to [Google Cloud documentation](https://cloud.google.com/compute/docs/regions-zones#available)
**Requirement**: Must be an available Google Cloud zone in the selected region.
It must offer all selected instance types, including autoscaling nodes.
Refer to [Google Cloud documentation](https://cloud.google.com/compute/docs/regions-zones#available)
for the list of available zones and their characteristics.

**Post build modification effect**: changing or clearing this value resets the
selection and may rebuild instances and managed disks at next `terraform apply`.

### 5.4 OpenStack and OVH

#### 5.4.1 os_floating_ips (optional)
Expand Down
65 changes: 56 additions & 9 deletions gcp/infrastructure.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,67 @@ data "google_compute_zones" "available" {
status = "UP"
}

locals {
instance_types = distinct([for instance in var.instances : instance.type])
# Custom N1 shapes are not listed by the API; check their machine family.
machine_type_names = {
for type in local.instance_types : type => startswith(type, "custom-") ? "n1-standard-1" : type
}
}

data "google_compute_machine_types" "available" {
for_each = toset(data.google_compute_zones.available.names)
project = var.project
zone = each.key
filter = join(" OR ", [for type in distinct(values(local.machine_type_names)) : "name = ${jsonencode(type)}"])
}

locals {
zone_choices = toset([
for zone, offerings in data.google_compute_machine_types.available : zone
if alltrue([
for type in local.instance_types : contains(offerings.machine_types[*].name, local.machine_type_names[type])
])
])
}

resource "random_shuffle" "random_zone" {
input = data.google_compute_zones.available.names
input = local.zone_choices
result_count = 1
}

locals {
zone = (
(var.zone != "" &&
contains(data.google_compute_zones.available.names,
var.zone)
?
var.zone : random_shuffle.random_zone.result[0]
)
)
zone = terraform_data.zone.output
}

resource "terraform_data" "zone" {
input = var.zone != "" ? var.zone : random_shuffle.random_zone.result[0]
triggers_replace = [var.zone]

lifecycle {
ignore_changes = [input]

precondition {
condition = length(data.google_compute_zones.available.names) > 0
error_message = "There are no available zones in ${var.region}."
}
precondition {
condition = length(local.zone_choices) > 0
error_message = "There is not a single available zone in ${var.region} that provides all selected instance types ${jsonencode(local.instance_types)}."
}
precondition {
condition = var.zone == "" || contains(data.google_compute_zones.available.names, var.zone)
error_message = "The selected zone ${var.zone} is not available in ${var.region}. Select one of ${jsonencode(data.google_compute_zones.available.names)} or leave zone undefined."
}
precondition {
condition = var.zone == "" || contains(local.zone_choices, var.zone)
error_message = "The selected zone ${var.zone} does not provide all selected instance types. Select one of ${jsonencode(local.zone_choices)} or leave zone undefined."
}
postcondition {
condition = contains(local.zone_choices, self.output)
error_message = "The cluster zone ${self.output} is not available or does not provide all selected instance types. Select instance types available in this zone or explicitly change zone to one of ${jsonencode(local.zone_choices)}."
}
}
}

data "external" "machine_type" {
Expand Down
6 changes: 6 additions & 0 deletions gcp/versions.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

terraform {
required_version = ">= 1.5.7"
required_providers {
google = {
source = "hashicorp/google"
version = ">= 5.15.0"
}
}
}
Loading