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

The zonal field for resource disks cannot be empty #658

Closed
leighmhart opened this issue Oct 31, 2017 · 7 comments
Closed

The zonal field for resource disks cannot be empty #658

leighmhart opened this issue Oct 31, 2017 · 7 comments

Comments

@leighmhart
Copy link

Hi there,

I'm upgrading a project from 0.8.2 to 0.10.7 and having problems with an existing google_compute_instance resource and its associated disk(s).

I became aware that previous references to disks using the

  disk {
    name = "xxx"
    device_name = "yyy"
    auto_delete = "false"
  }

method to link in an existing google_compute_disk resource needed to be changed to:

        boot_disk {
                source = "${google_compute_disk.whatever.self_link}"
                initialize_params {
                        image = ""
                }
                device_name = "disk1"
                auto_delete = "false"
        }

and this has worked for several VMs across different projects coming from various terraform versions up to and including 0.10.7. The initialize_params shouldn't have needed to be there, especially given the presence of the source parameter, but terraform plan kept saying it wanted to force new resource on the instance because initialize_params went from 1 => 0 - this work-around was the closest I could get to a clean "no change moving forward" plan.

However, in one particularly old project, I am now getting a strange error on terraform refresh:

Error refreshing state: 1 error(s) occurred:

* google_compute_instance.xxxxxxxxxxxxxxxx: 1 error(s) occurred:

* google_compute_instance.xxxxxxxxxxxxxxxx: google_compute_instance.xxxxxxxxxxxxxxxx: The zonal field for resource disks cannot be empty.

with no other additional info.

Terraform Version

Terraform v0.10.7

The release notes for 0.10.8 do not indicate any related fixes to this issue and this appears to be a Google provider specific error message.

Affected Resource(s)

  • google_compute_instance
  • google_compute_disk

Terraform Configuration Files

resource "google_compute_disk" "os-disk" {
        name = "os-disk"
        type = "pd-standard"
        zone = "us-east1-b"
        size = "100"
        image = "windows-server-2012-r2-dc-v20161012"

        lifecycle {
                prevent_destroy = "true"
        }
}

resource "google_compute_disk" "data-disk" {
        name = "data-disk"
        type = "pd-standard"
        zone = "us-east1-b"
        size = "500"

        lifecycle {
                prevent_destroy = "true"
        }
}

resource "google_compute_instance" "server" {
        name = "server"
        machine_type = "n1-standard-2"
        zone = "us-east1-b"

        lifecycle {
                ignore_changes = [
                                "create_timeout"
                ]
        }

        boot_disk {
                source = "${google_compute_disk.os-disk.self_link}"
                initialize_params {
                        image = ""
                }
                device_name = "disk1"
                auto_delete = "false"
        }

        attached_disk {
                source = "{google_compute_disk.data-disk.self_link}"
        }

Debug Output

Debug output can be provided on request.

Panic Output

no panic output.

Expected Behavior

refresh and plan

Actual Behavior

error above.

Steps to Reproduce

  1. terraform refresh

Important Factoids

nothing out of the ordinary!

References

none

@leighmhart
Copy link
Author

0.10.8 yields same result.

@danawillow
Copy link
Contributor

Hey @allandrick, you definitely shouldn't need the empty initialize_params block. Can you show me what your previous config looked like, as well as the output of terraform plan when you omit initialize_params?

@leighmhart
Copy link
Author

leighmhart commented Nov 1, 2017

Hi @danawillow - yeah, the empty initialize_params block was a definite work-around.

Previous config looked like (sanitised):

resource "google_compute_disk" "os-disk" {
	name = "os-disk" 
	type = "pd-standard"
	zone = "us-east1-b"
	size = "100"
	image = "windows-2012-r2"

	lifecycle {
		prevent_destroy = "true"
	}
}

resource "google_compute_disk" "data-disk" {
	name = "data-disk" 
	type = "pd-standard"
	zone = "us-east1-b"
	size = "500"

	lifecycle {
		prevent_destroy = "true"
	}
}

resource "google_compute_instance" "server" {
	name = "server" 
	description = "Server"
	machine_type = "n1-standard-2"
	zone = "us-east1-b"

	lifecycle {
		ignore_changes = [
				"create_timeout"
		]
	}

	disk {
		disk = "os-disk" 
		device_name = "disk1"
		auto_delete = "false"
	}

...

the terraform plan before changes:

* google_compute_instance.server: "boot_disk": required field is not set
* google_compute_instance.server: "disk": [REMOVED] Use boot_disk, scratch_disk, and attached_disk instead

so I change:

disk {
  disk = "disk-name"
  device_name = "disk1"
  auto_delete = "false"

to:

boot_disk {
  source = "${google_compute_disk.disk-name.self_link}"
  device_name = "disk1"
  auto_delete = "false"

and similarly any second disks from:

disk {
  name = "data"
  device_name = "disk2"
  auto_delete = "false"
}

to

attached_disk {
  source = "${google_compute_disk.data.self_link}"
  device_name = "disk2"
}

Then terraform plan says:

-/+ google_compute_instance.server (new resource required)
      id:                                                  "server" => <computed> (forces new resource)
      boot_disk.#:                                         "1" => "1"
      boot_disk.0.auto_delete:                             "false" => "false"
      boot_disk.0.device_name:                             "disk1" => "disk1"
      boot_disk.0.disk_encryption_key_sha256:              "" => <computed>
      boot_disk.0.initialize_params.#:                     "1" => "0" (forces new resource)
...

with no other changes identified.

@leighmhart
Copy link
Author

@danawillow FWIW, this has worked in several other projects - it's just one project where now it is unable to refresh due to this zonal resource disk issue - I don't think it is related to the initialize_params (we should probably split those two issues out).

@danawillow
Copy link
Contributor

Hey @allandrick, with the config I'm seeing now I can't reproduce that exact error. I actually get a different one- Invalid value for field 'resource.disks[0]': ''. Cannot specify both 'source' and 'initializeParams'.

I can send out a fix for the migration that put initialize_params in there when it shouldn't have been, but without a working repro I can't fix the other issue. That one tends to pop up when a disk source is empty, so I'd just make sure that those values are definitely there. If you're still stuck, I'd appreciate the full configs (before and after) as well as debug logs. If you don't feel comfortable posting them here, feel free to reach out over email or slack.

@leighmhart
Copy link
Author

@danawillow thanks for the chat - confirming for anyone else having this issue, the problem was (for some reason, probably my fat fingers) that the state had an invalid number of elements in the attached disks array on the google_compute_instance resource (there was supposed to be 1 attached disk and 1 boot disk):

                        "attributes": {
                            "attached_disk.#": "2",
                            "attached_disk.1.device_name": "data-disk",
                            "attached_disk.1.disk_encryption_key_raw": "",
                            "attached_disk.1.disk_encryption_key_sha256": "",
                            "attached_disk.1.source": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-east1-b/disks/data-disk",

instead of

                        "attributes": {
                            "attached_disk.#": "1",
                            "attached_disk.0.device_name": "data-disk",
                            "attached_disk.0.disk_encryption_key_raw": "",
                            "attached_disk.0.disk_encryption_key_sha256": "",
                            "attached_disk.0.source": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-east1-b/disks/data-disk",

Thanks again for the second set of eyes!

Regards,

Leigh

luis-silva pushed a commit to luis-silva/terraform-provider-google that referenced this issue May 21, 2019
Signed-off-by: Modular Magician <magic-modules@google.com>
@ghost
Copy link

ghost commented Mar 30, 2020

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@hashicorp hashicorp locked and limited conversation to collaborators Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants