Stay organized with collections Save and categorize content based on your preferences.
This document describes how to create a managed instance group (MIG) that preserves the data on disks with a given device name for all of the MIG's VMs, even in the event of VM recreation—for example when a VM in the MIG is autohealed, updated, or recreated. Preserving disks is useful for certain workloads—for example, for databases or legacy applications.
In addition to preserving disks for all VMs in the group, you can also configure a stateful MIG for the following:
For more information, see the stateful MIG overview.
You can also read about other basic scenarios for creating a MIG.
Before you beginSelect the tab for how you plan to use the samples on this page:
ConsoleWhen you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloudInstall the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:
gcloud init
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
.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:
gcloud auth application-default login
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.
RESTTo 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.
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
A MIG with stateful configuration—a stateful MIG—has the following limitations:
RECREATE
.NONE
) to prevent deletion of stateful instances by automatic cross-zone redistribution.To see the full list of MIG limitations, which varies based on the configuration that you use, see MIG limitations.
Create a MIG with stateful disksUse the Google Cloud console, the gcloud CLI, Terraform, or REST.
Pro Tip: Consider storing data on an additional persistent disk and keeping the boot disk, containing the application, stateless. Such a configuration makes your application resilient to boot disk file system corruption. This configuration also simplifies VM updates because the MIG can recreate boot disks based on the immutable source image that you specify in the MIG's instance template.
Permissions required for this taskTo perform this task, you must have the following permissions:
instanceGroupManagers.insert
method (for zonal MIGs)regionInstanceGroupManagers.insert
method (for regional MIGs)Go to the Instance groups page.
The remaining steps appear in the Google Cloud console.
To specify which disks from the instance template should be stateful on MIG creation, use the --stateful-disk
flag with the gcloud compute instance-groups managed create
command:
gcloud compute instance-groups managed create INSTANCE_GROUP_NAME \ --template INSTANCE_TEMPLATE_URL \ --size SIZE \ --stateful-disk device-name=DEVICE_NAME[,auto-delete=DELETE_RULE]
Replace the following:
INSTANCE_GROUP_NAME
: The name of the managed instance group to create.INSTANCE_TEMPLATE_URL
: the URL of the instance template that you want to use to create VMs in the MIG. The URL can contain either the ID or name of the instance template. Specify one of the following values:
projects/PROJECT_ID/regions/REGION/instanceTemplates/INSTANCE_TEMPLATE_ID
INSTANCE_TEMPLATE_ID
SIZE
: The initial number of VMs you need in this group.DEVICE_NAME
: The device name of a disk specified in the instance template.DELETE_RULE
: A value that prescribes what should happen to a stateful disk when a VM is deleted. Available options are:
never
: (Default.) Never delete the disk; instead, detach the disk when its VM is deleted.on-permanent-instance-deletion
: Delete the disk when its VM instance is permanently deleted from the instance group, for example, when the managed instance is deleted manually or when the group size is decreased.Regardless of the value of the delete rule, stateful disks are always preserved on VM autohealing, update, and recreation operations.
gcloud compute instance-templates describe
command. Terraform
If you haven't already created an instance template, which specifies the machine type, boot disk image, network, and other VM properties that you want for each VM in your MIG, create an instance template.
To specify which disks from the instance template should be stateful on MIG creation, include the stateful_disk
block. The following sample creates a zonal MIG with stateful disks. For more information about the resource that is used in the sample, see google_compute_instance_group_manager
resource.
To learn how to apply or remove a Terraform configuration, see Basic Terraform commands.
RESTTo specify which disks from the instance template should be stateful on MIG creation, include them in the statefulPolicy
field in your request body. For a zonal MIG, use the instanceGroupManagers.insert
method or for a regional MIG, use the regionInstanceGroupManagers.insert
method.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT/zones/ZONE/instanceGroupManagers { "name": "NAME", "versions": [ { "instanceTemplate": "INSTANCE_TEMPLATE_URL" } ], "targetSize": SIZE, "statefulPolicy": { "preservedState": { "disks": { "DEVICE_NAME": {"autoDelete": "DELETE_RULE" }, "DEVICE_NAME": {"autoDelete": "DELETE_RULE" } } } } }
Replace the following:
PROJECT
: The project ID for the request.ZONE
: The zone where the MIG is located (applies to a zonal MIG).
zones/ZONE
with regions/REGION
and specify the region of the MIG.NAME
: The name of the MIG to create.INSTANCE_TEMPLATE_URL
: the URL of the instance template that you want to use to create VMs in the MIG. The URL can contain either the ID or name of the instance template. Specify one of the following values:
projects/PROJECT_ID/regions/REGION/instanceTemplates/INSTANCE_TEMPLATE_ID
INSTANCE_TEMPLATE_ID
SIZE
: The initial number of instances you need in this group.DEVICE_NAME
: The device name of a disk specified in the instance template.DELETE_RULE
: A value that prescribes what should happen to the stateful disk when the VM instance is deleted. The available options are:
never
: (Default.) Never delete the disk; detach the disk when the VM is deleted.on_permanent_instance_deletion
: Delete the stateful disk when its VM is permanently deleted from the instance group, for example, when the managed instance is deleted manually or when the group size is decreased.Regardless of the value of the delete rule, stateful disks are always preserved on instance autohealing, update, and recreation operations.
instanceTemplates.get
method and reading the instanceTemplates.disks[].deviceName
field in the response. What's next
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["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 2025-08-07 UTC."],[[["This document guides users on creating managed instance groups (MIGs) that preserve data on specified disks across VM operations like autohealing, updates, or recreation, which is useful for workloads such as databases."],["Stateful MIGs offer the ability to preserve instance-specific disks, metadata, and IP addresses, extending beyond basic data persistence."],["Creating a stateful MIG involves defining stateful disks during MIG creation, through the console, gcloud CLI, Terraform, or REST API, by specifying device names and delete rules."],["When configuring stateful disks, you can choose whether to detach or delete the disk when a VM is permanently deleted, but disks are always preserved during VM autohealing, update, or recreation regardless of the setting."],["Stateful MIGs have limitations such as not being compatible with autoscaling and requiring the `RECREATE` replacement method for automated rolling updates, along with needing proactive redistribution to be disabled for stateful regional MIGs."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4