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: Fix zone auto-detection when var.zones are not set #534

Merged

Conversation

legal90
Copy link
Contributor

@legal90 legal90 commented Oct 26, 2023

In v17.0.0 (#507) there was an error in the detection of the default value for local.zone, which takes place when var.zone is not set:

Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: Invalid index
│
│   on .terraform/modules/postgresql/modules/postgresql/read_replica.tf line 22, in locals:22:   zone = var.zone == null ? data.google_compute_zones.available[0].names[0] : var.zone
│     ├────────────────
│     │ data.google_compute_zones.available is empty tuple
│
│ The given key does not identify an element in this collection value: the
│ collection has no elements.

This PR fixes this issue.

Solution details

In line 21 we see:

locals {
  # ...
  // Zone for replica instances
  zone = var.zone == null ? data.google_compute_zones.available[0].names[0] : var.zone
}

It means that we are going to rely on data.google_compute_zones only when var.zone == null. So that, we should flip the "count" condition for data.google_compute_zones, as I did in this PR.

After that fix terraform plan works as expected with both cases: when var.zone is defined and when when it's not defined (null).

cc @imrannayer , @g-awmalik

@legal90 legal90 requested review from isaurabhuttam and a team as code owners October 26, 2023 14:53
@legal90 legal90 changed the title Fix detection of the default availability zone when var.zone is not set fix: Fix zone auto-detection when var.zones are not set Oct 26, 2023
@imrannayer imrannayer self-requested a review as a code owner November 1, 2023 00:54
@imrannayer
Copy link
Collaborator

/gcbrun

@imrannayer
Copy link
Collaborator

/gcbrun

1 similar comment
@imrannayer
Copy link
Collaborator

/gcbrun

@imrannayer imrannayer merged commit 8409f72 into terraform-google-modules:master Nov 3, 2023
4 checks passed
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.

None yet

2 participants