Skip to content

Commit 81b088a

Browse files
Add new field instanceLifecyclePolicy.onRepair.allowChangingZone to google_compute_region_instance_group_manager & google_compute_instance_group_manager (#14580)
1 parent ac90bd0 commit 81b088a

6 files changed

+192
-27
lines changed

mmv1/third_party/terraform/services/compute/resource_compute_instance_group_manager.go.tmpl

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,28 @@ func ResourceComputeInstanceGroupManager() *schema.Resource {
380380
ValidateFunc: validation.StringInSlice([]string{"YES", "NO"}, true),
381381
Description: `Specifies whether to apply the group's latest configuration when repairing a VM. Valid options are: YES, NO. If YES and you updated the group's instance template or per-instance configurations after the VM was created, then these changes are applied when VM is repaired. If NO (default), then updates are applied in accordance with the group's update policy type.`,
382382
},
383+
384+
{{- if ne $.TargetVersionName `ga` }}
385+
"on_repair": {
386+
Type: schema.TypeList,
387+
Computed: true,
388+
Optional: true,
389+
MaxItems: 1,
390+
Description: `Configuration for VM repairs in the MIG.`,
391+
Elem: &schema.Resource{
392+
Schema: map[string]*schema.Schema{
393+
"allow_changing_zone": {
394+
Type: schema.TypeString,
395+
Optional: true,
396+
Default: "NO",
397+
ValidateFunc: validation.StringInSlice([]string{"YES", "NO"}, true),
398+
Description: `Specifies whether the MIG can change a VM's zone during a repair. If "YES", MIG can select a different zone for the VM during a repair. Else if "NO", MIG cannot change a VM's zone during a repair. The default value of allow_changing_zone is "NO".`,
399+
},
400+
},
401+
},
402+
},
403+
{{- end }}
404+
383405
},
384406
},
385407
},
@@ -1362,13 +1384,29 @@ func expandInstanceLifecyclePolicy(configured []interface{}) *compute.InstanceGr
13621384
data := raw.(map[string]interface{})
13631385
instanceLifecyclePolicy.ForceUpdateOnRepair = data["force_update_on_repair"].(string)
13641386
instanceLifecyclePolicy.DefaultActionOnFailure = data["default_action_on_failure"].(string)
1365-
{{ if ne $.TargetVersionName `ga` -}}
1387+
1388+
{{ if ne $.TargetVersionName `ga` -}}
13661389
instanceLifecyclePolicy.OnFailedHealthCheck = data["on_failed_health_check"].(string)
1367-
{{- end }}
1390+
{{- end }}
1391+
1392+
{{- if ne $.TargetVersionName `ga` }}
1393+
instanceLifecyclePolicy.OnRepair = expandOnRepair(data["on_repair"].([]any))
1394+
{{- end }}
13681395
}
13691396
return instanceLifecyclePolicy
13701397
}
13711398

