Add instance flexibility

This document describes how to add instance flexibility that lets you setmultiple machine types in a MIG.

You can add instance flexibility when creating a MIG or by editing an existingMIG. To add the flexibility, configure an instance flexibility policy in theMIG. The policy overrides the machine type specified in the instance template.Each time the MIG creates a virtual machine (VM) instance, it automaticallyselects one of the machine types you've listed in the policy based on resourceavailability. You can also assign ranks to the lists of machine types toindicate your preference.

To know how instance flexibility works in a MIG, seeAbout instance flexibility.

Before you begin

Create a MIG with instance flexibility

Before creating a MIG, you must firstcreate an instance template,if you don't already have one. You can then create a MIG with instanceflexibility to override the machine type specified in the instance template.

Create a MIG with instance flexibility in one of the following ways:

Create a MIG with multiple machine types

Console

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

    Go to Instance groups

  2. ClickCreate instance group.

  3. In theName field, enter a name for the MIG.

  4. In theInstance template list, select the instance template that youwant to use for the MIG.

  5. Before you can specify theNumber of instances and addInstance selections, you need to do the following:

    1. Go to theLocation section on the page and set a location as follows:

      1. SelectMultiple zones.

      2. In theRegions and theZones drop-downs, select a region andthe zones in which you want to create the VMs in the MIG. If youselected a regional instance template, then the region of thattemplate is selected by default.

      3. In theTarget distribution shape field, selectBalanced,Any, orAny single zone.

        • If you selectBalanced orAny single zone, then in thedialog that opens, clickDisable instance redistribution.

        • If you selectAny, then make sure that theAllow instance redistribution checkbox is not selected.

    2. Go to theAutoscaling section on the page and delete the autoscalingconfiguration as follows:

      1. In theAutoscaling mode drop-down, clickDelete autoscalingconfiguration.

      2. In the dialog that opens, clickDelete.

    3. Scroll back to theNumber of instances field.

  6. In theNumber of instances field, specify the number of VMs that youwant in the group.

  7. In theInstance selections section, clickAdd selections.

    TheInstance selections window opens.

    1. ClickAdd instance selection.

    2. In theNew instance selection section, do the following:

      1. In theName field, enter a name for the instance selection.

      2. In theMachine types section, clickAdd machine type, selecta machine type that you want to add in the instance selection, andthen clickDone.

        Repeat this step for each machine type that you want to add to theinstance selection.

      3. After you add the machine types to the instance selection, clickDone.

  8. In theInstance selections window, clickDone.

  9. Leave the other fields in their default settings or modify as needed.

  10. ClickCreate.

gcloud

To create a regional MIG with multiple machine types, use theinstance-groups managed create commandas follows:

gcloud compute instance-groups managed createINSTANCE_GROUP_NAME \    --regionREGION \    --sizeTARGET_SIZE \    --templateINSTANCE_TEMPLATE_URL \    --target-distribution-shapeSHAPE \    --instance-redistribution-type none \    --instance-selection-machine-typesMACHINE_TYPE,MACHINE_TYPE,...

Zonal MIGs don't support instance flexibility. However, if you want to createa MIG in a single zone, set the target distribution shape toany-single-zone. Furthermore, if you want a specific zone, use theany-single-zone distribution shape and include the--zonesZONE flag.

Replace the following:

  • INSTANCE_GROUP_NAME: the name of the MIG.
  • REGION: the region where you want to create the MIG.
  • TARGET_SIZE: the number of VMs you want the MIG tocreate and maintain.
  • 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
  • SHAPE: the target distribution shape. The value canbebalanced,any, orany-single-zone.
  • MACHINE_TYPE: the machine types that you wantto configure in the MIG—for example,n1-standard-16,n2-standard-16,e2-standard-16.

Terraform

If you haven't already created an instance template, which specifies theVM properties that you want for each VM in your MIG,create an instance template.

To create a regional MIG with multiple machine types, use thegoogle_compute_region_instance_group_manager resource.

