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 engine instance and disk referencing error #112

Closed
hashibot opened this issue Jun 13, 2017 · 8 comments · Fixed by #320
Closed

Google compute engine instance and disk referencing error #112

hashibot opened this issue Jun 13, 2017 · 8 comments · Fixed by #320
Labels

Comments

@hashibot
Copy link

This issue was originally opened by @nodesocket as hashicorp/terraform#15181. It was migrated here as part of the provider split. The original body of the issue is below.


Think I discovered a bug using google_compute_disk and google_compute_instance referencing resources.

Create a disk using a resource block like:

resource "google_compute_disk" "blog" {
    name  = "blog"
    type  = "pd-ssd"
    zone  = "us-west1-a"
    snapshot = "some-snapshot-here"
    size = 10
}

Then create an instance referencing the above disk:

resource "google_compute_instance" "blog" {
    name = "blog"
    machine_type = "f1-micro"
    zone = "${google_compute_disk.blog.zone}"

    tags = []

    disk {
        disk = "${google_compute_disk.blog.name}"
        auto_delete = true
    }

    network_interface {
        network = "default"
        access_config {
            # ephemeral external ip address
        }
    }

    metadata {
    }

    service_account {
        scopes = ["https://www.googleapis.com/auth/servicecontrol",
                  "https://www.googleapis.com/auth/service.management.readonly",
                  "https://www.googleapis.com/auth/logging.write",
                  "https://www.googleapis.com/auth/monitoring.write",
                  "https://www.googleapis.com/auth/trace.append",
                  "https://www.googleapis.com/auth/devstorage.read_only",
                  "https://www.googleapis.com/auth/cloud.useraccounts.readonly"]
    }

    scheduling {
        preemptible = false
        on_host_maintenance = "MIGRATE"
        automatic_restart = true
    }
}

After the apply finishes, run apply again. You will see the following error:

Error applying plan:

1 error(s) occurred:

* google_compute_disk.blog (destroy): 1 error(s) occurred:

* google_compute_disk.blog: Error detaching disk persistent-disk-0 from instance project-id-here/https://www.googleapis.com/compute/v1/projects/project-id-here/zones/us-west1-a/blog: googleapi: Error 400: Invalid value 'https://www.googleapis.com/compute/v1/projects/project-id-here/zones/us-west1-a'. Values must match the following regular expression: '[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?', invalidParameter

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
@hashibot hashibot added the bug label Jun 13, 2017
@nodesocket
Copy link
Contributor

nodesocket commented Jun 17, 2017

Bump of this please. The specific error seems to be:

Error detaching disk persistent-disk-0 from instance project-id-here/https://www.googleapis.com/compute/v1/projects/project-id-here/zones/us-west1-a/blog: googleapi: Error 400: Invalid value 'https://www.googleapis.com/compute/v1/projects/project-id-here/zones/us-west1-a'. Values must match the following regular expression: '[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?', invalidParameter

@danawillow
Copy link
Contributor

Hey @nodesocket, sorry you're having issues. I'm actually doing a big rework of the disk attaching process so I'm not going to be able to get to this specific issue right away, but it should be resolved reasonably soon as a result of the other work!

@nodesocket
Copy link
Contributor

Great. Is this specific to creating a disk from a snapshot or does this bug also apply to creating disks via an image and associating with a VM instance?

@danawillow
Copy link
Contributor

My work is focusing on the latter.

@nodesocket
Copy link
Contributor

nodesocket commented Jun 21, 2017

Ok, well I need both cases to work 😸 .

Create disk from snapshot:

resource "google_compute_disk" "blog" {
    name  = "blog"
    type  = "pd-ssd"
    zone  = "us-west1-a"
    snapshot = "some-snapshot-here"
    size = 10
}

Create disk from image:

resource "google_compute_disk" "blog" {
    name  = "blog"
    type  = "pd-ssd"
    zone  = "us-west1-a"
    image = "some-image-here"
    size = 10
}

disk {
    disk = "${google_compute_disk.blog.name}"
    auto_delete = true
}

@nodesocket
Copy link
Contributor

nodesocket commented Aug 3, 2017

This seems to actually still be a bug.

iMac ➜  terraform git:(master) ✗ terraform apply
Error applying plan:

1 error(s) occurred:

* google_compute_disk.blog (destroy): 1 error(s) occurred:

* google_compute_disk.blog: Error detaching disk persistent-disk-0 from instance my-project/https://www.googleapis.com/compute/v1/projects/my-project/zones/us-west1-a/blog: googleapi: Error 400: Invalid value 'https://www.googleapis.com/compute/v1/projects/my-project/zones/us-west1-a'. Values must match the following regular expression: '[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?', invalidParameter

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
-/+ google_compute_disk.blog (new resource required)
      disk_encryption_key_sha256: "" => "<computed>"
      name:                       "blog" => "blog"
      self_link:                  "https://www.googleapis.com/compute/v1/projects/my-project/zones/us-west1-a/disks/blog" => "<computed>"
      size:                       "10" => "10"
      snapshot:                   "https://www.googleapis.com/compute/v1/projects/my-project/global/snapshots/blog-2017-07-12-1" => "blog-2017-07-12-1" (forces new resource)
      type:                       "pd-ssd" => "pd-ssd"
      users.#:                    "1" => "<computed>"
      zone:                       "us-west1-a" => "us-west1-a"

@rileykarson
Copy link
Collaborator

The disk should be successfully detached with #320; I just wanted to note that this doesn't mean that attaching and detaching will work, and that deleting a disk means it will be removed completely from the instance. The delete operation will just succeed now, instead of failing unintentionally.

luis-silva pushed a commit to luis-silva/terraform-provider-google that referenced this issue May 21, 2019
@ghost
Copy link

ghost commented Mar 31, 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 👉 [email protected]. Thanks!

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