GoogleCloudPlatform / terraform-google-managed-instance-group

Modular Google Compute Engine managed instance group for Terraform.
Apache License 2.0
63 stars 139 forks source link

Using a name_prefix instead of name for template #9

Closed AndrewFarley closed 6 years ago

AndrewFarley commented 6 years ago

Problem:

When modifying anything in the instance template, for example, the machine type, it is unable to make this modification in terraform because of a duplicate named resource. Using the lifecycle rule "create before destroy" is necessary, but because of this, there can not be two similarly named templates. For example, when changing the machine type of a template you get...

* google_compute_instance_template.default: Error creating instance template: googleapi: Error 409: The resource 'projects/projectname/global/instanceTemplates/default-7850850885292525658' already exists

Solution:

There is a terraform feature called "name_prefix" instead of "name" in most resources which helps fix this use-case. This merge implements it for the google_compute_instance_template

Notes:

Keep in mind, anyone that is using this template hopefully they have version locked (as is best practice for modules) the previous version, because if they did not they will suddenly have a changed name and re-creating of the template the next time they terraform init which might cause unexpected downtime. I think it's something worth noting in the release notes, and to consider modifying your Usage Example to include version pinning (which it does not currently)

googlebot commented 6 years ago

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers
AndrewFarley commented 6 years ago

I signed it!

googlebot commented 6 years ago

CLAs look good, thanks!

danisla commented 6 years ago

Thanks for the PR. I've been avoiding this breaking change but I think it's finally time to do it. Sorry but I ended up merging a similar change already, this one also deprecates the random_id resource and updates the README with a note about the version pinning.

AndrewFarley commented 6 years ago

@danisla Thanks for that... despite being breaking changes, these are vital changes for an iterable infrastructure. Cheers!