Selectively apply VM configuration updates in a MIG

This document describes how to selectively apply configuration updates to thevirtual machine (VM) instances in amanaged instance group (MIG).

Compute Engine maintains the VMs in a MIG based on theconfiguration componentsthat you use: instance template, optional all-instances configuration, andoptional stateful configuration.

Whenever you update a MIG's VM configuration by changing those components,Compute Engine automatically applies your updated configuration to newVMs that are added to the group.

To apply an updated configuration to existing VMs, you can set up a selectiveupdate–also known as a "opportunistic" update type. This type of update offersthe following advantages:

  • You can select the VMs that you want to update.
  • You can control the timing and the sequence of the updates.
  • You can use the gcloud CLI or REST to update allVMs immediately.

Alternatively, if you want to automate the rollout of a new configuration toall or to a random subset of the VMs in a MIG, seeAutomatically apply VM configuration updates in a MIG.To help you decide, seeMethods to apply a new configuration to existing VMs.

Before you begin

Apply updated configuration to selected VMs

Ensure your group's update policy type is set to "opportunistic" to preventthe MIG from automatically applying new a VM configuration to existing VMs. Formore information, seeCheck your group's update policy type.

Then use the gcloud CLI or REST to update your MIG'sconfiguration and to apply the latest configuration to specific VMs in thegroup or to all VMs in the group.

Permissions required for this task

To perform this task, you must have the followingpermissions:

gcloud

To set up a new instance template for your group, you can use theset-instance-template command.

gcloud compute instance-groups managed set-instance-templateINSTANCE_GROUP_NAME \    --template=INSTANCE_TEMPLATE

Apply configuration to specific VMs

To apply the updated configuration to specific VMs, use theupdate-instances commandwith the--instances flag.

gcloud compute instance-groups managed update-instancesINSTANCE_GROUP_NAME \--instancesINSTANCE_NAMES \    --most-disruptive-allowed-actionDISRUPTION_LEVEL \    --minimal-actionDISRUPTION_LEVEL

Apply configuration to all VMs

To apply the updated configuration to all VMs, use theupdate-instances commandwith the--all-instances flag.

gcloud compute instance-groups managed update-instancesINSTANCE_GROUP_NAME \--all-instances \    --most-disruptive-allowed-actionDISRUPTION_LEVEL \    --minimal-actionDISRUPTION_LEVEL

Replace the following:

  • INSTANCE_GROUP_NAME: the name of the MIG
  • INSTANCE_TEMPLATE: new instance template
  • INSTANCE_NAMES: a list of VMs to apply thetemplate to
  • DISRUPTION_LEVEL: the minimal or maximaldisruption level:none,refresh,restart, orreplace
    • The default minimal action isnone
    • The default most disruptive allowed action isreplace

REST

To set up a new instance template for your group,call thepatch method on azonal orregionalMIG and update theversions.instanceTemplate field. To avoid automaticallyrolling out the new template to all VMs in the group, set theupdatePolicy.type field toOPPORTUNISTIC.

PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME{  "updatePolicy": {    "type": "OPPORTUNISTIC"  },  "versions": [{    "instanceTemplate": "global/instanceTemplates/NEW_TEMPLATE",  }]}

Apply configuration to specific VMs

To apply the updated configuration to specific VMs, call theapplyUpdatesToInstances method for yourzonalorregionalMIG and specify a list of VMs in the request.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME/applyUpdatesToInstances{"instances": [    "zones/ZONE/instances/INSTANCE_NAME_1",    "zones/ZONE/instances/INSTANCE_NAME_2"  ],  "minimalAction":DISRUPTION_LEVEL,  "mostDisruptiveAllowedAction":DISRUPTION_LEVEL}

Apply configuration to all VMs

To apply the updated configuration to all existing VMs, set theallInstances field totrue:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME/applyUpdatesToInstances{"allInstances": true,  "minimalAction":DISRUPTION_LEVEL,  "mostDisruptiveAllowedAction":DISRUPTION_LEVEL}

Replace the following:

  • INSTANCE_GROUP_NAME: the name of the group
  • NEW_TEMPLATE: the name of the new template
  • ZONE: the zone of an instance to update
  • INSTANCE_NAME_1 andINSTANCE_NAME_2: the names of the VMs toupdate
  • DISRUPTION_LEVEL: the minimal or maximaldisruption level:NONE,REFRESH,RESTART, orREPLACE
    • The defaultminimalAction isNONE.
    • The defaultmostDisruptiveAllowedAction isREPLACE.

Similar to other managed instance group methods,applyUpdatesToInstancesis intent-based, which means itreturns an operation response.The operation can take some time to complete.

After you make a request, you cancheck the statusto verify that the update is complete.

Control the disruption level during selective updates

Depending on the nature of an update, it might disrupt an instance'sstate. For example, changing aninstance's boot disk requires replacing the instance. You cancontrol the level of disruption during a selective update by setting thefollowing options:

  • Minimal action: Use this option to minimize disruption as much as possibleor to apply a more disruptive action than is necessary.

    • To limit disruption as much as possible, set the minimal action toNONE. If your update requires a more disruptive action,Compute Engine performs the necessary action to execute theupdate.
    • To apply a more disruptive action than is strictly necessary, set theminimal action toRESTART orREPLACE. For example,Compute Engine does not need to restart a VM to change itsmetadata. But if your application reads instance metadata only when a VMis restarted, you can set the minimal action toRESTART in order to pickup metadata changes.
  • Most disruptive allowed action: Use this option to prevent an update ifit requires more disruption than you can afford. If your update requires amore disruptive action than you set with this flag, the update request fails.For example, if you set the most disruptive allowed action toRESTART, thenan attempt to update the boot disk image fails because that update requiresinstance recreation, a more disruptive action than a restart.

When updating selected VMs, both of these options accept the followingvalues:

ValueDescriptionWhich instance properties can be updated?
NONEDon't disrupt the instance at all.None
REFRESHDon't stop the instance.Additional disks, Dynamic Network Interfaces (NICs), instance metadata, labels, tags
RESTARTStop the instance and start it again.Additional disks, Dynamic NICs, instance metadata, labels, tags, machine type
REPLACEDelete the instance and create it again.All instance properties stored in the instance template or per-instance configuration

The most disruptive allowed action can't be less disruptive than the minimalaction.

When you selectively update VMs, the following defaults apply:

  • The default minimal action isNONE, which limits disruption as much aspossible.
  • The default most disruptive allowed action isREPLACE. If you cannottolerate such disruption, set the most disruptive allowed action to be lessdisruptive.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.