Skip to content

Commit

Permalink
Add replacement_method to IGM and RIGM update_policy (#4258) (#2756)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Dec 2, 2020
1 parent adb4c26 commit 50f26d8
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changelog/4258.txt
Original file line number Diff line number Diff line change
@@ -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`
```
9 changes: 9 additions & 0 deletions google-beta/resource_compute_instance_group_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
},
},
},
},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
58 changes: 58 additions & 0 deletions google-beta/resource_compute_instance_group_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
})
}
Expand Down Expand Up @@ -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" {
Expand Down
9 changes: 9 additions & 0 deletions google-beta/resource_compute_region_instance_group_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
},
},
},
},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
63 changes: 63 additions & 0 deletions google-beta/resource_compute_region_instance_group_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
})
}
Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit 50f26d8

Please sign in to comment.