resource "google_compute_region_instance_group_manager" "default" {  name               = "flex-igm"  base_instance_name = "tf-test-flex-igm"  region             = "us-central1"  target_size                      = 3  distribution_policy_target_shape = "ANY_SINGLE_ZONE"  version {    instance_template = google_compute_instance_template.default.id  }  instance_flexibility_policy {    instance_selections {      name          = "default-instance-selection"      machine_types = ["n1-standard-16", "n2-standard-16", "e2-standard-16"]    }  }  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 create a regional MIG with multiple machine types, make aPOST request totheregionInstanceGroupManagers.insert method.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers{  "name": "INSTANCE_GROUP_NAME",  "targetSize":TARGET_SIZE,  "instanceTemplate": "INSTANCE_TEMPLATE_URL",  "distributionPolicy": {    "targetShape": "SHAPE"  },  "updatePolicy": {    "instanceRedistributionType": "NONE"  },  "instanceFlexibilityPolicy": {    "instanceSelections": {      "INSTANCE_SELECTION": {        "machineTypes": [          "MACHINE_TYPE_1",          "MACHINE_TYPE_2",          ...        ]      }    }  }}

Zonal MIGs don't support instance flexibility. However, if you want to createa MIG in a single zone, set the target distribution shape toANY_SINGLE_ZONE. Furthermore, if you want a specific zone, use theANY_SINGLE_ZONE distribution shape and include thedistributionPolicy.zones[].zone field in the request.

Replace the following:

  • PROJECT_ID: yourproject ID.
  • REGION: the region where you want to create the MIG.
  • INSTANCE_GROUP_NAME: the name of the MIG.
  • TARGET_SIZE: the number of VMs you want the MIG tocreate and maintain.
  • 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
  • SHAPE: the target distribution shape. The value canbeBALANCED,ANY, orANY_SINGLE_ZONE.
  • INSTANCE_SELECTION: the name for the list ofmachine types.
  • MACHINE_TYPE: the machine types that you wantto configure in the MIG—for example,"n1-standard-16","n2-standard-16","e2-standard-16".

Create a MIG with multiple machine types and preferences

Console

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

    Go to Instance groups

  2. ClickCreate instance group.

  3. In theName field, enter a name for the MIG.

  4. In theInstance template list, select the instance template that youwant to use for the MIG.

  5. Before you can specify theNumber of instances and addInstance selections, you need to do the following:

    1. Go to theLocation section on the page and set a location as follows:

      1. SelectMultiple zones.

      2. In theRegions and theZones drop-downs, select a region andthe zones in which you want to create the VMs in the MIG. If youselected a regional instance template, then the region of thattemplate is selected by default.

      3. In theTarget distribution shape field, selectBalanced,Any, orAny single zone.

        • If you selectBalanced orAny single zone, then in thedialog that opens, clickDisable instance redistribution.

        • If you selectAny, then make sure that theAllow instance redistribution checkbox is not selected.

    2. Go to theAutoscaling section on the page and delete the autoscalingconfiguration as follows:

      1. In theAutoscaling mode drop-down, clickDelete autoscalingconfiguration.

      2. In the dialog that opens, clickDelete.

    3. Scroll back to theNumber of instances field.

  6. In theNumber of instances field, specify the number of VMs that youwant in the group.

  7. In theInstance selections section, clickAdd selections.

    TheInstance selections window opens.Repeat the following steps foreach instance selection that you want to add in the MIG.

    1. ClickAdd instance selection.

    2. In theNew instance selection section, do the following:

      1. In theName field, enter a name for the instance selection.

      2. In theRank field, enter the order of preference among theinstance selections that you add for the MIG.

      3. In theMachine types section, clickAdd machine type, selecta machine type that you want to add in the instance selection, andthen clickDone.

        Repeat this step for each machine type that you want to add to theinstance selection.

      4. After you add the machine types to the instance selection, clickDone.

  8. After you complete adding the instance selections, clickDone.

  9. Leave the other fields in their default settings or modify as needed.

  10. ClickCreate.

gcloud

To create a regional MIG with multiple machine types and preferences, use theinstance-groups managed create command.

gcloud compute instance-groups managed createINSTANCE_GROUP_NAME \    --regionREGION \    --sizeTARGET_SIZE \    --templateINSTANCE_TEMPLATE_URL \    --target-distribution-shapeSHAPE \    --instance-redistribution-type none \    --instance-selection "name=INSTANCE_SELECTION_1,machine-type=MACHINE_TYPE_1,machine-type=MACHINE_TYPE_2,rank=RANK_1" \    --instance-selection "name=INSTANCE_SELECTION_2,machine-type=MACHINE_TYPE_3,machine-type=MACHINE_TYPE_4,rank=RANK_2"

Zonal MIGs don't support instance flexibility. However, if you want to createa MIG in a single zone, set the target distribution shape toany-single-zone. Furthermore, if you want a specific zone, use theany-single-zone distribution shape and include the--zonesZONE flag.

Replace the following:

  • INSTANCE_GROUP_NAME: the name of the MIG.
  • REGION: the region where you want to create the MIG.
  • TARGET_SIZE: the number of VMs that you want the MIG to create and maintain.
  • 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
  • SHAPE: the target distribution shape. The value can bebalanced,any, orany-single-zone. The other target distribution shapes are not supported.
  • INSTANCE_SELECTION: the name of the list of machine types.
  • MACHINE_TYPE: the machine types that you want to configure in the MIG.
  • RANK: a number representing your order of preference for instance selection. A lower value means a higher preference.

Terraform

If you haven't already created an instance template, which specifies theVM properties that you want for each VM in your MIG,create an instance template.

To create a regional MIG with multiple machine types and preferences, usethegoogle_compute_region_instance_group_manager resource.

resource "google_compute_region_instance_group_manager" "default" {  name               = "flex-igm"  base_instance_name = "tf-test-flex-igm"  region             = "us-central1"  target_size                      = 3  distribution_policy_target_shape = "ANY_SINGLE_ZONE"  version {    instance_template = google_compute_instance_template.default.id  }  instance_flexibility_policy {    instance_selections {      name          = "best-choice"      rank          = 1      machine_types = ["n1-standard-1", "n1-standard-2"]    }    instance_selections {      name          = "still-ok"      rank          = 2      machine_types = ["n2-standard-1"]    }    instance_selections {      name          = "if-nothing-else"      rank          = 3      machine_types = ["e2-standard-2"]    }  }  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 create a regional MIG with multiple machine types and preferences, make aPOST request to theregionInstanceGroupManagers.insert method.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers{  "name": "INSTANCE_GROUP_NAME",  "targetSize":TARGET_SIZE,  "instanceTemplate": "INSTANCE_TEMPLATE_URL",  "distributionPolicy": {    "targetShape": "SHAPE"  },  "updatePolicy": {    "instanceRedistributionType": "NONE"  },  "instanceFlexibilityPolicy": {    "instanceSelections": {      "INSTANCE_SELECTION_1": {        "machineTypes": [          "MACHINE_TYPE_1",          "MACHINE_TYPE_2",          ...        ],        "rank":RANK_1      },      "INSTANCE_SELECTION_2": {        "machineTypes": [          "MACHINE_TYPE_3",          "MACHINE_TYPE_4",          ...        ],        "rank":RANK_2      },      ...    }  }}

Zonal MIGs don't support instance flexibility. However, if you want to createa MIG in a single zone, set the target distribution shape toANY_SINGLE_ZONE. Furthermore, if you want a specific zone, use theANY_SINGLE_ZONE distribution shape and include thedistributionPolicy.zones[].zone field in the request.

Replace the following:

  • PROJECT_ID: yourproject ID.
  • REGION: the region where you want to create the MIG.
  • INSTANCE_GROUP_NAME: the name of the MIG.
  • TARGET_SIZE: the number of VMs that you want the MIG to create and maintain.
  • 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
  • SHAPE: the target distribution shape. The value can beBALANCED,ANY, orANY_SINGLE_ZONE. The other target distribution shapes are not supported.
  • INSTANCE_SELECTION: the name of the list of machine types.
  • MACHINE_TYPE: the machine types that you want to configure in the MIG.
  • RANK: a number representing your order of preference for instance selection. A lower value means a higher preference.

Add instance flexibility to an existing MIG

You can add instance flexibility to an existing MIG. You can set multiplemachine types and also set preferences for certain machine types.

If your MIG already has VMs in it, those VMs continue to use the machine typespecified in the instance template. If you want the existing VMs in the MIG touse the machine types from the instance flexibility policy, then, after you addthe policy,deletethe existing VMs and thenresize the MIGto the required number of VMs. When resizing, the new VMs will use the machinetypes from the policy.

If you want to add an instance selection to an existing instance flexibilitypolicy, seeChange instance flexibility configuration.

Add instance flexibility to a MIG in one of the following ways:

Add multiple machine types

Console

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

    Go to Instance groups

  2. Click the name of the MIG in which you want to set multiple machine types.

  3. ClickEdit.

  4. ClickInstance flexibility to expand the section.

  5. In theInstance selections section, clickAdd selections.

    TheInstance selections window opens.

    1. ClickAdd instance selection.

    2. In theNew instance selection section, do the following:

      1. In theName field, enter a name for the instance selection.

      2. In theMachine types section, clickAdd machine type, selecta machine type that you want to add in the instance selection, andthen clickDone.

        Repeat this step for each machine type that you want to add to theinstance selection.

      3. After you add the machine types to the instance selection, clickDone.

  6. In theInstance selections window, clickDone.

  7. ClickSave.

gcloud

To add multiple machine types to an existing MIG, use theinstance-groups managed update command.

gcloud compute instance-groups managed updateINSTANCE_GROUP_NAME \    --regionREGION \    --instance-selection-machine-typesMACHINE_TYPE,MACHINE_TYPE,...

Replace the following:

  • INSTANCE_GROUP_NAME: the name of the MIG.
  • REGION: the region where the MIG is located.
  • MACHINE_TYPE: the machine types that you want to configure in the MIG.

REST

To add multiple machine types to an existing MIG, make aPATCH request totheregionInstanceGroupManagers.patch method.

PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME{  "instanceFlexibilityPolicy": {    "instanceSelections": {    "INSTANCE_SELECTION": {        "machineTypes": [          "MACHINE_TYPE_1",          "MACHINE_TYPE_2"          ...        ]      }    }  }}

Replace the following:

  • PROJECT_ID: yourproject ID.
  • REGION: the region where the MIG is located.
  • INSTANCE_GROUP_NAME: the name of the MIG.
  • INSTANCE_SELECTION: the name of the list of machine types.
  • MACHINE_TYPE: the machine types that you want to configure in the MIG.
  • RANK: a number representing your order of preference for instance selection. A lower value means a higher preference.

Add multiple machine types and preferences

Console

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

    Go to Instance groups

  2. Click the name of the MIG in which you want to set multiple machine types.

  3. ClickEdit.

  4. ClickInstance flexibility to expand the section.

  5. In theInstance selections section, clickAdd selections.

    TheInstance selections window opens.Repeat the following steps foreach instance selection that you want to add in the MIG.

    1. ClickAdd instance selection.

    2. In theNew instance selection section, do the following:

      1. In theName field, enter a name for the instance selection.

      2. In theRank field, enter the order of preference among theinstance selections that you add for the MIG.

      3. In theMachine types section, clickAdd machine type, selecta machine type that you want to add in the instance selection, andthen clickDone.

        Repeat this step for each machine type that you want to add to theinstance selection.

      4. After you add the machine types to the instance selection, clickDone.

  6. After you complete adding the instance selections, clickDone.

  7. ClickSave.

gcloud

To add multiple machine types and preferences to an existing MIG, use theinstance-groups managed update command

gcloud compute instance-groups managed updateINSTANCE_GROUP_NAME \    --regionREGION \    --instance-selection "name=INSTANCE_SELECTION_1,machine-type=MACHINE_TYPE_1,machine-type=MACHINE_TYPE_2,rank=RANK_1" \    --instance-selection "name=INSTANCE_SELECTION_2,machine-type=MACHINE_TYPE_3,machine-type=MACHINE_TYPE_4,rank=RANK_2"

Replace the following:

  • INSTANCE_GROUP_NAME: the name of the MIG.
  • REGION: the region where the MIG is located.
  • INSTANCE_SELECTION: the name of the list of machine types.
  • MACHINE_TYPE: the machine types that you want to configure in the MIG.
  • RANK: a number representing your order of preference for instance selection. A lower value means a higher preference.

REST

To add multiple machine types and preferences to an existing MIG, make aPATCH request to theregionInstanceGroupManagers.patch method.

PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME{  "instanceFlexibilityPolicy": {    "instanceSelections": {      "INSTANCE_SELECTION_1": {        "machineTypes": [          "MACHINE_TYPE_1",          "MACHINE_TYPE_2"        ],        "rank":RANK_1      },      "INSTANCE_SELECTION_2": {        "machineTypes": [          "MACHINE_TYPE_3",          "MACHINE_TYPE_4"        ],        "rank":RANK_2      }    }  }}

Replace the following:

  • PROJECT_ID: yourproject ID.
  • REGION: the region where the MIG is located.
  • INSTANCE_GROUP_NAME: the name of the MIG.
  • INSTANCE_SELECTION: the name of the list of machine types.
  • MACHINE_TYPE: the machine types that you want to configure in the MIG.
  • RANK: a number representing your order of preference for instance selection. A lower value means a higher preference.

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-16 UTC.