From 665c4fff2a65f2b7c6cdd525bc954940f5254947 Mon Sep 17 00:00:00 2001 From: Evan Brown Date: Wed, 11 May 2016 14:54:47 -0700 Subject: [PATCH] providers/google: support optionial uuid naming for Instance Template (#6604) Auto-generating an Instance Template name (or just its suffix) allows the create_before_destroy lifecycle option to function correctly on the Instance Template resource. This in turn allows Instance Group Managers to be updated without being destroyed. --- r/compute_instance_template.html.markdown | 55 ++++++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/r/compute_instance_template.html.markdown b/r/compute_instance_template.html.markdown index e6bc6e6b..be56da80 100644 --- a/r/compute_instance_template.html.markdown +++ b/r/compute_instance_template.html.markdown @@ -58,6 +58,51 @@ resource "google_compute_instance_template" "foobar" { } ``` +## Using with Instance Group Manager + +Instance Templates cannot be updated after creation with the Google +Cloud Platform API. In order to update an Instance Template, Terraform will +destroy the existing resource and create a replacement. In order to effectively +use an Instance Template resource with an [Instance Group Manager resource][1], +it's recommended to specify `create_before_destroy` in a [lifecycle][2] block. +Either omit the Instance Template `name` attribute, or specify a partial name +with `name_prefix`. Example: + +``` +resource "google_compute_instance_template" "instance_template" { + name_prefix = "instance-template-" + machine_type = "n1-standard-1" + region = "us-central1" + + // boot disk + disk { + ... + } + + // networking + network_interface { + ... + } + + lifecycle { + create_before_destroy = true + } +} + +resource "google_compute_instance_group_manager" "instance_group_manager" { + name = "instance-group-manager" + instance_template = "${google_compute_instance_template.instance_template.self_link}" + base_instance_name = "instance-group-manager" + zone = "us-central1-f" + target_size = "1" +} +``` + +With this setup Terraform generates a unique name for your Instance +Template and can then update the Instance Group manager without conflict before +destroying the previous Instance Template. + + ## Argument Reference Note that changing any field for this resource forces a new resource to be created. @@ -70,9 +115,12 @@ The following arguments are supported: * `machine_type` - (Required) The machine type to create. -* `name` - (Required) A unique name for the resource, required by GCE. - - - - +* `name` - (Optional) The name of the instance template. If you leave + this blank, Terraform will auto-generate a unique name. + +* `name_prefix` - (Optional) Creates a unique name beginning with the specified + prefix. Conflicts with `name`. * `can_ip_forward` - (Optional) Whether to allow sending and receiving of packets with non-matching source or destination IPs. This defaults to false. @@ -191,3 +239,6 @@ exported: * `self_link` - The URI of the created resource. * `tags_fingerprint` - The unique fingerprint of the tags. + +[1]: /docs/providers/google/r/compute_instance_group_manager.html +[2]: /docs/configuration/resources.html#lifecycle