From 8bf3caf3fabc976c13efe2d8b76e5971154afb82 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Wed, 2 Dec 2020 00:44:35 +0000 Subject: [PATCH] Add replacement_method to IGM and RIGM update_policy (#4258) Signed-off-by: Modular Magician --- .changelog/4258.txt | 6 ++ ...resource_compute_instance_group_manager.go | 9 +++ ...rce_compute_instance_group_manager_test.go | 58 +++++++++++++++++ ...e_compute_region_instance_group_manager.go | 9 +++ ...pute_region_instance_group_manager_test.go | 63 +++++++++++++++++++ 5 files changed, 145 insertions(+) create mode 100644 .changelog/4258.txt diff --git a/.changelog/4258.txt b/.changelog/4258.txt new file mode 100644 index 0000000000..386c35b3b9 --- /dev/null +++ b/.changelog/4258.txt @@ -0,0 +1,6 @@ +```release-note:enhancement +compute: added `replacement_method` field to `update_policy` block of `google_compute_instance_group_manager` +``` +```release-note:enhancement +compute: added `replacement_method` field to `update_policy` block of `google_compute_region_instance_group_manager` +``` diff --git a/google-beta/resource_compute_instance_group_manager.go b/google-beta/resource_compute_instance_group_manager.go index 33d221dcea..aa5b159a73 100644 --- a/google-beta/resource_compute_instance_group_manager.go +++ b/google-beta/resource_compute_instance_group_manager.go @@ -252,6 +252,13 @@ func resourceComputeInstanceGroupManager() *schema.Resource { ValidateFunc: validation.IntBetween(0, 3600), Description: `Minimum number of seconds to wait for after a newly created instance becomes available. This value must be from range [0, 3600].`, }, + "replacement_method": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"RECREATE", "SUBSTITUTE", ""}, false), + DiffSuppressFunc: emptyOrDefaultStringSuppress("SUBSTITUTE"), + Description: `The instance replacement method for managed instance groups. Valid values are: "RECREATE", "SUBSTITUTE". If SUBSTITUTE (default), the group replaces VM instances with new instances that have randomly generated names. If RECREATE, instance names are preserved. You must also set max_unavailable_fixed or max_unavailable_percent to be greater than 0.`, + }, }, }, }, @@ -800,6 +807,7 @@ func expandUpdatePolicy(configured []interface{}) *computeBeta.InstanceGroupMana updatePolicy.MinimalAction = data["minimal_action"].(string) updatePolicy.Type = data["type"].(string) + updatePolicy.ReplacementMethod = data["replacement_method"].(string) // percent and fixed values are conflicting // when the percent values are set, the fixed values will be ignored @@ -888,6 +896,7 @@ func flattenUpdatePolicy(updatePolicy *computeBeta.InstanceGroupManagerUpdatePol up["min_ready_sec"] = updatePolicy.MinReadySec up["minimal_action"] = updatePolicy.MinimalAction up["type"] = updatePolicy.Type + up["replacement_method"] = updatePolicy.ReplacementMethod results = append(results, up) } return results diff --git a/google-beta/resource_compute_instance_group_manager_test.go b/google-beta/resource_compute_instance_group_manager_test.go index 4cb579fa8f..cba4a66665 100644 --- a/google-beta/resource_compute_instance_group_manager_test.go +++ b/google-beta/resource_compute_instance_group_manager_test.go @@ -241,6 +241,14 @@ func TestAccInstanceGroupManager_updatePolicy(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + Config: testAccInstanceGroupManager_rollingUpdatePolicy5(igm), + }, + { + ResourceName: "google_compute_instance_group_manager.igm-rolling-update-policy", + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -980,6 +988,56 @@ resource "google_compute_instance_group_manager" "igm-rolling-update-policy" { `, igm) } +func testAccInstanceGroupManager_rollingUpdatePolicy5(igm string) string { + return fmt.Sprintf(` +data "google_compute_image" "my_image" { + family = "debian-9" + project = "debian-cloud" +} + +resource "google_compute_instance_template" "igm-rolling-update-policy" { + machine_type = "e2-medium" + can_ip_forward = false + tags = ["terraform-testing"] + disk { + source_image = data.google_compute_image.my_image.self_link + auto_delete = true + boot = true + } + network_interface { + network = "default" + } + lifecycle { + create_before_destroy = true + } +} + +resource "google_compute_instance_group_manager" "igm-rolling-update-policy" { + description = "Terraform test instance group manager" + name = "%s" + version { + name = "prod2" + instance_template = google_compute_instance_template.igm-rolling-update-policy.self_link + } + base_instance_name = "igm-rolling-update-policy" + zone = "us-central1-c" + target_size = 3 + update_policy { + type = "PROACTIVE" + minimal_action = "REPLACE" + max_surge_fixed = 0 + max_unavailable_fixed = 2 + min_ready_sec = 20 + replacement_method = "RECREATE" + } + named_port { + name = "customhttp" + port = 8080 + } +} +`, igm) +} + func testAccInstanceGroupManager_separateRegions(igm1, igm2 string) string { return fmt.Sprintf(` data "google_compute_image" "my_image" { diff --git a/google-beta/resource_compute_region_instance_group_manager.go b/google-beta/resource_compute_region_instance_group_manager.go index 821b001fe7..1402227d03 100644 --- a/google-beta/resource_compute_region_instance_group_manager.go +++ b/google-beta/resource_compute_region_instance_group_manager.go @@ -279,6 +279,13 @@ func resourceComputeRegionInstanceGroupManager() *schema.Resource { DiffSuppressFunc: emptyOrDefaultStringSuppress("PROACTIVE"), Description: `The instance redistribution policy for regional managed instance groups. Valid values are: "PROACTIVE", "NONE". If PROACTIVE (default), the group attempts to maintain an even distribution of VM instances across zones in the region. If NONE, proactive redistribution is disabled.`, }, + "replacement_method": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"RECREATE", "SUBSTITUTE", ""}, false), + DiffSuppressFunc: emptyOrDefaultStringSuppress("SUBSTITUTE"), + Description: `The instance replacement method for regional managed instance groups. Valid values are: "RECREATE", "SUBSTITUTE". If SUBSTITUTE (default), the group replaces VM instances with new instances that have randomly generated names. If RECREATE, instance names are preserved. You must also set max_unavailable_fixed or max_unavailable_percent to be greater than 0.`, + }, }, }, }, @@ -639,6 +646,7 @@ func expandRegionUpdatePolicy(configured []interface{}) *computeBeta.InstanceGro updatePolicy.MinimalAction = data["minimal_action"].(string) updatePolicy.Type = data["type"].(string) updatePolicy.InstanceRedistributionType = data["instance_redistribution_type"].(string) + updatePolicy.ReplacementMethod = data["replacement_method"].(string) // percent and fixed values are conflicting // when the percent values are set, the fixed values will be ignored @@ -699,6 +707,7 @@ func flattenRegionUpdatePolicy(updatePolicy *computeBeta.InstanceGroupManagerUpd up["minimal_action"] = updatePolicy.MinimalAction up["type"] = updatePolicy.Type up["instance_redistribution_type"] = updatePolicy.InstanceRedistributionType + up["replacement_method"] = updatePolicy.ReplacementMethod results = append(results, up) } diff --git a/google-beta/resource_compute_region_instance_group_manager_test.go b/google-beta/resource_compute_region_instance_group_manager_test.go index 178d8bd49a..9cb7f5f67a 100644 --- a/google-beta/resource_compute_region_instance_group_manager_test.go +++ b/google-beta/resource_compute_region_instance_group_manager_test.go @@ -228,6 +228,14 @@ func TestAccRegionInstanceGroupManager_rollingUpdatePolicy(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + Config: testAccRegionInstanceGroupManager_rollingUpdatePolicy3(igm), + }, + { + ResourceName: "google_compute_region_instance_group_manager.igm-rolling-update-policy", + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -1231,6 +1239,61 @@ resource "google_compute_region_instance_group_manager" "igm-rolling-update-poli `, igm) } +func testAccRegionInstanceGroupManager_rollingUpdatePolicy3(igm string) string { + return fmt.Sprintf(` +data "google_compute_image" "my_image" { + family = "debian-9" + project = "debian-cloud" +} + +resource "google_compute_instance_template" "igm-rolling-update-policy" { + machine_type = "e2-medium" + can_ip_forward = false + tags = ["terraform-testing"] + + disk { + source_image = data.google_compute_image.my_image.self_link + auto_delete = true + boot = true + } + + network_interface { + network = "default" + } + + lifecycle { + create_before_destroy = true + } +} + +resource "google_compute_region_instance_group_manager" "igm-rolling-update-policy" { + description = "Terraform test instance group manager" + name = "%s" + version { + name = "primary" + instance_template = google_compute_instance_template.igm-rolling-update-policy.self_link + } + base_instance_name = "igm-rolling-update-policy" + region = "us-central1" + distribution_policy_zones = ["us-central1-a", "us-central1-f"] + target_size = 3 + update_policy { + type = "PROACTIVE" + instance_redistribution_type = "NONE" + minimal_action = "REPLACE" + max_surge_fixed = 0 + max_unavailable_fixed = 2 + min_ready_sec = 10 + replacement_method = "RECREATE" + } + named_port { + name = "customhttp" + port = 8080 + } +} +`, igm) +} + func testAccRegionInstanceGroupManager_stateful(template, igm string) string { return fmt.Sprintf(` data "google_compute_image" "my_image" {