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

google_compute_attached_disk failing for zone #16265

Assignees
Labels
Milestone

Comments

@nikeshp1
Copy link

GCP VM proivisioning is failing and as workaround using 4.83.0.
Error is Failed to retrieve zone, pid: , err: zone: required field is not set for resource "google_compute_attached_disk"

Logs during the tf execution

18:08:49 Error: 1 error occurred:
18:08:49 * Failed to retrieve zone, pid: , err: zone: required field is not set
18:08:49
18:08:49
18:08:49
18:08:49 on ../../../modules/google/tf_12/virtual-machine/main.tf line 168, in resource "google_compute_attached_disk" "disk_attachment":
18:08:49 168: resource "google_compute_attached_disk" "disk_attachment" {

The code is

resource "google_compute_attached_disk" "disk_attachment" {
for_each = local.disks_merged
disk = google_compute_disk.data_disk[each.key].id
device_name = each.value.device_name
instance = google_compute_instance_from_template.vm_instances[each.value.hostname].id
}

The same code was working until 4.83.0 and started failing from 4.84.0
Per the latest documentation as well, the zone is not a mandatory attribute and is extracted from the instance_id self link

@edwardmedia edwardmedia self-assigned this Oct 17, 2023
@edwardmedia
Copy link
Contributor

@nikeshp1 I do not see a change in google_compute_attached_disk in 4.84.0. The issue could be in other resources. Can you share a config that I can use to repro the issue? Also please share the full debug log that contains the api requests and responses.

@rvnz45
Copy link

rvnz45 commented Oct 19, 2023

i had same issue on google_compute_attached_disk

current workaround is adding zone at the resource block :

resource "google_compute_attached_disk" "attachdisk_genai_003" {
disk = google_compute_disk.disk_genai_003.id
instance = google_compute_instance.vm_genai_003.id
zone = "asia-southeast2-a"
}

the documentation should be updated to add the zone

@addyb77
Copy link

addyb77 commented Oct 19, 2023

I also have the same issue. I cannot apply the workaround listed by @rvnz45 as it will effect all my existing disks on compute instances already spun up via terraform.

@edwardmedia
Copy link
Contributor

@addyb77 @rvnz45 @nikeshp1 tested upgrading from v4.80.0 to v5.0.0 with below config, I did not hit a problem.

Anyone of you can provide a config and steps that I can follow to repro?

resource "google_compute_attached_disk" "default" {
  disk     = google_compute_disk.default.id
  instance = google_compute_instance.default.id
}

resource "google_compute_instance" "default" {
  name         = "issue16265"
  machine_type = "e2-medium"
  zone         = "us-west1-a"

  boot_disk {
    initialize_params {
      image = "debian-cloud/debian-11"
    }
  }

  network_interface {
    network = "default"
  }

  lifecycle {
    ignore_changes = [attached_disk]
  }
}

resource "google_compute_disk" "default" {
  name  = "issue16265-disk"
  type  = "pd-ssd"
  zone  = "us-west1-a"
  image = "debian-11-bullseye-v20220719"
  physical_block_size_bytes = 4096
}


terraform {
    required_providers {
        google = {
            version = "~> 5.0.0"
            #version = "~> 4.84.0"
            #version = "~> 4.80.0"
        }
        google-beta = {
            version = "~> 5.0.0"
            #version = "~> 4.84.0"
            #version = "~> 4.80.0"
        }
    }
}

@nikeshp1
Copy link
Author

Hi @edwardmedia,
Thanks for looking into the issue, I could reproduce the issue with the same code you tested.
Using google provider version 4.83.0 - Works fine
Using google provider version 5.0.0 - Fails at attached disk resource with "zone not provided" error

XXXXXXXX@XXXXXXXX manual % terraform init -upgrade

Initializing the backend...

Initializing provider plugins...

  • Finding hashicorp/google-beta versions matching "~> 4.83.0"...
  • Finding hashicorp/google versions matching "~> 4.83.0"...
  • Installing hashicorp/google-beta v4.83.0...
  • Installed hashicorp/google-beta v4.83.0 (signed by HashiCorp)
  • Installing hashicorp/google v4.83.0...
  • Installed hashicorp/google v4.83.0 (signed by HashiCorp)

Terraform has made some changes to the provider dependency selections recorded
in the .terraform.lock.hcl file. Review those changes and commit them to your
version control system if they represent changes you intended to make.

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
i859246@N62FH6MXPK manual % terraform plan

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:

  • create

Terraform will perform the following actions:

google_compute_attached_disk.default will be created

  • resource "google_compute_attached_disk" "default" {
    • device_name = (known after apply)
    • disk = (known after apply)
    • id = (known after apply)
    • instance = (known after apply)
    • mode = "READ_WRITE"
    • project = (known after apply)
    • zone = (known after apply)
      }

google_compute_disk.default will be created

  • resource "google_compute_disk" "default" {
    • creation_timestamp = (known after apply)
    • id = (known after apply)
    • image = "debian-11-bullseye-v20220719"
    • label_fingerprint = (known after apply)
    • last_attach_timestamp = (known after apply)
    • last_detach_timestamp = (known after apply)
    • licenses = (known after apply)
    • name = "issue16265-disk"
    • physical_block_size_bytes = 4096
    • project = (known after apply)
    • provisioned_iops = (known after apply)
    • provisioned_throughput = (known after apply)
    • self_link = (known after apply)
    • size = (known after apply)
    • source_disk_id = (known after apply)
    • source_image_id = (known after apply)
    • source_snapshot_id = (known after apply)
    • type = "pd-ssd"
    • users = (known after apply)
    • zone = "asia-northeast2-a"
      }

google_compute_instance.default will be created

  • resource "google_compute_instance" "default" {
    • can_ip_forward = false

    • cpu_platform = (known after apply)

    • current_status = (known after apply)

    • deletion_protection = false

    • guest_accelerator = (known after apply)

    • id = (known after apply)

    • instance_id = (known after apply)

    • label_fingerprint = (known after apply)

    • machine_type = "e2-medium"

    • metadata_fingerprint = (known after apply)

    • min_cpu_platform = (known after apply)

    • name = "issue16265"

    • project = (known after apply)

    • self_link = (known after apply)

    • tags_fingerprint = (known after apply)

    • zone = "asia-northeast2-a"

    • boot_disk {

      • auto_delete = true

      • device_name = (known after apply)

      • disk_encryption_key_sha256 = (known after apply)

      • kms_key_self_link = (known after apply)

      • mode = "READ_WRITE"

      • source = (known after apply)

      • initialize_params {

        • image = "debian-cloud/debian-11"
        • labels = (known after apply)
        • size = (known after apply)
        • type = (known after apply)
          }
          }
    • network_interface {

      • internal_ipv6_prefix_length = (known after apply)
      • ipv6_access_type = (known after apply)
      • ipv6_address = (known after apply)
      • name = (known after apply)
      • network = "default"
      • network_ip = (known after apply)
      • stack_type = (known after apply)
      • subnetwork = (known after apply)
      • subnetwork_project = (known after apply)
        }
        }

Plan: 3 to add, 0 to change, 0 to destroy.

─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.
XXXXXX@XXXXX manual % terraform --version
Terraform v1.4.6
on darwin_arm64

  • provider registry.terraform.io/hashicorp/google v4.83.0
  • provider registry.terraform.io/hashicorp/google-beta v4.83.0

Your version of Terraform is out of date! The latest version
is 1.6.2. You can update by downloading from https://www.terraform.io/downloads.html
XXXXXXX@XXXXXX manual % vi main.tf
XXXXXXX@XXXXXX manual % terraform init -upgrade

Initializing the backend...

Initializing provider plugins...

  • Finding hashicorp/google versions matching "~> 5.0.0"...
  • Finding hashicorp/google-beta versions matching "~> 5.0.0"...
  • Installing hashicorp/google v5.0.0...
  • Installed hashicorp/google v5.0.0 (signed by HashiCorp)
  • Installing hashicorp/google-beta v5.0.0...
  • Installed hashicorp/google-beta v5.0.0 (signed by HashiCorp)

Terraform has made some changes to the provider dependency selections recorded
in the .terraform.lock.hcl file. Review those changes and commit them to your
version control system if they represent changes you intended to make.

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
i859246@N62FH6MXPK manual % terraform plan

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:

  • create

Terraform planned the following actions, but then encountered a problem:

google_compute_disk.default will be created

  • resource "google_compute_disk" "default" {
    • creation_timestamp = (known after apply)
    • effective_labels = (known after apply)
    • id = (known after apply)
    • image = "debian-11-bullseye-v20220719"
    • label_fingerprint = (known after apply)
    • last_attach_timestamp = (known after apply)
    • last_detach_timestamp = (known after apply)
    • licenses = (known after apply)
    • name = "issue16265-disk"
    • physical_block_size_bytes = 4096
    • project = "sap-hcm-pd51-shared"
    • provisioned_iops = (known after apply)
    • provisioned_throughput = (known after apply)
    • self_link = (known after apply)
    • size = (known after apply)
    • source_disk_id = (known after apply)
    • source_image_id = (known after apply)
    • source_snapshot_id = (known after apply)
    • terraform_labels = (known after apply)
    • type = "pd-ssd"
    • users = (known after apply)
    • zone = "asia-northeast2-a"
      }

google_compute_instance.default will be created

  • resource "google_compute_instance" "default" {
    • can_ip_forward = false

    • cpu_platform = (known after apply)

    • current_status = (known after apply)

    • deletion_protection = false

    • effective_labels = (known after apply)

    • guest_accelerator = (known after apply)

    • id = (known after apply)

    • instance_id = (known after apply)

    • label_fingerprint = (known after apply)

    • machine_type = "e2-medium"

    • metadata_fingerprint = (known after apply)

    • min_cpu_platform = (known after apply)

    • name = "issue16265"

    • project = "sap-hcm-pd51-shared"

    • self_link = (known after apply)

    • tags_fingerprint = (known after apply)

    • terraform_labels = (known after apply)

    • zone = "asia-northeast2-a"

    • boot_disk {

      • auto_delete = true

      • device_name = (known after apply)

      • disk_encryption_key_sha256 = (known after apply)

      • kms_key_self_link = (known after apply)

      • mode = "READ_WRITE"

      • source = (known after apply)

      • initialize_params {

        • image = "debian-cloud/debian-11"
        • labels = (known after apply)
        • size = (known after apply)
        • type = (known after apply)
          }
          }
    • network_interface {

      • internal_ipv6_prefix_length = (known after apply)
      • ipv6_access_type = (known after apply)
      • ipv6_address = (known after apply)
      • name = (known after apply)
      • network = "default"
      • network_ip = (known after apply)
      • stack_type = (known after apply)
      • subnetwork = (known after apply)
      • subnetwork_project = (known after apply)
        }
        }

Plan: 2 to add, 0 to change, 0 to destroy.

│ Error: 1 error occurred:
│ * Failed to retrieve zone, pid: , err: zone: required field is not set



│ with google_compute_attached_disk.default,
│ on main.tf line 6, in resource "google_compute_attached_disk" "default":
│ 6: resource "google_compute_attached_disk" "default" {

╵XXXXX@XXXXX manual % terraform --version
Terraform v1.4.6
on darwin_arm64

  • provider registry.terraform.io/hashicorp/google v5.0.0
  • provider registry.terraform.io/hashicorp/google-beta v5.0.0

Your version of Terraform is out of date! The latest version
is 1.6.2. You can update by downloading from https://www.terraform.io/downloads.html

Code:

resource "google_compute_attached_disk" "default" {
  disk     = google_compute_disk.default.id
  instance = google_compute_instance.default.id
}

resource "google_compute_instance" "default" {
  name         = "issue16265"
  machine_type = "e2-medium"
  zone         = "asia-northeast2-a"

  boot_disk {
    initialize_params {
      image = "debian-cloud/debian-11"
    }
  }

  network_interface {
    network = "default"
  }

  lifecycle {
    ignore_changes = [attached_disk]
  }
}

resource "google_compute_disk" "default" {
  name  = "issue16265-disk"
  type  = "pd-ssd"
  zone  = "asia-northeast2-a"
  image = "debian-11-bullseye-v20220719"
  physical_block_size_bytes = 4096
}


terraform {
    required_providers {
        google = {
            version = "~> 5.0.0"
            #version = "~> 4.84.0"
            #version = "~> 4.80.0"
        }
        google-beta = {
            version = "~> 5.0.0"
            #version = "~> 4.84.0"
            #version = "~> 4.80.0"
        }
    }
}

Btw, this is the test code, in prod we are using instance template and instance from template which has similar error attaching disk

@nikeshp1
Copy link
Author

Here is the error log with log at debug level
2023-10-19T14:42:20.773-0400 [DEBUG] Resource instance state not found for node "google_compute_attached_disk.default", instance google_compute_attached_disk.default
2023-10-19T14:42:20.773-0400 [DEBUG] ReferenceTransformer: "google_compute_attached_disk.default" references: []
2023-10-19T14:42:20.773-0400 [DEBUG] refresh: google_compute_attached_disk.default: no state, so not refreshing
2023-10-19T14:42:20.774-0400 [ERROR] provider.terraform-provider-google_v5.0.0_x5: Response contains error diagnostic: @caller=github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/internal/diag/diagnostics.go:55 diagnostic_summary="1 error occurred:
* Failed to retrieve zone, pid: , err: zone: required field is not set

" tf_proto_version=5.3 tf_rpc=PlanResourceChange @module=sdk.proto diagnostic_detail= diagnostic_severity=ERROR tf_provider_addr=registry.terraform.io/hashicorp/google tf_req_id=cc5a9de5-58ec-0853-3b28-7e3ec9df897c tf_resource_type=google_compute_attached_disk timestamp=2023-10-19T14:42:20.774-0400
2023-10-19T14:42:20.774-0400 [ERROR] vertex "google_compute_attached_disk.default" error: 1 error occurred:
* Failed to retrieve zone, pid: , err: zone: required field is not set
2023-10-19T14:42:20.774-0400 [ERROR] vertex "google_compute_attached_disk.default (expand)" error: 1 error occurred:
* Failed to retrieve zone, pid: , err: zone: required field is not set

@nikeshp1
Copy link
Author

FYI, this issue is when we don't provide zone explicitly to "google_compute_attached_disk" or zone is not configured in the provider.
We cannot set the zone in the provider as we are deploying resources in multiple zones

@addyb77
Copy link

addyb77 commented Oct 19, 2023 via email

@edwardmedia
Copy link
Contributor

Oh I see. This error actually only happens for a fresh plan/apply with v5.x. It is fine when the config was first applied with v4.x and then upgrade with terraform init -upgrade with v5.x

@nikeshp1
Copy link
Author

Hi,
Yes, this is when using 4.84.0+ versions for a fresh build.
Please note this behavior is from 4.84.0

@edwardmedia
Copy link
Contributor

The issue appears to be related to the introduction of DefaultProviderZone by v5.x

@addyb77
Copy link

addyb77 commented Oct 24, 2023

Is there any update on this issue? I have attempted to create a new compute module for testing and even with hardcoding the zone at the module level, i still get the same error:

*** Failed to retrieve zone, pid: , err: zone: required field is not set**

@nikeshp1
Copy link
Author

nikeshp1 commented Nov 7, 2023

@NickElliot ,
I see the PR is still open, Is this planned to be merged in the next release?
And will this be fixed in the releases from 4.84.0 where this started to break

@NickElliot
Copy link
Collaborator

NickElliot commented Nov 7, 2023

I've been implementing the update test for this issue between other work that made me busy last week, if it's merged by EOD it would be released next monday, otherwise will be the monday after that. There are no plans to implement a patch.

@nikeshp1
Copy link
Author

@NickElliot,
Is this fix available in the latest release?
We are still getting the same error using 5.6.0 with the same code shared above
image

@NickElliot
Copy link
Collaborator

It was merged on Thurs the 9th which is after the deadline for the release made yesterday. It should be a part of the release on the 20th.

Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.