Skip to content

Conversation

@lennydong-rogo
Copy link

As noted in: hashicorp/terraform-provider-google#25914

It seems the GCP API for returning compute zones began returning ai zones, as a result of the recent introduction of AI zones on 16th Jan in us-central1

This PR adds a variable to allow users to exclude AI zones when using the GKE module

@google-cla
Copy link

google-cla bot commented Jan 28, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @lennydong-rogo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new optional variable, exclude_ai_zones, to the GKE module. This variable allows users to explicitly filter out newly introduced AI-specific compute zones from the list of available zones dynamically fetched from Google Cloud. This ensures that GKE deployments can maintain expected zone configurations and avoid unintended interactions with AI zones, addressing a recent change in the GCP API's zone enumeration.

Highlights

  • New Configuration Variable: Introduced an optional boolean variable exclude_ai_zones (default false) to control the inclusion of AI-specific zones when fetching available Google Compute Zones.
  • Conditional Zone Filtering: Implemented logic in main.tf to conditionally filter out zones matching the regex pattern -ai\d+[a-z]$ from the list of available zones if exclude_ai_zones is set to true.
  • Addressing GCP API Changes: This change addresses a recent issue where the GCP API began returning AI zones, which could inadvertently affect GKE module deployments by including unintended zones.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new variable exclude_ai_zones to filter out AI-specific zones from the list of available zones, which is a good fix for the issue described.

However, the changes have been applied to auto-generated files (main.tf and variables.tf) instead of their source templates in the autogen/main/ directory. This is a critical issue as the changes will be lost during the next code generation. I've left comments on the respective files with instructions on how to apply the changes to the correct template files.

I've also included a suggestion to improve the clarity of the filtering logic.

Comment on lines +34 to +37
input = var.exclude_ai_zones ? [
for zone in data.google_compute_zones.available[0].names : zone
if !can(regex("-ai\\d+[a-z]$", zone))
] : data.google_compute_zones.available[0].names
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This file is auto-generated from a template. Your changes will be overwritten. Please apply your changes to the template file autogen/main/main.tf.tmpl instead.

You should replace the random_shuffle.available_zones resource in autogen/main/main.tf.tmpl with the logic you've added.

While you're at it, I'd also suggest using regexall for better readability. The !can(regex(...)) pattern works, but it's a bit of a trick that relies on regex erroring on no match. Using length(regexall(...)) == 0 is more explicit about the intent.

Here is the suggested replacement for the random_shuffle resource in autogen/main/main.tf.tmpl:

resource "random_shuffle" "available_zones" {
  count        = local.zone_count == 0 ? 1 : 0

  input = var.exclude_ai_zones ? [
    for zone in data.google_compute_zones.available[0].names : zone
    if length(regexall("-ai\\d+[a-z]$", zone)) == 0
  ] : data.google_compute_zones.available[0].names
  result_count = 3
}

Comment on lines +1076 to +1080
variable "exclude_ai_zones" {
description = "(Optional) Controls whether to exclude AI zones from the dynamically fetched google_compute_zones"
type = bool
default = false
} No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This file is auto-generated from a template. Your changes will be overwritten. Please add the new exclude_ai_zones variable to the template file autogen/main/variables.tf.tmpl instead. Here is the suggested addition for autogen/main/variables.tf.tmpl:

variable "exclude_ai_zones" {
  description = "(Optional) Controls whether to exclude AI zones from the dynamically fetched google_compute_zones"
  type        = bool
  default     = false
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant