Add instance flexibility
Stay organized with collections
Save and categorize content based on your preferences.
This document describes how to add instance flexibility that lets you set
multiple machine types in a MIG.
You can add instance flexibility when creating a MIG or by editing an existing
MIG. To add the flexibility, configure an instance flexibility policy in the
MIG. The policy overrides the machine type specified in the instance template.
Each time the MIG creates a virtual machine (VM) instance, it automatically
selects one of the machine types you've listed in the policy based on resource
availability. You can also assign ranks to the lists of machine types to
indicate your preference.
Make sure you choose machine types that are supported in the region
where your MIG is located. To see the machine types in a region, see Available regions and zones.
If you haven't already, set up authentication.
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:
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.
Before creating a MIG, you must first create an instance template,
if you don't already have one. You can then create a MIG with instance
flexibility to override the machine type specified in the instance template.
Create a MIG with instance flexibility in one of the following ways:
In the Instance template list, select the instance template that you
want to use for the MIG.
Before you can specify the Number of instances and add
Instance selections, you need to do the following:
Go to the Location section on the page and set a location as follows:
Select Multiple zones.
In the Regions and the Zones drop-downs, select a region and
the zones in which you want to create the VMs in the MIG. If you
selected a regional instance template, then the region of that
template is selected by default.
In the Target distribution shape field, select Balanced,
Any, or Any single zone.
If you select Balanced or Any single zone, then in the
dialog that opens, click Disable instance redistribution.
If you select Any, then make sure that the
Allow instance redistribution checkbox is not selected.
Go to the Autoscaling section on the page and delete the autoscaling
configuration as follows:
In the Autoscaling mode drop-down, click Delete autoscaling
configuration.
In the dialog that opens, click Delete.
Scroll back to the Number of instances field.
In the Number of instances field, specify the number of VMs that you
want in the group.
In the Instance selections section, click Add selections.
The Instance selections window opens.
Click Add instance selection.
In the New instance selection section, do the following:
In the Name field, enter a name for the instance selection.
In the Machine types section, click Add machine type, select
a machine type that you want to add in the instance selection, and
then click Done.
Repeat this step for each machine type that you want to add to the
instance selection.
After you complete adding the machine types,
click Done.
In the Instance selections window, click Done.
Leave the other fields in their default settings or modify as needed.
Zonal MIGs don't support instance flexibility. However, if you want to create
a MIG in a single zone, set the target distribution shape to
any-single-zone. Furthermore, if you want a specific zone, use the
any-single-zone distribution shape and include the --zones
ZONE 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 to
create and maintain.
INSTANCE_TEMPLATE_URL: the URL of the instance template that you want to
use to create instances in the MIG. The URL can contain either the
ID
or 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
be balanced, any, or any-single-zone.
MACHINE_TYPE: the machine types that you want
to 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 the
VM properties that you want for each VM in your MIG,
create an instance template.
Zonal MIGs don't support instance flexibility. However, if you want to create
a MIG in a single zone, set the target distribution shape to
ANY_SINGLE_ZONE. Furthermore, if you want a specific zone, use the
ANY_SINGLE_ZONE distribution shape and include the
distributionPolicy.zones[].zone field in the request.
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 to
create and maintain.
INSTANCE_TEMPLATE_URL: the URL of the instance template that you want to
use to create instances in the MIG. The URL can contain either the
ID
or 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
be BALANCED, ANY, or ANY_SINGLE_ZONE.
INSTANCE_SELECTION: the name for the list of
machine types.
MACHINE_TYPE: the machine types that you want
to configure in the MIG—for example,
"n1-standard-16","n2-standard-16","e2-standard-16".
Create a MIG with multiple machine types and preferences
In the Instance template list, select the instance template that you
want to use for the MIG.
Before you can specify the Number of instances and add
Instance selections, you need to do the following:
Go to the Location section on the page and set a location as follows:
Select Multiple zones.
In the Regions and the Zones drop-downs, select a region and
the zones in which you want to create the VMs in the MIG. If you
selected a regional instance template, then the region of that
template is selected by default.
In the Target distribution shape field, select Balanced,
Any, or Any single zone.
If you select Balanced or Any single zone, then in the
dialog that opens, click Disable instance redistribution.
If you select Any, then make sure that the
Allow instance redistribution checkbox is not selected.
Go to the Autoscaling section on the page and delete the autoscaling
configuration as follows:
In the Autoscaling mode drop-down, click Delete autoscaling
configuration.
In the dialog that opens, click Delete.
Scroll back to the Number of instances field.
In the Number of instances field, specify the number of VMs that you
want in the group.
In the Instance selections section, click Add selections.
The Instance selections window opens.
Repeat the following steps for each instance selection that you want to add
in the MIG.
Click Add instance selection.
In the New instance selection section, do the following:
In the Name field, enter a name for the instance selection.
In the Rank field, enter the order of preference among the
instance selections that you add for the MIG.
In the Machine types section, click Add machine type, select
a machine type that you want to add in the instance selection, and
then click Done.
Repeat this step for each machine type that you want to add to the
instance selection.
If you want to override the minimum CPU platform specified in the
instance template, then select the
Override CPU platform for this selection checkbox. In the
CPU platform list, select the platform that you want to use for
the instance selection.
If you want to override the disk configuration specified in the
instance template or to attach a storage, then select the
Override disks checkbox.
To override the boot disk, in the Boot disk section, click
Change, and follow the prompts.
To attach a storage, click Add new disk or Attach existing
disk, and follow the prompts.
After you complete adding the machine types and the overrides,
click Done.
After you complete adding the instance selections, click Done.
Leave the other fields in their default settings or modify as needed.
You can also use a YAML or JSON file to configure the instance flexibility
policy. To do so, use the --flags-file flag
instead of the --instance-flexibility-policy flag and specify the filename.
For example, use --flags-file=FILE_NAME.YAML.
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 to
use to create instances in the MIG. The URL can contain either the
ID
or 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 be balanced, any, or any-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.
MIN_CPU_PLATFORM: the
minimum CPU platform for the instances.
DEVICE_NAME: the device name
for the disk.
IMAGE_PROJECT: the project
ID of the source image.
IMAGE_NAME: the name of the
source image.
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 the
VM properties that you want for each VM in your MIG,
create an instance template.
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 to
use to create instances in the MIG. The URL can contain either the
ID
or 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 be BALANCED, ANY, or ANY_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.
MIN_CPU_PLATFORM: the
minimum CPU platform for the instances.
DEVICE_NAME: the device name
for the disk.
IMAGE_PROJECT: the project
ID of the source image.
IMAGE_NAME: the name of the
source image.
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 multiple
machine types and also set preferences for certain machine types.
If your MIG already has VMs in it, those VMs continue to use the machine type
specified in the instance template. If you want the existing VMs in the MIG to
use the machine types from the instance flexibility policy, then, after you add
the policy, delete
the existing VMs and then
resize the MIG
to the required number of VMs. When resizing, the new VMs will use the machine
types from the policy.
Click the name of the MIG in which you want to set multiple machine types.
Click Edit.
Click Instance flexibility to expand the section.
In the Instance selections section, click Add selections.
The Instance selections window opens.
Repeat the following steps for each instance selection that you want to add
in the MIG.
Click Add instance selection.
In the New instance selection section, do the following:
In the Name field, enter a name for the instance selection.
In the Rank field, enter the order of preference among the
instance selections that you add for the MIG.
In the Machine types section, click Add machine type, select
a machine type that you want to add in the instance selection, and
then click Done.
Repeat this step for each machine type that you want to add to the
instance selection.
If you want to override the minimum CPU platform specified in the
instance template, then select the
Override CPU platform for this selection checkbox. In the
CPU platform list, select the platform that you want to use for
the instance selection.
If you want to override the disk configuration specified in the
instance template or to attach a storage, then select the
Override disks checkbox.
To override the boot disk, in the Boot disk section, click
Change, and follow the prompts.
To attach a storage, click Add new disk or Attach existing
disk, and follow the prompts.
After you complete adding the machine types and the overrides,
click Done.
After you complete adding the instance selections, click Done.
You can also use a YAML or JSON file to configure the instance flexibility
policy. To do so, use the --flags-file flag
instead of the --instance-flexibility-policy flag and specify the filename.
For example, use --flags-file=FILE_NAME.YAML.
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.
MIN_CPU_PLATFORM: the
minimum CPU platform for the instances.
DEVICE_NAME: the device name
for the disk.
IMAGE_PROJECT: the project
ID of the source image.
IMAGE_NAME: the name of the
source image.
RANK: a number representing your
order of preference for instance selection. A lower value means a higher
preference.
INSTANCE_SELECTION:
the name of the list of machine types.
MACHINE_TYPE: the machine
types that you want to configure in the MIG.
MIN_CPU_PLATFORM: the
minimum CPU platform for the instances.
DEVICE_NAME: the device name
for the disk.
IMAGE_PROJECT: the project
ID of the source image.
IMAGE_NAME: the name of the
source image.
RANK: a number representing your
order of preference for instance selection. A lower value means a higher
preference.
Example for YAML file to configure instance flexibility
You can use a YAML or JSON file to configure the instance flexibility policy. To
do so, use the --flags-file flag in
your gcloud CLI command and specify the filename. For example, use
--flags-file=FILE_NAME.YAML.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-06-09 UTC."],[],[]]