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

Can't specify snapshots on Google Compute #902

Closed
spuder opened this issue Jan 30, 2015 · 5 comments
Closed

Can't specify snapshots on Google Compute #902

spuder opened this issue Jan 30, 2015 · 5 comments

Comments

@spuder
Copy link
Contributor

spuder commented Jan 30, 2015

Currently, it appears that you can only create instances on google compute using images.
Terraform should also support using snapshots.

screenshot 2015-01-30 15 40 24

resource "google_compute_instance" "kafka01" {
    name = "kafka01"
    machine_type = "g1-small"
    zone = "us-central1-a"

    disk {
#        image = "ubuntu-1404-trusty-v20141212"
        image = "chef-installed"
    }
    network {
        source = "default"
    }
}
$ terraform apply
google_compute_instance.kafka01: Creating...
  can_ip_forward:             "" => "0"
  disk.#:                     "" => "1"
  disk.0.image:               "" => "chef-installed"
  machine_type:               "" => "g1-small"
  metadata_fingerprint:       "" => "<computed>"
  name:                       "" => "kafka01"
  network.#:                  "" => "1"
  network.0.external_address: "" => "<computed>"
  network.0.internal_address: "" => "<computed>"
  network.0.name:             "" => "<computed>"
  network.0.source:           "" => "default"
  tags_fingerprint:           "" => "<computed>"
  zone:                       "" => "us-central1-a"
google_compute_instance.kafka01: Error: Error loading image 'chef-installed': googleapi: Error 404: The resource 'projects/foobar/global/images/chef-installed' was not found, notFound
Error applying plan:

1 error(s) occurred:

* Error loading image 'chef-installed': googleapi: Error 404: The resource 'projects/brave-reason-831/global/images/chef-installed' was not found, notFound

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.
@spuder spuder changed the title Google Compute should let you specify snapshots Can't specify snapshots on Google Compute Jan 30, 2015
@sparkprime
Copy link
Contributor

The underlying instance API does not allow creating a disk from a snapshot, only an image. In fact it only allows creating the first disk (the boot disk) from an image. The rest have to be existing disks. The Cloud Console actually implemented the operation you have screenshotted as two POST requests, which you can see by clicking on the "Equivalent REST" link at the bottom. That is not the case if you initialize the disk from an image as there is a special sourceImage field in the create instance API.

We could replicate the console behavior, but I'd actually rather not as I see Terraform mirroring the underlying resources in a 1:1 fashion (the Google commandline utility gcloud also does not implement this convenience feature).

I will submit a PR to allow something like the following, would that be sufficient for you?

resource "google_compute_disk" "kafka01" {
    name = "kafka01"
    snapshot = "chef-installed"
}

resource "google_compute_instance" "kafka01" {
    name = "kafka01"
    machine_type = "g1-small"
    zone = "us-central1-a"

    disk {
        disk = "kafka01"
        auto_delete = false
    }
    network {
        source = "default"
    }
}

@spuder
Copy link
Contributor Author

spuder commented Jan 31, 2015

That would be great, thank you.

@mitchellh
Copy link
Contributor

Fixed by #1426

@kamaljeetrathi
Copy link

how to give dynamic name to the instance id

@ghost
Copy link

ghost commented Apr 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 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.

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

No branches or pull requests

5 participants