Skip to content

Commit a2f013f

Browse files
Adds support for Graceful Updater in Compute Managed Instance Groups. (#5975) (#11640)
* Support new features of IGM.updatePolicy (#4956) * Add new IGM.UpdatePolicy features - minimal_action=REFRESH and most_disruptive_allowed_action * Fix documentation of most_disruptive_allowed_action * Make most_disruptive_allowed_action an Optional field. * Fix RMIG UpdatePolicy flattening. * Fix most_disruptive_allowed_action documentation - new field is Optional. * Fix most_disruptive_allowed_action documentation - and improve testing. * Fix whitespaces in test. Co-authored-by: Grzegorz Sancewicz <[email protected]> * Always send minimal_action and most_disruptive_allowed_action with IGM.UpdatePolicy. * Make minimal_action optional and send null values instead of empty strings * Remove unnecesary appending to ForceSendFields array * Fix documentation for minimal_action - field is no longer required. * Revert making minimal_action optional. Co-authored-by: Kamil Hajduczenia <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Kamil Hajduczenia <[email protected]>
1 parent cb31755 commit a2f013f

7 files changed

+71
-29
lines changed

.changelog/5975.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```release-note:enhancement
2+
compute: added field `update_policy.most_disruptive_allowed_action` to `google_compute_instance_group_manager` and `google_compute_region_instance_group_manager`
3+
```
4+
```release-note:enhancement
5+
compute: added value `REFRESH` to field update_policy.minimal_action` in `google_compute_instance_group_manager` and `google_compute_region_instance_group_manager`
6+
```

google/resource_compute_instance_group_manager.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,15 @@ func resourceComputeInstanceGroupManager() *schema.Resource {
201201
"minimal_action": {
202202
Type: schema.TypeString,
203203
Required: true,
204-
ValidateFunc: validation.StringInSlice([]string{"RESTART", "REPLACE"}, false),
205-
Description: `Minimal action to be taken on an instance. You can specify either RESTART to restart existing instances or REPLACE to delete and create new instances from the target template. If you specify a RESTART, the Updater will attempt to perform that action only. However, if the Updater determines that the minimal action you specify is not enough to perform the update, it might perform a more disruptive action.`,
204+
ValidateFunc: validation.StringInSlice([]string{"REFRESH", "RESTART", "REPLACE"}, false),
205+
Description: `Minimal action to be taken on an instance. You can specify either REFRESH to update without stopping instances, RESTART to restart existing instances or REPLACE to delete and create new instances from the target template. If you specify a REFRESH, the Updater will attempt to perform that action only. However, if the Updater determines that the minimal action you specify is not enough to perform the update, it might perform a more disruptive action.`,
206+
},
207+
208+
"most_disruptive_allowed_action": {
209+
Type: schema.TypeString,
210+
Optional: true,
211+
ValidateFunc: validation.StringInSlice([]string{"NONE", "REFRESH", "RESTART", "REPLACE"}, false),
212+
Description: `Most disruptive action that is allowed to be taken on an instance. You can specify either NONE to forbid any actions, REFRESH to allow actions that do not need instance restart, RESTART to allow actions that can be applied without instance replacing or REPLACE to allow all possible actions. If the Updater determines that the minimal update action needed is more disruptive than most disruptive allowed action you specify it will not perform the update at all.`,
206213
},
207214

208215
"type": {
@@ -906,6 +913,12 @@ func expandUpdatePolicy(configured []interface{}) *compute.InstanceGroupManagerU
906913
data := raw.(map[string]interface{})
907914

908915
updatePolicy.MinimalAction = data["minimal_action"].(string)
916+
mostDisruptiveAllowedAction := data["most_disruptive_allowed_action"].(string)
917+
if mostDisruptiveAllowedAction != "" {
918+
updatePolicy.MostDisruptiveAllowedAction = mostDisruptiveAllowedAction
919+
} else {
920+
updatePolicy.NullFields = append(updatePolicy.NullFields, "MostDisruptiveAllowedAction")
921+
}
909922
updatePolicy.Type = data["type"].(string)
910923
updatePolicy.ReplacementMethod = data["replacement_method"].(string)
911924

@@ -990,6 +1003,7 @@ func flattenUpdatePolicy(updatePolicy *compute.InstanceGroupManagerUpdatePolicy)
9901003
up["max_unavailable_percent"] = 0
9911004
}
9921005
up["minimal_action"] = updatePolicy.MinimalAction
1006+
up["most_disruptive_allowed_action"] = updatePolicy.MostDisruptiveAllowedAction
9931007
up["type"] = updatePolicy.Type
9941008
up["replacement_method"] = updatePolicy.ReplacementMethod
9951009
results = append(results, up)

google/resource_compute_instance_group_manager_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -932,10 +932,11 @@ resource "google_compute_instance_group_manager" "igm-rolling-update-policy" {
932932
zone = "us-central1-c"
933933
target_size = 3
934934
update_policy {
935-
type = "PROACTIVE"
936-
minimal_action = "REPLACE"
937-
max_surge_fixed = 2
938-
max_unavailable_fixed = 2
935+
type = "PROACTIVE"
936+
minimal_action = "REPLACE"
937+
most_disruptive_allowed_action = "REPLACE"
938+
max_surge_fixed = 2
939+
max_unavailable_fixed = 2
939940
}
940941
named_port {
941942
name = "customhttp"

google/resource_compute_region_instance_group_manager.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,15 @@ func resourceComputeRegionInstanceGroupManager() *schema.Resource {
239239
"minimal_action": {
240240
Type: schema.TypeString,
241241
Required: true,
242-
ValidateFunc: validation.StringInSlice([]string{"RESTART", "REPLACE"}, false),
243-
Description: `Minimal action to be taken on an instance. You can specify either RESTART to restart existing instances or REPLACE to delete and create new instances from the target template. If you specify a RESTART, the Updater will attempt to perform that action only. However, if the Updater determines that the minimal action you specify is not enough to perform the update, it might perform a more disruptive action.`,
242+
ValidateFunc: validation.StringInSlice([]string{"REFRESH", "RESTART", "REPLACE"}, false),
243+
Description: `Minimal action to be taken on an instance. You can specify either REFRESH to update without stopping instances, RESTART to restart existing instances or REPLACE to delete and create new instances from the target template. If you specify a REFRESH, the Updater will attempt to perform that action only. However, if the Updater determines that the minimal action you specify is not enough to perform the update, it might perform a more disruptive action.`,
244+
},
245+
246+
"most_disruptive_allowed_action": {
247+
Type: schema.TypeString,
248+
Optional: true,
249+
ValidateFunc: validation.StringInSlice([]string{"NONE", "REFRESH", "RESTART", "REPLACE"}, false),
250+
Description: `Most disruptive action that is allowed to be taken on an instance. You can specify either NONE to forbid any actions, REFRESH to allow actions that do not need instance restart, RESTART to allow actions that can be applied without instance replacing or REPLACE to allow all possible actions. If the Updater determines that the minimal update action needed is more disruptive than most disruptive allowed action you specify it will not perform the update at all.`,
244251
},
245252

246253
"type": {
@@ -762,6 +769,12 @@ func expandRegionUpdatePolicy(configured []interface{}) *compute.InstanceGroupMa
762769
data := raw.(map[string]interface{})
763770

764771
updatePolicy.MinimalAction = data["minimal_action"].(string)
772+
mostDisruptiveAllowedAction := data["most_disruptive_allowed_action"].(string)
773+
if mostDisruptiveAllowedAction != "" {
774+
updatePolicy.MostDisruptiveAllowedAction = mostDisruptiveAllowedAction
775+
} else {
776+
updatePolicy.NullFields = append(updatePolicy.NullFields, "MostDisruptiveAllowedAction")
777+
}
765778
updatePolicy.Type = data["type"].(string)
766779
updatePolicy.InstanceRedistributionType = data["instance_redistribution_type"].(string)
767780
updatePolicy.ReplacementMethod = data["replacement_method"].(string)
@@ -818,6 +831,7 @@ func flattenRegionUpdatePolicy(updatePolicy *compute.InstanceGroupManagerUpdateP
818831
up["max_unavailable_percent"] = 0
819832
}
820833
up["minimal_action"] = updatePolicy.MinimalAction
834+
up["most_disruptive_allowed_action"] = updatePolicy.MostDisruptiveAllowedAction
821835
up["type"] = updatePolicy.Type
822836
up["instance_redistribution_type"] = updatePolicy.InstanceRedistributionType
823837
up["replacement_method"] = updatePolicy.ReplacementMethod

google/resource_compute_region_instance_group_manager_test.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -1294,12 +1294,13 @@ resource "google_compute_region_instance_group_manager" "igm-rolling-update-poli
12941294
distribution_policy_zones = ["us-central1-a", "us-central1-f"]
12951295
target_size = 3
12961296
update_policy {
1297-
type = "PROACTIVE"
1298-
instance_redistribution_type = "NONE"
1299-
minimal_action = "REPLACE"
1300-
max_surge_fixed = 0
1301-
max_unavailable_fixed = 2
1302-
replacement_method = "RECREATE"
1297+
type = "PROACTIVE"
1298+
instance_redistribution_type = "NONE"
1299+
minimal_action = "REPLACE"
1300+
most_disruptive_allowed_action = "REPLACE"
1301+
max_surge_fixed = 0
1302+
max_unavailable_fixed = 2
1303+
replacement_method = "RECREATE"
13031304
}
13041305
named_port {
13051306
name = "customhttp"

website/docs/r/compute_instance_group_manager.html.markdown

+10-7
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,19 @@ group. You can specify only one value. Structure is [documented below](#nested_a
149149

150150
```hcl
151151
update_policy {
152-
type = "PROACTIVE"
153-
minimal_action = "REPLACE"
154-
max_surge_percent = 20
155-
max_unavailable_fixed = 2
156-
min_ready_sec = 50
157-
replacement_method = "RECREATE"
152+
type = "PROACTIVE"
153+
minimal_action = "REPLACE"
154+
most_disruptive_allowed_action = "REPLACE"
155+
max_surge_percent = 20
156+
max_unavailable_fixed = 2
157+
min_ready_sec = 50
158+
replacement_method = "RECREATE"
158159
}
159160
```
160161

161-
* `minimal_action` - (Required) - Minimal action to be taken on an instance. You can specify either `RESTART` to restart existing instances or `REPLACE` to delete and create new instances from the target template. If you specify a `RESTART`, the Updater will attempt to perform that action only. However, if the Updater determines that the minimal action you specify is not enough to perform the update, it might perform a more disruptive action.
162+
* `minimal_action` - (Required) - Minimal action to be taken on an instance. You can specify either `REFRESH` to update without stopping instances, `RESTART` to restart existing instances or `REPLACE` to delete and create new instances from the target template. If you specify a `REFRESH`, the Updater will attempt to perform that action only. However, if the Updater determines that the minimal action you specify is not enough to perform the update, it might perform a more disruptive action.
163+
164+
* `most_disruptive_allowed_action` - (Optional) - Most disruptive action that is allowed to be taken on an instance. You can specify either NONE to forbid any actions, REFRESH to allow actions that do not need instance restart, RESTART to allow actions that can be applied without instance replacing or REPLACE to allow all possible actions. If the Updater determines that the minimal update action needed is more disruptive than most disruptive allowed action you specify it will not perform the update at all.
162165

163166
* `type` - (Required) - The type of update process. You can specify either `PROACTIVE` so that the instance group manager proactively executes actions in order to bring instances to their target versions or `OPPORTUNISTIC` so that no action is proactively executed but the update will be performed as part of other actions (for example, resizes or recreateInstances calls).
164167

website/docs/r/compute_region_instance_group_manager.html.markdown

+11-8
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,20 @@ group. You can specify one or more values. For more information, see the [offici
158158

159159
```hcl
160160
update_policy {
161-
type = "PROACTIVE"
162-
instance_redistribution_type = "PROACTIVE"
163-
minimal_action = "REPLACE"
164-
max_surge_percent = 20
165-
max_unavailable_fixed = 2
166-
min_ready_sec = 50
167-
replacement_method = "RECREATE"
161+
type = "PROACTIVE"
162+
instance_redistribution_type = "PROACTIVE"
163+
minimal_action = "REPLACE"
164+
most_disruptive_allowed_action = "REPLACE"
165+
max_surge_percent = 20
166+
max_unavailable_fixed = 2
167+
min_ready_sec = 50
168+
replacement_method = "RECREATE"
168169
}
169170
```
170171

171-
* `minimal_action` - (Required) - Minimal action to be taken on an instance. You can specify either `RESTART` to restart existing instances or `REPLACE` to delete and create new instances from the target template. If you specify a `RESTART`, the Updater will attempt to perform that action only. However, if the Updater determines that the minimal action you specify is not enough to perform the update, it might perform a more disruptive action.
172+
* `minimal_action` - (Required) - Minimal action to be taken on an instance. You can specify either `REFRESH` to update without stopping instances, `RESTART` to restart existing instances or `REPLACE` to delete and create new instances from the target template. If you specify a `REFRESH`, the Updater will attempt to perform that action only. However, if the Updater determines that the minimal action you specify is not enough to perform the update, it might perform a more disruptive action.
173+
174+
* `most_disruptive_allowed_action` - (Optional) - Most disruptive action that is allowed to be taken on an instance. You can specify either NONE to forbid any actions, REFRESH to allow actions that do not need instance restart, RESTART to allow actions that can be applied without instance replacing or REPLACE to allow all possible actions. If the Updater determines that the minimal update action needed is more disruptive than most disruptive allowed action you specify it will not perform the update at all.
172175

173176
* `type` - (Required) - The type of update process. You can specify either `PROACTIVE` so that the instance group manager proactively executes actions in order to bring instances to their target versions or `OPPORTUNISTIC` so that no action is proactively executed but the update will be performed as part of other actions (for example, resizes or recreateInstances calls).
174177

0 commit comments

Comments
 (0)