Repair a VM in an alternate zone Stay organized with collections Save and categorize content based on your preferences.
Preview
This feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of theService Specific Terms. Pre-GA features are available "as is" and might have limited support. For more information, see thelaunch stage descriptions.
This document describes how to allow a regional managed instance group (MIG) torepair a virtual machine (VM) instance in an alternate zone when the MIG cannotrepair the VM in its original zone. To learn more about repairs in a MIG, seeAbout repairing VMs for high availability.
When you create a regional MIG, you select one or more zones where the MIGdistributes its VMs. By default, if a VM in the MIG fails, the MIG tries torepair that VM in its original zone. You can optionally allow the MIG to repairthat VM in one of the other selected zones, which is useful in cases where theMIG cannot repair the VM in its original zone. The MIG picks the alternate zonebased on available capacity and quota.
Limitations
When you configure a regional MIG to repair a VM in alternate zone, thefollowing limitations apply:
You must enableupdate on repair.
Regional MIGs with the following configuration aren't supported:
MIGs with
EVENorANY_SINGLE_ZONEtarget distribution shapes.MIGs withstateful configuration.
Before you begin
- If you haven't already, set upauthentication. Authentication verifies your identity for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine by selecting one of the following options:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
Install the Google Cloud CLI. After installation,initialize the Google Cloud CLI by running the following command:
gcloudinit
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.- Set a default region and zone.
Terraform
To use the Terraform samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.For more information, seeAuthenticate for using REST in the Google Cloud authentication documentation.
Allow repairs in an alternate zone
To allow a MIG to repair a VM in an alternate zone, select one of the followingoptions:
Console
In the Google Cloud console, go to theInstance groups page.
If you already have a MIG, do the following:
- Click the name of the MIG.
- ClickEdit.
If you don't have a MIG yet, do the following:
- ClickCreate instance group.
- Enter aName.
- Select anInstance template.
- In theLocation section, selectMultiple zones, and thenselect a region and zones.
In theTarget distribution shape drop-down, selectBalancedorAny.
If you selectBalanced, in the dialog that appears, clickDisable instance redistribution.
If you want to selectAny, you must first delete theautoscaling configuration. To delete autoscaling, in theAutoscaling mode drop-down, clickDelete autoscalingconfiguration.
In theVM instance lifecycle section, make sure that the followingfields are set as follows:
TheDefault action on failure list is set toRepair instance.
TheUpdates during VM instance repair is set toUpdate the instance configuration.
In theChange zone during VM instance repair section, select theAllow repair of VMs in an alternate zone checkbox.
For the other settings, you can either use the default values or modifythe fields.
After you finish, clickSave for an existing MIG orCreate for anew MIG.
gcloud
To configure an existing MIG to repair VM in an alternate zone, use thebetaupdate command:
gcloud beta compute instance-groups managed updateMIG_NAME \ --on-repair-allow-changing-zone=YES \ --force-update-on-repair \ --region=REGION
To create a MIG that can repair VM in an alternate zone, use thebetacreate command:
gcloud beta compute instance-groups managed createMIG_NAME \ --template=INSTANCE_TEMPLATE_URL \ --size=SIZE \ --zones=ZONES \ --target-distribution-shape=SHAPE \ --instance-redistribution-type=none \ --on-repair-allow-changing-zone=YES \ --force-update-on-repair
Replace the following:
MIG_NAME: the name of the MIG.INSTANCE_TEMPLATE_URL: the URL of the instance template that you want touse to create VMs in the MIG. The URL can contain either theIDor name of the instance template. Specify one of the following values:- For a regional instance template:
projects/PROJECT_ID/regions/REGION/instanceTemplates/INSTANCE_TEMPLATE_ID - For a global instance template:
INSTANCE_TEMPLATE_ID
- For a regional instance template:
SIZE: the target size of the MIG.ZONES: the list of zones in a region whereyou want to create the VMs in the MIG.SHAPE: the target distribution shape. This valuecan be eitherbalancedorany.REGION: the region where the MIG is located.
Terraform
If you haven't already created an instance template, which specifies themachine type, boot disk image, network, and other VM properties that youwant for each VM in your MIG,create an instance template.
To create a MIG that can repair VM in an alternate zone, use thegoogle_compute_region_instance_group_manager resource.
resource "google_compute_region_instance_group_manager" "default" { provider = google-beta name = "example-rmig" base_instance_name = "example-rmig-instance" region = "us-central1" target_size = 3 distribution_policy_target_shape = "BALANCED" version { instance_template = google_compute_instance_template.default.id } instance_lifecycle_policy { default_action_on_failure = "REPAIR" force_update_on_repair = "YES" on_repair { allow_changing_zone = "YES" } } update_policy { instance_redistribution_type = "NONE" type = "OPPORTUNISTIC" minimal_action = "REPLACE" max_surge_fixed = 0 max_unavailable_fixed = 6 }}To learn how to apply or remove a Terraform configuration, seeBasic Terraform commands.
REST
To configure an existing MIG to repair VM in an alternate zone, use thebetaregionInstanceGroupManagers.patch method:
PATCH https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/MIG_NAME{ "instanceLifecyclePolicy": { "onRepair": { "allowChangingZone": "YES" }, "forceUpdateOnRepair": "YES" }}To create a MIG that can repair VM in an alternate zone, use thebetaregionInstanceGroupManagers.insert method:
POST https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/regions/REGION/instanceGroupManagers{ "name": "MIG_NAME", "instanceTemplate": "INSTANCE_TEMPLATE_URL", "targetSize":SIZE, "distributionPolicy": { "targetShape": "SHAPE" } "updatePolicy": { "instanceRedistributionType": none } "instanceLifecyclePolicy": { "forceUpdateOnRepair": "YES", "onRepair": { "allowChangingZone": "YES" } }}Replace the following:
PROJECT_ID: yourproject ID.REGION: the region where the MIG is located.MIG_NAME: the name of the MIG.INSTANCE_TEMPLATE_URL: the URL of the instance template that you want touse to create VMs in the MIG. The URL can contain either theIDor name of the instance template. Specify one of the following values:- For a regional instance template:
projects/PROJECT_ID/regions/REGION/instanceTemplates/INSTANCE_TEMPLATE_ID - For a global instance template:
INSTANCE_TEMPLATE_ID
- For a regional instance template:
SIZE: the target size of the MIG.SHAPE: the target distribution shape. This valuecan be eitherBALANCEDorANY.
Disallow repairs in an alternate zone
If you configured a MIG to repair VM in an alternate zone, then you can restorethe default setting in which the MIG repairs the VM in the original zone.
To disallow repairs in an alternate zone, select one of the following options:
Console
In the Google Cloud console, go to theInstance groups page.
Click the name of the MIG.
ClickEdit.
Go to theVM instance lifecycle section.
In theChange zone during VM instance repair section, clear theAllow repair of VMs in an alternate zone checkbox.
ClickSave.
gcloud
To disallow repairs in an alternate zone, use thebetaupdate command:
gcloud beta compute instance-groups managed updateMIG_NAME \ --on-repair-allow-changing-zone=NO \ --region=REGION
Replace the following:
MIG_NAME: the name of the MIG.REGION: the region where the MIG is located.
REST
To disallow repairs in an alternate zone, use thebetaregionInstanceGroupManagers.patch method:
PATCH https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/MIG_NAME{ "instanceLifecyclePolicy": { "onRepair": { "allowChangingZone": "NO" } }}Replace the following:
PROJECT_ID: yourproject ID.REGION: the region where the MIG is located.MIG_NAME: the name of the MIG.
What's next
- Check the repair configuration in a MIG
- Check the zone of a VM bylisting the managed instances
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.