hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.29k stars 1.72k forks source link

Import support for google_compute_instance_from_template #15297

Open mwarkentin opened 1 year ago

mwarkentin commented 1 year ago

Community Note

Description

It would be nice if google_compute_instance_from_template support terraform import. We had a bit of state manipulation gone wrong that left some google_compute_instance_from_template resources stranded and it turns out that we're not able to re-import them under terraform management.

Are there technical reasons that import isn't supported, or does it just need a bit of implementation work? I assume it would look similar to the import support for a regular instance:

$ terraform import google_compute_instance.default projects/{{project}}/zones/{{zone}}/instances/{{name}}
$ terraform import google_compute_instance.default {{project}}/{{zone}}/{{name}}
$ terraform import google_compute_instance.default {{name}}

New or Affected Resource(s)

Potential Terraform Configuration

N/A

References

rileykarson commented 1 year ago

These resources(from_template and from_machine_image) are a little different than other standard resources because they mostly map to the API call that the resource was created through. I think it was intentional to omit this because you would be expected to import preexisting resources through google_compute_instance. However, in the case of reused configurations that may not always make sense / be possible.

rileykarson commented 3 days ago

Thinking about this a bit more- what does this solve that importing by google_compute_instance with https://developer.hashicorp.com/terraform/tutorials/state/state-import#generate-configuration doesn't? Widely reused configurations are the primary usecase I'd see but I'd be surprised if these resources were used extensively in those over google_compute_instance modules or MIGs to manage the instance templates' instances.