Skip to content

Commit 50f26d8

Browse files
Add replacement_method to IGM and RIGM update_policy (#4258) (#2756)
Signed-off-by: Modular Magician <[email protected]>
1 parent adb4c26 commit 50f26d8

File tree

5 files changed

+145
-0
lines changed

5 files changed

+145
-0
lines changed

.changelog/4258.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```release-note:enhancement
2+
compute: added `replacement_method` field to `update_policy` block of `google_compute_instance_group_manager`
3+
```
4+
```release-note:enhancement
5+
compute: added `replacement_method` field to `update_policy` block of `google_compute_region_instance_group_manager`
6+
```

google-beta/resource_compute_instance_group_manager.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,13 @@ func resourceComputeInstanceGroupManager() *schema.Resource {
252252
ValidateFunc: validation.IntBetween(0, 3600),
253253
Description: `Minimum number of seconds to wait for after a newly created instance becomes available. This value must be from range [0, 3600].`,
254254
},
255+
"replacement_method": {
256+
Type: schema.TypeString,
257+
Optional: true,
258+
ValidateFunc: validation.StringInSlice([]string{"RECREATE", "SUBSTITUTE", ""}, false),
259+
DiffSuppressFunc: emptyOrDefaultStringSuppress("SUBSTITUTE"),
260+
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.`,
261+
},
255262
},
256263
},
257264
},
@@ -800,6 +807,7 @@ func expandUpdatePolicy(configured []interface{}) *computeBeta.InstanceGroupMana
800807

801808
updatePolicy.MinimalAction = data["minimal_action"].(string)
802809
updatePolicy.Type = data["type"].(string)
810+
updatePolicy.ReplacementMethod = data["replacement_method"].(string)
803811

804812
// percent and fixed values are conflicting
805813
// when the percent values are set, the fixed values will be ignored
@@ -888,6 +896,7 @@ func flattenUpdatePolicy(updatePolicy *computeBeta.InstanceGroupManagerUpdatePol
888896
up["min_ready_sec"] = updatePolicy.MinReadySec
889897
up["minimal_action"] = updatePolicy.MinimalAction
890898
up["type"] = updatePolicy.Type
899+
up["replacement_method"] = updatePolicy.ReplacementMethod
891900
results = append(results, up)
892901
}
893902
return results

google-beta/resource_compute_instance_group_manager_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,14 @@ func TestAccInstanceGroupManager_updatePolicy(t *testing.T) {
241241
ImportState: true,
242242
ImportStateVerify: true,
243243
},
244+
{
245+
Config: testAccInstanceGroupManager_rollingUpdatePolicy5(igm),
246+
},
247+
{
248+
ResourceName: "google_compute_instance_group_manager.igm-rolling-update-policy",
249+
ImportState: true,
250+
ImportStateVerify: true,
251+
},
244252
},
245253
})
246254
}
@@ -980,6 +988,56 @@ resource "google_compute_instance_group_manager" "igm-rolling-update-policy" {
980988
`, igm)
981989
}
982990

