Create a MIG in a single zone Stay organized with collections Save and categorize content based on your preferences.
This document describes how to create amanaged instance group (MIG)in a single zone. Putting all your MIG's VMs in a single zone helps to minimizelatency, which is useful for certain workloads—for example, batch workloads.
This type of MIG is also known as azonal MIG.
You can also read about otherbasic scenarios for creating a MIG.
Before you begin
- Create an instance template, which is required in order to create a managed instance group.
- 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.
Limitations
To see the full list of MIG limitations, which varies based on the configurationthat you use, seeMIG limitations.
Create a MIG in a single zone
To create a MIG in a single zone, use theGoogle Cloud console, thegcloud CLI,Terraform, orREST.
Permissions required for this task
To perform this task, you must have the followingpermissions:
- All permissions required to call the
instanceGroupManagers.insertmethod.
Console
In the Google Cloud console, go to theInstance groups page.
The remaining steps appear in the Google Cloud console.
- Click
Create instance group . - If you want to create a stateful MIG, select the
New managed instance group (stateful) option. To help you decide, seeWhen to use stateful MIGs. - Assign a name and optionally a description to your instance group.
- Choose an instance template for the instance group orcreate a new one.
- Specify the
number of VMs for this group. Remember toprovision enough VMs to support your application if a zone failure happens. - For
Location , selectSingle zone. - Select theRegion and theZone where you want to create your MIG. If you chose a regional instance template, then theRegion is automatically selected based on the template's region.
- For stateless MIGs,Autoscaling is enabled by default. With autoscaling, your groupautomatically adds or removes instances based on its utilization.
- Optionally, enableautohealing to perform application-based health checking on VMs within the group.
- ClickCreate to create the new group.
gcloud
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.
Create a managed instance group with theinstance-groups managed create commandand specify the group name, group size, instance template, and zone.
gcloud compute instance-groups managed createINSTANCE_GROUP_NAME \ --sizeSIZE \ --templateINSTANCE_TEMPLATE_URL \ --zoneZONE
Replace the following:
INSTANCE_GROUP_NAME: the name for thisinstance group.SIZE: the size of the instance group.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:
ZONE: one of thezones available forCompute Engine. If you want to distribute your MIG's VMs acrossmultiple zones in a region, seeCreate a regional MIG.
You can optionally supply the--base-instance-name flag. Because theseVMs are based on a common template, each VM is assigned a random string aspart of its VM name. The base name is prepended to this random string. Forexample, if you set the base name totest, VMs will have names liketest-yahs andtest-qtyz. If you need specific names, seeCreating instances with specific names in MIGs.
For example, the following command creates an instance group namedexample-group, with base VM nametest. The group contains threeinstances:
gcloud compute instance-groups managed create example-group \ --base-instance-name test \ --size 3 \ --template an-instance-template \ --zone us-central1-f
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 zonal MIG, you can use thegoogle_compute_instance_group_managerresource.
resource "google_compute_instance_group_manager" "default" { name = "example-group" base_instance_name = "test" target_size = 3 zone = "us-central1-f" version { instance_template = google_compute_instance_template.default.id name = "primary" }}To learn how to apply or remove a Terraform configuration, seeBasic Terraform commands.
REST
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.
Create a managed instance group with theinstanceGroupManagers.insert method.In the request body, include the group name, group size,and the URL to the instance template.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers{ "versions": [ { "instanceTemplate": "INSTANCE_TEMPLATE_URL" } ], "name": "INSTANCE_GROUP_NAME", "targetSize":SIZE}Replace the following:
PROJECT_ID: the project ID for the request.ZONE: thezone for the request. If youwant to distribute your MIG's VMs across multiple zones in a region,replacezones/ZONEwithregions/REGIONand specify a region. For moreinformation, seeCreate a regional MIG.INSTANCE_GROUP_NAME: the name for thisinstance group.SIZE: the size of the instance group.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:
You can optionally supply thebase-name field. Because theseVMs are based on a common template, each VM is assigned a random string aspart of its VM name. The base name is prepended to this random string. Forexample, if you set the base name totest, VMs will have names liketest-yahs andtest-qtyz. If you need specific names, seeCreating instances with specific names in MIGs.
Depending on how you configure and act on a MIG, various policies and actionscan affect the instances in the group. To determine which managedinstances are up and running, seeChecking the status of managed instances.
What's next
- Set up application-based autohealing,which periodically verifies that your application responds as expected oneach of the MIG's VMs and automatically recreates unresponsive VMs.
- Enable autoscaling to automatically add or deleteVMs from your MIG based on increases or decreases in load.
- Learn how toapply a new configurationto all or to a subset of the VMs in a MIG by setting and applying a newinstance template, all-instances configuration, or per-instance configuration.
- Preserve disks, metadata, and IP addresses across disruptive events like VMrecreation, autohealing, and updates byadding stateful configuration.
- Learn aboutworking with managed instances,for example, to delete, abandon, and recreate VMs in a MIG.
- View info aboutMIGs and their VMs.
- Learn how toadd an external HTTP(S) load balancer frontend to your instancegroup. Forinformation about other types of load balancers, see theLoad balancingoverview.
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-02 UTC.