1399+
{{ if ne $.TargetVersionName `ga` -}}
1400+
func expandOnRepair(configured []any) *compute.InstanceGroupManagerInstanceLifecyclePolicyOnRepair {
1401+
onRepair := &compute.InstanceGroupManagerInstanceLifecyclePolicyOnRepair{}
1402+
for _, raw := range configured {
1403+
data := raw.(map[string]any)
1404+
onRepair.AllowChangingZone = data["allow_changing_zone"].(string)
1405+
}
1406+
return onRepair
1407+
}
1408+
{{- end }}
1409+
13721410
func expandStandbyPolicy(d *schema.ResourceData) *compute.InstanceGroupManagerStandbyPolicy {
13731411
standbyPolicy := &compute.InstanceGroupManagerStandbyPolicy{}
13741412
for _, sp := range d.Get("standby_policy").([]any) {
@@ -1563,14 +1601,31 @@ func flattenInstanceLifecyclePolicy(instanceLifecyclePolicy *compute.InstanceGro
15631601
ilp := map[string]interface{}{}
15641602
ilp["force_update_on_repair"] = instanceLifecyclePolicy.ForceUpdateOnRepair
15651603
ilp["default_action_on_failure"] = instanceLifecyclePolicy.DefaultActionOnFailure
1566-
{{ if ne $.TargetVersionName `ga` -}}
1604+
1605+
{{ if ne $.TargetVersionName `ga` -}}
15671606
ilp["on_failed_health_check"] = instanceLifecyclePolicy.OnFailedHealthCheck
1568-
{{- end }}
1607+
{{- end }}
1608+
1609+
{{ if ne $.TargetVersionName `ga` -}}
1610+
ilp["on_repair"] = flattenOnRepair(instanceLifecyclePolicy.OnRepair)
1611+
{{- end }}
15691612
results = append(results, ilp)
15701613
}
15711614
return results
15721615
}
15731616

1617+
{{ if ne $.TargetVersionName `ga` -}}
1618+
func flattenOnRepair(onRepair *compute.InstanceGroupManagerInstanceLifecyclePolicyOnRepair) []map[string]any {
1619+
results := []map[string]any{}
1620+
if onRepair != nil {
1621+
or := map[string]any{}
1622+
or["allow_changing_zone"] = onRepair.AllowChangingZone
1623+
results = append(results, or)
1624+
}
1625+
return results
1626+
}
1627+
{{- end }}
1628+
15741629
func expandAllInstancesConfig(old []interface{}, new []interface{}) *compute.InstanceGroupManagerAllInstancesConfig {
15751630
var properties *compute.InstancePropertiesPatch
15761631
for _, raw := range new {

mmv1/third_party/terraform/services/compute/resource_compute_instance_group_manager_test.go.tmpl

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,14 @@ func TestAccInstanceGroupManager_update(t *testing.T) {
172172
Config: testAccInstanceGroupManager_update(template1, target1, description, igm),
173173
Check: resource.ComposeTestCheckFunc(
174174
resource.TestCheckResourceAttr("google_compute_instance_group_manager.igm-update", "instance_lifecycle_policy.0.default_action_on_failure", "DO_NOTHING"),
175-
{{- if ne $.TargetVersionName "ga" }}
176-
resource.TestCheckResourceAttr("google_compute_instance_group_manager.igm-update", "instance_lifecycle_policy.0.on_failed_health_check", "DO_NOTHING"),
177-
{{- end }}
175+
176+
{{- if ne $.TargetVersionName "ga" }}
177+
resource.TestCheckResourceAttr("google_compute_instance_group_manager.igm-update", "instance_lifecycle_policy.0.on_failed_health_check", "DO_NOTHING"),
178+
{{- end }}
179+
180+
{{- if ne $.TargetVersionName "ga" }}
181+
resource.TestCheckResourceAttr("google_compute_instance_group_manager.igm-update", "instance_lifecycle_policy.0.on_repair.0.allow_changing_zone", "NO"),
182+
{{- end }}
178183
),
179184
},
180185
{
@@ -187,9 +192,14 @@ func TestAccInstanceGroupManager_update(t *testing.T) {
187192
Config: testAccInstanceGroupManager_update2(template1, target1, target2, template2, description, igm),
188193
Check: resource.ComposeTestCheckFunc(
189194
resource.TestCheckResourceAttr("google_compute_instance_group_manager.igm-update", "instance_lifecycle_policy.0.default_action_on_failure", "REPAIR"),
190-
{{- if ne $.TargetVersionName "ga" }}
191-
resource.TestCheckResourceAttr("google_compute_instance_group_manager.igm-update", "instance_lifecycle_policy.0.on_failed_health_check", "REPAIR"),
192-
{{- end }}
195+
196+
{{- if ne $.TargetVersionName "ga" }}
197+
resource.TestCheckResourceAttr("google_compute_instance_group_manager.igm-update", "instance_lifecycle_policy.0.on_failed_health_check", "REPAIR"),
198+
{{- end }}
199+
200+
{{- if ne $.TargetVersionName "ga" }}
201+
resource.TestCheckResourceAttr("google_compute_instance_group_manager.igm-update", "instance_lifecycle_policy.0.on_repair.0.allow_changing_zone", "NO"),
202+
{{- end }}
193203
),
194204
},
195205
{
@@ -984,9 +994,16 @@ resource "google_compute_instance_group_manager" "igm-update" {
984994
instance_lifecycle_policy {
985995
force_update_on_repair = "NO"
986996
default_action_on_failure = "REPAIR"
987-
{{- if ne $.TargetVersionName "ga" }}
997+
998+
{{- if ne $.TargetVersionName "ga" }}
988999
on_failed_health_check = "REPAIR"
989-
{{- end }}
1000+
{{- end }}
1001+
1002+
{{- if ne $.TargetVersionName "ga" }}
1003+
on_repair {
1004+
allow_changing_zone = "NO"
1005+
}
1006+
{{- end }}
9901007
}
9911008
}
9921009
`, template1, target1, target2, template2, description, igm)

mmv1/third_party/terraform/services/compute/resource_compute_region_instance_group_manager.go.tmpl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,28 @@ func ResourceComputeRegionInstanceGroupManager() *schema.Resource {
336336
ValidateFunc: validation.StringInSlice([]string{"YES", "NO"}, false),
337337
Description: `Specifies whether to apply the group's latest configuration when repairing a VM. Valid options are: YES, NO. If YES and you updated the group's instance template or per-instance configurations after the VM was created, then these changes are applied when VM is repaired. If NO (default), then updates are applied in accordance with the group's update policy type.`,
338338
},
339+
340+
{{- if ne $.TargetVersionName `ga` }}
341+
"on_repair": {
342+
Type: schema.TypeList,
343+
Computed: true,
344+
Optional: true,
345+
MaxItems: 1,
346+
Description: `Configuration for VM repairs in the MIG.`,
347+
Elem: &schema.Resource{
348+
Schema: map[string]*schema.Schema{
349+
"allow_changing_zone": {
350+
Type: schema.TypeString,
351+
Optional: true,
352+
Default: "NO",
353+
ValidateFunc: validation.StringInSlice([]string{"YES", "NO"}, true),
354+
Description: `Specifies whether the MIG can change a VM's zone during a repair. If "YES", MIG can select a different zone for the VM during a repair. Else if "NO", MIG cannot change a VM's zone during a repair. The default value of allow_changing_zone is "NO".`,
355+
},
356+
},
357+
},
358+
},
359+
{{- end }}
360+
339361
},
340362
},
341363
},

mmv1/third_party/terraform/services/compute/resource_compute_region_instance_group_manager_test.go.tmpl

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,16 @@ func TestAccRegionInstanceGroupManager_update(t *testing.T) {
9090
Config: testAccRegionInstanceGroupManager_update(template1, target1, igm),
9191
Check: resource.ComposeTestCheckFunc(
9292
resource.TestCheckResourceAttr("google_compute_region_instance_group_manager.igm-update", "instance_lifecycle_policy.0.default_action_on_failure", "DO_NOTHING"),
93-
{{- if ne $.TargetVersionName "ga" }}
94-
resource.TestCheckResourceAttr("google_compute_region_instance_group_manager.igm-update", "instance_lifecycle_policy.0.on_failed_health_check", "DO_NOTHING"),
95-
{{- end }}
93+
94+
{{- if ne $.TargetVersionName "ga" }}
95+
resource.TestCheckResourceAttr("google_compute_region_instance_group_manager.igm-update", "instance_lifecycle_policy.0.on_failed_health_check", "DO_NOTHING"),
96+
{{- end }}
97+
98+
{{- if ne $.TargetVersionName "ga" }}
99+
resource.TestCheckResourceAttr("google_compute_region_instance_group_manager.igm-update", "instance_lifecycle_policy.0.force_update_on_repair", "NO"),
100+
resource.TestCheckResourceAttr("google_compute_region_instance_group_manager.igm-update", "instance_lifecycle_policy.0.on_repair.0.allow_changing_zone", "NO"),
101+
{{- end }}
102+
96103
),
97104
},
98105
{
@@ -105,9 +112,16 @@ func TestAccRegionInstanceGroupManager_update(t *testing.T) {
105112
Config: testAccRegionInstanceGroupManager_update2(template1, target1, target2, template2, igm),
106113
Check: resource.ComposeTestCheckFunc(
107114
resource.TestCheckResourceAttr("google_compute_region_instance_group_manager.igm-update", "instance_lifecycle_policy.0.default_action_on_failure", "REPAIR"),
108-
{{- if ne $.TargetVersionName "ga" }}
109-
resource.TestCheckResourceAttr("google_compute_region_instance_group_manager.igm-update", "instance_lifecycle_policy.0.on_failed_health_check", "REPAIR"),
110-
{{- end }}
115+
116+
{{- if ne $.TargetVersionName "ga" }}
117+
resource.TestCheckResourceAttr("google_compute_region_instance_group_manager.igm-update", "instance_lifecycle_policy.0.on_failed_health_check", "REPAIR"),
118+
{{- end }}
119+
120+
{{- if ne $.TargetVersionName "ga" }}
121+
resource.TestCheckResourceAttr("google_compute_region_instance_group_manager.igm-update", "instance_lifecycle_policy.0.force_update_on_repair", "YES"),
122+
resource.TestCheckResourceAttr("google_compute_region_instance_group_manager.igm-update", "instance_lifecycle_policy.0.on_repair.0.allow_changing_zone", "YES"),
123+
{{- end }}
124+
111125
),
112126
},
113127
{
@@ -120,9 +134,16 @@ func TestAccRegionInstanceGroupManager_update(t *testing.T) {
120134
Config: testAccRegionInstanceGroupManager_update3(template1, target1, target2, template2, igm),
121135
Check: resource.ComposeTestCheckFunc(
122136
resource.TestCheckResourceAttr("google_compute_region_instance_group_manager.igm-update", "instance_lifecycle_policy.0.default_action_on_failure", "REPAIR"),
123-
{{- if ne $.TargetVersionName "ga" }}
124-
resource.TestCheckResourceAttr("google_compute_region_instance_group_manager.igm-update", "instance_lifecycle_policy.0.on_failed_health_check", "REPAIR"),
125-
{{- end }}
137+
138+
{{- if ne $.TargetVersionName "ga" }}
139+
resource.TestCheckResourceAttr("google_compute_region_instance_group_manager.igm-update", "instance_lifecycle_policy.0.on_failed_health_check", "REPAIR"),
140+
{{- end }}
141+
142+
{{- if ne $.TargetVersionName "ga" }}
143+
resource.TestCheckResourceAttr("google_compute_region_instance_group_manager.igm-update", "instance_lifecycle_policy.0.force_update_on_repair", "YES"),
144+
resource.TestCheckResourceAttr("google_compute_region_instance_group_manager.igm-update", "instance_lifecycle_policy.0.on_repair.0.allow_changing_zone", "YES"),
145+
{{- end }}
146+
126147
),
127148
},
128149
{
@@ -719,11 +740,17 @@ resource "google_compute_region_instance_group_manager" "igm-update" {
719740
}
720741

721742
instance_lifecycle_policy {
743+
{{- if ne $.TargetVersionName "ga" }}
744+
force_update_on_repair = "NO"
745+
{{- else }}
722746
force_update_on_repair = "YES"
747+
{{- end }}
748+
723749
default_action_on_failure = "DO_NOTHING"
724-
{{- if ne $.TargetVersionName "ga" }}
750+
751+
{{- if ne $.TargetVersionName "ga" }}
725752
on_failed_health_check = "DO_NOTHING"
726-
{{- end }}
753+
{{- end }}
727754
}
728755
}
729756
`, template, target, igm)
@@ -808,6 +835,9 @@ resource "google_compute_region_instance_group_manager" "igm-update" {
808835
region = "us-central1"
809836
target_size = 3
810837
list_managed_instances_results = "PAGINATED"
838+
839+
distribution_policy_target_shape = "ANY"
840+
811841
named_port {
812842
name = "customhttp"
813843
port = 8080
@@ -827,11 +857,23 @@ resource "google_compute_region_instance_group_manager" "igm-update" {
827857
}
828858

829859
instance_lifecycle_policy {
830-
force_update_on_repair = "NO"
831860
default_action_on_failure = "REPAIR"
832-
{{- if ne $.TargetVersionName "ga" }}
861+
862+
{{- if ne $.TargetVersionName "ga" }}
833863
on_failed_health_check = "REPAIR"
834-
{{- end }}
864+
{{- end }}
865+
866+
{{- if ne $.TargetVersionName "ga" }}
867+
force_update_on_repair = "YES"
868+
{{- else }}
869+
force_update_on_repair = "NO"
870+
{{- end }}
871+
872+
{{- if ne $.TargetVersionName "ga" }}
873+
on_repair {
874+
allow_changing_zone = "YES"
875+
}
876+
{{- end }}
835877

836878
}
837879
}

mmv1/third_party/terraform/website/docs/r/compute_instance_group_manager.html.markdown

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,27 @@ instance_lifecycle_policy {
304304
force_update_on_repair = "YES"
305305
default_action_on_failure = "DO_NOTHING"
306306
on_failed_health_check = "DO_NOTHING" //google-beta only
307+
on_repair { //google-beta only
308+
allow_changing_zone = "YES"
309+
}
307310
}
308311
```
309312

310313
* `force_update_on_repair` - (Optional), Specifies whether to apply the group's latest configuration when repairing a VM. Valid options are: `YES`, `NO`. If `YES` and you updated the group's instance template or per-instance configurations after the VM was created, then these changes are applied when VM is repaired. If `NO` (default), then updates are applied in accordance with the group's update policy type.
311314
* `default_action_on_failure` - (Optional), Specifies the action that a MIG performs on a failed VM. If the value of the `on_failed_health_check` field is `DEFAULT_ACTION`, then the same action also applies to the VMs on which your application fails a health check. Valid options are: `DO_NOTHING`, `REPAIR`. If `DO_NOTHING`, then MIG does not repair a failed VM. If `REPAIR` (default), then MIG automatically repairs a failed VM by recreating it. For more information, see about repairing VMs in a MIG.
312315
* `on_failed_health_check` - (Optional, Beta), Specifies the action that a MIG performs on an unhealthy VM. A VM is marked as unhealthy when the application running on that VM fails a health check. Valid options are: `DEFAULT_ACTION`, `DO_NOTHING`, `REPAIR`. If `DEFAULT_ACTION` (default), then MIG uses the same action configured for the `default_action_on_failure` field. If `DO_NOTHING`, then MIG does not repair unhealthy VM. If `REPAIR`, then MIG automatically repairs an unhealthy VM by recreating it. For more information, see about repairing VMs in a MIG.
316+
* `on_repair` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)), Configuration for VM repairs in the MIG. Structure is [documented below](#nested_on_repair).
317+
- - -
318+
319+
<a name="nested_on_repair"></a>The `on_repair` block supports:
320+
321+
```hcl
322+
on_repair {
323+
allow_changing_zone = "NO"
324+
}
325+
```
326+
327+
* `allow_changing_zone` - (Optional), Specifies whether the MIG can change a VM's zone during a repair. If "YES", MIG can select a different zone for the VM during a repair. Else if "NO", MIG cannot change a VM's zone during a repair. The default value of allow_changing_zone is "NO".
313328

314329
- - -
315330

mmv1/third_party/terraform/website/docs/r/compute_region_instance_group_manager.html.markdown

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,27 @@ instance_lifecycle_policy {
256256
force_update_on_repair = "YES"
257257
default_action_on_failure = "DO_NOTHING"
258258
on_failed_health_check = "DO_NOTHING" //google-beta only
259-
259+
on_repair { //google-beta only
260+
allow_changing_zone = "YES"
261+
}
260262
}
261263
```
262264

263265
* `force_update_on_repair` - (Optional), Specifies whether to apply the group's latest configuration when repairing a VM. Valid options are: `YES`, `NO`. If `YES` and you updated the group's instance template or per-instance configurations after the VM was created, then these changes are applied when VM is repaired. If `NO` (default), then updates are applied in accordance with the group's update policy type.
264266
* `default_action_on_failure` - (Optional), Specifies the action that a MIG performs on a failed VM. If the value of the `on_failed_health_check` field is `DEFAULT_ACTION`, then the same action also applies to the VMs on which your application fails a health check. Valid options are: `DO_NOTHING`, `REPAIR`. If `DO_NOTHING`, then MIG does not repair a failed VM. If `REPAIR` (default), then MIG automatically repairs a failed VM by recreating it. For more information, see about repairing VMs in a MIG.
265267
* `on_failed_health_check` - (Optional, Beta), Specifies the action that a MIG performs on an unhealthy VM. A VM is marked as unhealthy when the application running on that VM fails a health check. Valid options are: `DEFAULT_ACTION`, `DO_NOTHING`, `REPAIR`. If `DEFAULT_ACTION` (default), then MIG uses the same action configured for the `default_action_on_failure` field. If `DO_NOTHING`, then MIG does not repair unhealthy VM. If `REPAIR`, then MIG automatically repairs an unhealthy VM by recreating it. For more information, see about repairing VMs in a MIG.
268+
* `on_repair` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)), Configuration for VM repairs in the MIG. Structure is [documented below](#nested_on_repair).
269+
- - -
270+
271+
<a name="nested_on_repair"></a>The `on_repair` block supports:
272+
273+
```hcl
274+
on_repair {
275+
allow_changing_zone = "YES"
276+
}
277+
```
278+
279+
* `allow_changing_zone` - (Optional), Specifies whether the MIG can change a VM's zone during a repair. If "YES", MIG can select a different zone for the VM during a repair. Else if "NO", MIG cannot change a VM's zone during a repair. The default value of allow_changing_zone is "NO".
266280

267281
- - -
268282
<a name="nested_instance_flexibility_policy"></a>The `instance_flexibility_policy` block supports:

0 commit comments

Comments
 (0)