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

Support google_compute_instance import #369

Closed
nikoren opened this issue Aug 30, 2017 · 10 comments · Fixed by #873
Closed

Support google_compute_instance import #369

nikoren opened this issue Aug 30, 2017 · 10 comments · Fixed by #873

Comments

@nikoren
Copy link

nikoren commented Aug 30, 2017

The initial idea was to try to update the configuration for google compute disks:
disk ==> boot_disk/attached_disk as required in version 10 to prevent all the deprecation errors, however this action involves destroying disk and the instance and then re-provision them.

To avoid re-provisioning I thought we can manually remove all the resources from the state and re-import them on by one with the new configuration. Unfortunately importing google_compute_instance is currently not supported. I think we will stay with deprecation warnings and wait until this issue is resolve to update our config .

Terraform Version

Terraform v0.10.2

Affected Resource(s)

  • google_compute_instance

Terraform Configuration Files

resource "google_compute_instance" "compute-recommendation" {
  count = "${var.gce_recommendation_compute_count}"
  name = "${var.environment}-${var.client}-compute-recommendation-${count.index}"
  machine_type = "${var.gce_recommendation_compute_machine_type}"
  zone = "${var.gce_region}-b"
  tags = ["compute-recommendation"]

  boot_disk {
    source = "${element(google_compute_disk.compute-recommendation-disk.*.name, count.index)}"
  }
  network_interface {
    network = "${var.environment}"
    access_config {
      nat_ip =  "${element(google_compute_address.compute-recommendation-static-ips.*.address, count.index)}"
    }
  }
  metadata {
    sshKeys = "${var.gce_ssh_user}:${file("${var.gce_ssh_pub_key_file}")}"
  }
  service_account {
    scopes = "${var.service_account_scopes}"
  }
}

Debug Output

https://gist.github.com/nikoren/887544482ab7597789b36b08a021a3af

Panic Output

Expected Behavior

Compute instance should be imported

Actual Behavior

Get error

Error importing: 1 error(s) occurred:

* module.dev-tst-environment.google_compute_instance.compute-recommendation (import id: 49023364572610319): import module.dev-tst-environment.google_compute_instance.compute-recommendation (id: 49023364572610319): resource google_compute_instance doesn't support import

Steps to Reproduce

  1. create gce_compute_instance
  2. remove instance from state terraform state rm gce_compute_instance.name
  3. Try to import the instance terraform import google_compute_instance.compute-recommendation ${instance_id}
@rosbo
Copy link
Contributor

rosbo commented Aug 30, 2017

Related to #182 which is to add import support for all compute resources.

@danawillow
Copy link
Contributor

Also related to #329 which does a migration to the new fields to avoid the destroy/create you noticed.

@nikoren
Copy link
Author

nikoren commented Aug 31, 2017

Thanks for finding time to look into this issue,
@danawillow do you have any rough estimate for when this PR is going to be ready to merge?

@danawillow
Copy link
Contributor

Hopefully within the next week or two, but it's hard to know.

@rosbo rosbo self-assigned this Oct 5, 2017
@orkunkaraduman
Copy link

orkunkaraduman commented Oct 9, 2017

We have been waiting this feature for a month...

@rosbo rosbo removed their assignment Oct 9, 2017
@galdor
Copy link

galdor commented Oct 30, 2017

Is there any news for this feature ?

@lkr2des
Copy link

lkr2des commented Dec 17, 2017

I guess this open issue is related to what I am noticing as well,

I am on

$ terraform --version
Terraform v0.11.1

  • provider.google v1.1.0

and trying to do,

$ terraform import google_compute_instance.ac01 ac01
google_compute_instance.ac01: Importing from ID "ac01"...
Error importing: 1 error(s) occurred:

  • google_compute_instance.ac01 (import id: ac01): import google_compute_instance.ac01 (id: ac01): resource google_compute_instance doesn't support import

Logs...
2017/12/17 11:36:08 [ERROR] root: eval: *terraform.EvalImportState, err: import google_compute_instance.ac01 (id: ac01): resource google_compute_instance doesn't support import
2017/12/17 11:36:08 [ERROR] root: eval: *terraform.EvalSequence, err: import google_compute_instance.ac01 (id: ac01): resource google_compute_instance doesn't support import

@rosbo rosbo self-assigned this Dec 18, 2017
@rosbo
Copy link
Contributor

rosbo commented Dec 18, 2017

@lkr2des You are correct. This error message shows up because the feature is not supported yet.

It won't be possible to import the metadata field correctly without a breaking change but I can still support import for all the other field. After the import, it will show a diff for the metadata field but since metadata supports update, it shouldn't be a big deal.

I suggest we do it in 2 parts:

  1. Support import w/o the metadata field now.
  2. Wait for v2 to do a breaking change allowing proper import support for the metadata.

@harmon
Copy link

harmon commented Apr 30, 2018

@rosbo I'm currently using the instance import feature with great success, thanks for this addition! One thing I'm noticing is that metadata isn't getting imported (just metadata_startup_script). Does your comment above mean that it currently does not support importing metadata, and it'll be a while until this is supported? I can copy-paste from the google api to get this into terraform, but just curious if this was why I wasn't able to get it working.

Thanks!

@ghost
Copy link

ghost commented Nov 18, 2018

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 unassigned rosbo Nov 18, 2018
@ghost ghost locked and limited conversation to collaborators Nov 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants