Repair a VM in an alternate zone

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:

Before you begin

Allow repairs in an alternate zone

To allow a MIG to repair a VM in an alternate zone, select one of the followingoptions:

Console

  1. In the Google Cloud console, go to theInstance groups page.

    Go to Instance groups

  2. If you already have a MIG, do the following:

    1. Click the name of the MIG.
    2. ClickEdit.
  3. If you don't have a MIG yet, do the following:

    1. ClickCreate instance group.
    2. Enter aName.
    3. Select anInstance template.
    4. In theLocation section, selectMultiple zones, and thenselect a region and zones.
    5. 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.

  4. In theVM instance lifecycle section, make sure that the followingfields are set as follows:

    1. TheDefault action on failure list is set toRepair instance.

    2. TheUpdates during VM instance repair is set toUpdate the instance configuration.

    3. In theChange zone during VM instance repair section, select theAllow repair of VMs in an alternate zone checkbox.

  5. For the other settings, you can either use the default values or modifythe fields.

  6. 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
  • 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 eitherbalanced orany.
  • 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
  • SIZE: the target size of the MIG.
  • SHAPE: the target distribution shape. This valuecan be eitherBALANCED orANY.

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

  1. In the Google Cloud console, go to theInstance groups page.

    Go to Instance groups

  2. Click the name of the MIG.

  3. ClickEdit.

  4. Go to theVM instance lifecycle section.

  5. In theChange zone during VM instance repair section, clear theAllow repair of VMs in an alternate zone checkbox.

  6. 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

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.