991+
func testAccInstanceGroupManager_rollingUpdatePolicy5(igm string) string {
992+
return fmt.Sprintf(`
993+
data "google_compute_image" "my_image" {
994+
family = "debian-9"
995+
project = "debian-cloud"
996+
}
997+
998+
resource "google_compute_instance_template" "igm-rolling-update-policy" {
999+
machine_type = "e2-medium"
1000+
can_ip_forward = false
1001+
tags = ["terraform-testing"]
1002+
disk {
1003+
source_image = data.google_compute_image.my_image.self_link
1004+
auto_delete = true
1005+
boot = true
1006+
}
1007+
network_interface {
1008+
network = "default"
1009+
}
1010+
lifecycle {
1011+
create_before_destroy = true
1012+
}
1013+
}
1014+
1015+
resource "google_compute_instance_group_manager" "igm-rolling-update-policy" {
1016+
description = "Terraform test instance group manager"
1017+
name = "%s"
1018+
version {
1019+
name = "prod2"
1020+
instance_template = google_compute_instance_template.igm-rolling-update-policy.self_link
1021+
}
1022+
base_instance_name = "igm-rolling-update-policy"
1023+
zone = "us-central1-c"
1024+
target_size = 3
1025+
update_policy {
1026+
type = "PROACTIVE"
1027+
minimal_action = "REPLACE"
1028+
max_surge_fixed = 0
1029+
max_unavailable_fixed = 2
1030+
min_ready_sec = 20
1031+
replacement_method = "RECREATE"
1032+
}
1033+
named_port {
1034+
name = "customhttp"
1035+
port = 8080
1036+
}
1037+
}
1038+
`, igm)
1039+
}
1040+
9831041
func testAccInstanceGroupManager_separateRegions(igm1, igm2 string) string {
9841042
return fmt.Sprintf(`
9851043
data "google_compute_image" "my_image" {

google-beta/resource_compute_region_instance_group_manager.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,13 @@ func resourceComputeRegionInstanceGroupManager() *schema.Resource {
279279
DiffSuppressFunc: emptyOrDefaultStringSuppress("PROACTIVE"),
280280
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.`,
281281
},
282+
"replacement_method": {
283+
Type: schema.TypeString,
284+
Optional: true,
285+
ValidateFunc: validation.StringInSlice([]string{"RECREATE", "SUBSTITUTE", ""}, false),
286+
DiffSuppressFunc: emptyOrDefaultStringSuppress("SUBSTITUTE"),
287+
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.`,
288+
},
282289
},
283290
},
284291
},
@@ -639,6 +646,7 @@ func expandRegionUpdatePolicy(configured []interface{}) *computeBeta.InstanceGro
639646
updatePolicy.MinimalAction = data["minimal_action"].(string)
640647
updatePolicy.Type = data["type"].(string)
641648
updatePolicy.InstanceRedistributionType = data["instance_redistribution_type"].(string)
649+
updatePolicy.ReplacementMethod = data["replacement_method"].(string)
642650

643651
// percent and fixed values are conflicting
644652
// when the percent values are set, the fixed values will be ignored
@@ -699,6 +707,7 @@ func flattenRegionUpdatePolicy(updatePolicy *computeBeta.InstanceGroupManagerUpd
699707
up["minimal_action"] = updatePolicy.MinimalAction
700708
up["type"] = updatePolicy.Type
701709
up["instance_redistribution_type"] = updatePolicy.InstanceRedistributionType
710+
up["replacement_method"] = updatePolicy.ReplacementMethod
702711

703712
results = append(results, up)
704713
}

google-beta/resource_compute_region_instance_group_manager_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,14 @@ func TestAccRegionInstanceGroupManager_rollingUpdatePolicy(t *testing.T) {
228228
ImportState: true,
229229
ImportStateVerify: true,
230230
},
231+
{
232+
Config: testAccRegionInstanceGroupManager_rollingUpdatePolicy3(igm),
233+
},
234+
{
235+
ResourceName: "google_compute_region_instance_group_manager.igm-rolling-update-policy",
236+
ImportState: true,
237+
ImportStateVerify: true,
238+
},
231239
},
232240
})
233241
}
@@ -1231,6 +1239,61 @@ resource "google_compute_region_instance_group_manager" "igm-rolling-update-poli
12311239
`, igm)
12321240
}
12331241

1242+
func testAccRegionInstanceGroupManager_rollingUpdatePolicy3(igm string) string {
1243+
return fmt.Sprintf(`
1244+
data "google_compute_image" "my_image" {
1245+
family = "debian-9"
1246+
project = "debian-cloud"
1247+
}
1248+
1249+
resource "google_compute_instance_template" "igm-rolling-update-policy" {
1250+
machine_type = "e2-medium"
1251+
can_ip_forward = false
1252+
tags = ["terraform-testing"]
1253+
1254+
disk {
1255+
source_image = data.google_compute_image.my_image.self_link
1256+
auto_delete = true
1257+
boot = true
1258+
}
1259+
1260+
network_interface {
1261+
network = "default"
1262+
}
1263+
1264+
lifecycle {
1265+
create_before_destroy = true
1266+
}
1267+
}
1268+
1269+
resource "google_compute_region_instance_group_manager" "igm-rolling-update-policy" {
1270+
description = "Terraform test instance group manager"
1271+
name = "%s"
1272+
version {
1273+
name = "primary"
1274+
instance_template = google_compute_instance_template.igm-rolling-update-policy.self_link
1275+
}
1276+
base_instance_name = "igm-rolling-update-policy"
1277+
region = "us-central1"
1278+
distribution_policy_zones = ["us-central1-a", "us-central1-f"]
1279+
target_size = 3
1280+
update_policy {
1281+
type = "PROACTIVE"
1282+
instance_redistribution_type = "NONE"
1283+
minimal_action = "REPLACE"
1284+
max_surge_fixed = 0
1285+
max_unavailable_fixed = 2
1286+
min_ready_sec = 10
1287+
replacement_method = "RECREATE"
1288+
}
1289+
named_port {
1290+
name = "customhttp"
1291+
port = 8080
1292+
}
1293+
}
1294+
`, igm)
1295+
}
1296+
12341297
func testAccRegionInstanceGroupManager_stateful(template, igm string) string {
12351298
return fmt.Sprintf(`
12361299
data "google_compute_image" "my_image" {

0 commit comments

Comments
 (0)