Skip to content

Commit 0877c4f

Browse files
authored
Instance lifecycle policy default action on failure implementation (GoogleCloudPlatform#10050)
1 parent 2c4db32 commit 0877c4f

8 files changed

+51
-8
lines changed

mmv1/third_party/terraform/go.mod.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ require (
2727
github.com/sirupsen/logrus v1.8.1
2828
golang.org/x/net v0.21.0
2929
golang.org/x/oauth2 v0.17.0
30-
google.golang.org/api v0.166.0
30+
google.golang.org/api v0.167.0
3131
google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9
3232
google.golang.org/grpc v1.61.1
3333
google.golang.org/protobuf v1.32.0

mmv1/third_party/terraform/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
363363
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
364364
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
365365
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
366-
google.golang.org/api v0.166.0 h1:6m4NUwrZYhAaVIHZWxaKjw1L1vNAjtMwORmKRyEEo24=
367-
google.golang.org/api v0.166.0/go.mod h1:4FcBc686KFi7QI/U51/2GKKevfZMpM17sCdibqe/bSA=
366+
google.golang.org/api v0.167.0 h1:CKHrQD1BLRii6xdkatBDXyKzM0mkawt2QP+H3LtPmSE=
367+
google.golang.org/api v0.167.0/go.mod h1:4FcBc686KFi7QI/U51/2GKKevfZMpM17sCdibqe/bSA=
368368
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
369369
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
370370
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,13 @@ func ResourceComputeInstanceGroupManager() *schema.Resource {
305305
Description: `The instance lifecycle policy for this managed instance group.`,
306306
Elem: &schema.Resource{
307307
Schema: map[string]*schema.Schema{
308+
"default_action_on_failure": {
309+
Type: schema.TypeString,
310+
Default: "REPAIR",
311+
Optional: true,
312+
ValidateFunc: validation.StringInSlice([]string{"REPAIR", "DO_NOTHING"}, true),
313+
Description: `Default behavior for all instance or health check failures.`,
314+
},
308315
"force_update_on_repair": {
309316
Type: schema.TypeString,
310317
Default: "NO",
@@ -1188,6 +1195,7 @@ func expandInstanceLifecyclePolicy(configured []interface{}) *compute.InstanceGr
11881195
for _, raw := range configured {
11891196
data := raw.(map[string]interface{})
11901197
instanceLifecyclePolicy.ForceUpdateOnRepair = data["force_update_on_repair"].(string)
1198+
instanceLifecyclePolicy.DefaultActionOnFailure = data["default_action_on_failure"].(string)
11911199
}
11921200
return instanceLifecyclePolicy
11931201
}
@@ -1376,6 +1384,7 @@ func flattenInstanceLifecyclePolicy(instanceLifecyclePolicy *compute.InstanceGro
13761384
if instanceLifecyclePolicy != nil {
13771385
ilp := map[string]interface{}{}
13781386
ilp["force_update_on_repair"] = instanceLifecyclePolicy.ForceUpdateOnRepair
1387+
ilp["default_action_on_failure"] = instanceLifecyclePolicy.DefaultActionOnFailure
13791388
results = append(results, ilp)
13801389
}
13811390
return results

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ func TestAccInstanceGroupManager_update(t *testing.T) {
116116
Steps: []resource.TestStep{
117117
{
118118
Config: testAccInstanceGroupManager_update(template1, target1, description, igm),
119+
Check: resource.ComposeTestCheckFunc(
120+
resource.TestCheckResourceAttr("google_compute_instance_group_manager.igm-update", "instance_lifecycle_policy.0.default_action_on_failure", "DO_NOTHING"),
121+
),
119122
},
120123
{
121124
ResourceName: "google_compute_instance_group_manager.igm-update",
@@ -125,6 +128,9 @@ func TestAccInstanceGroupManager_update(t *testing.T) {
125128
},
126129
{
127130
Config: testAccInstanceGroupManager_update2(template1, target1, target2, template2, description, igm),
131+
Check: resource.ComposeTestCheckFunc(
132+
resource.TestCheckResourceAttr("google_compute_instance_group_manager.igm-update", "instance_lifecycle_policy.0.default_action_on_failure", "REPAIR"),
133+
),
128134
},
129135
{
130136
ResourceName: "google_compute_instance_group_manager.igm-update",
@@ -134,6 +140,9 @@ func TestAccInstanceGroupManager_update(t *testing.T) {
134140
},
135141
{
136142
Config: testAccInstanceGroupManager_update3(template1, target1, target2, template2, description2, igm),
143+
Check: resource.ComposeTestCheckFunc(
144+
resource.TestCheckResourceAttr("google_compute_instance_group_manager.igm-update", "instance_lifecycle_policy.0.default_action_on_failure", "REPAIR"),
145+
),
137146
},
138147
{
139148
ResourceName: "google_compute_instance_group_manager.igm-update",
@@ -671,6 +680,7 @@ resource "google_compute_instance_group_manager" "igm-update" {
671680

672681
instance_lifecycle_policy {
673682
force_update_on_repair = "YES"
683+
default_action_on_failure = "DO_NOTHING"
674684
}
675685
}
676686
`, template, target, description, igm)
@@ -775,6 +785,7 @@ resource "google_compute_instance_group_manager" "igm-update" {
775785

776786
instance_lifecycle_policy {
777787
force_update_on_repair = "NO"
788+
default_action_on_failure = "REPAIR"
778789
}
779790
}
780791
`, template1, target1, target2, template2, description, igm)
@@ -1786,6 +1797,7 @@ resource "google_compute_instance_group_manager" "igm-basic" {
17861797
}
17871798
instance_lifecycle_policy {
17881799
force_update_on_repair = "YES"
1800+
default_action_on_failure = "REPAIR"
17891801
}
17901802
wait_for_instances = true
17911803
wait_for_instances_status = "UPDATED"

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,13 @@ func ResourceComputeRegionInstanceGroupManager() *schema.Resource {
263263
Description: `The instance lifecycle policy for this managed instance group.`,
264264
Elem: &schema.Resource{
265265
Schema: map[string]*schema.Schema{
266+
"default_action_on_failure": {
267+
Type: schema.TypeString,
268+
Default: "REPAIR",
269+
Optional: true,
270+
ValidateFunc: validation.StringInSlice([]string{"REPAIR", "DO_NOTHING"}, true),
271+
Description: `Default behavior for all instance or health check failures.`,
272+
},
266273
"force_update_on_repair": {
267274
Type: schema.TypeString,
268275
Default: "NO",

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ func TestAccRegionInstanceGroupManager_update(t *testing.T) {
8383
Steps: []resource.TestStep{
8484
{
8585
Config: testAccRegionInstanceGroupManager_update(template1, target1, igm),
86+
Check: resource.ComposeTestCheckFunc(
87+
resource.TestCheckResourceAttr("google_compute_region_instance_group_manager.igm-update", "instance_lifecycle_policy.0.default_action_on_failure", "DO_NOTHING"),
88+
),
8689
},
8790
{
8891
ResourceName: "google_compute_region_instance_group_manager.igm-update",
@@ -92,6 +95,9 @@ func TestAccRegionInstanceGroupManager_update(t *testing.T) {
9295
},
9396
{
9497
Config: testAccRegionInstanceGroupManager_update2(template1, target1, target2, template2, igm),
98+
Check: resource.ComposeTestCheckFunc(
99+
resource.TestCheckResourceAttr("google_compute_region_instance_group_manager.igm-update", "instance_lifecycle_policy.0.default_action_on_failure", "REPAIR"),
100+
),
95101
},
96102
{
97103
ResourceName: "google_compute_region_instance_group_manager.igm-update",
@@ -101,6 +107,9 @@ func TestAccRegionInstanceGroupManager_update(t *testing.T) {
101107
},
102108
{
103109
Config: testAccRegionInstanceGroupManager_update3(template1, target1, target2, template2, igm),
110+
Check: resource.ComposeTestCheckFunc(
111+
resource.TestCheckResourceAttr("google_compute_region_instance_group_manager.igm-update", "instance_lifecycle_policy.0.default_action_on_failure", "REPAIR"),
112+
),
104113
},
105114
{
106115
ResourceName: "google_compute_region_instance_group_manager.igm-update",
@@ -573,6 +582,7 @@ resource "google_compute_region_instance_group_manager" "igm-update" {
573582

574583
instance_lifecycle_policy {
575584
force_update_on_repair = "YES"
585+
default_action_on_failure = "DO_NOTHING"
576586
}
577587
}
578588
`, template, target, igm)
@@ -677,6 +687,7 @@ resource "google_compute_region_instance_group_manager" "igm-update" {
677687

678688
instance_lifecycle_policy {
679689
force_update_on_repair = "NO"
690+
default_action_on_failure = "REPAIR"
680691
}
681692
}
682693
`, template1, target1, target2, template2, igm)

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,13 @@ update_policy {
205205

206206
```hcl
207207
instance_lifecycle_policy {
208-
force_update_on_repair = "YES"
208+
force_update_on_repair = "YES"
209+
default_action_on_failure = "DO_NOTHING"
209210
}
210211
```
211212

212-
* `force_update_on_repair` - (Optional, (https://terraform.io/docs/providers/google/guides/provider_versions.html)), 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.
213-
213+
* `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.
214+
* `default_action_on_failure` - (Optional), Default behavior for all instance or health check failures. Valid options are: `REPAIR`, `DO_NOTHING`. If `DO_NOTHING` then instances will not be repaired. If `REPAIR` (default), then failed instances will be repaired.
214215
- - -
215216

216217
<a name="nested_all_instances_config"></a>The `all_instances_config` block supports:

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,14 @@ update_policy {
215215

216216
```hcl
217217
instance_lifecycle_policy {
218-
force_update_on_repair = "YES"
218+
force_update_on_repair = "YES"
219+
default_action_on_failure = "DO_NOTHING"
219220
}
220221
```
221222

222-
* `force_update_on_repair` - (Optional, (https://terraform.io/docs/providers/google/guides/provider_versions.html)), 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.
223+
* `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.
224+
* `default_action_on_failure` - (Optional), Default behavior for all instance or health check failures. Valid options are: `REPAIR`, `DO_NOTHING`. If `DO_NOTHING` then instances will not be repaired. If `REPAIR` (default), then failed instances will be repaired.
225+
223226
- - -
224227

225228
<a name="nested_all_instances_config"></a>The `all_instances_config` block supports:

0 commit comments

Comments
 (0)