Override instance template properties with an all-instances configuration Stay organized with collections Save and categorize content based on your preferences.
This page explains how you can use an all-instances configuration to setlabels andmetadata properties for allvirtual machine (VM) instances in amanaged instance group (MIG)without the need to create a new instance template.
You can continue to use instance templates to set instanceproperties in MIG. However, using a MIG's all-instances configuration is easierin some scenarios, such as the following:
You need to update instance metadata or labels frequently and without theoverhead of creating new templates each time. Remember that instance templatesare immutable, which means they cannot be modified after they are created.
You want to have multiple MIGs based on one instance template, but you need toconfigure labels or metadata for each MIG differently. For example, if youhave one app but you want to support different environments for development,testing, and production. You can create a single instance template and reuseit for all environments by setting different metadata with a differentall-instances configuration for each environment.
You have one team who owns infrastructure and images while another team runsapps that require configuration. You can have one team provisioninfrastructure with an instance template while the app team can manageapp configurations with all-instances configurations.
You have an agent running on your VMs and you want to configure it usingmetadata. You want to make sure the VM agent configuration persists even afterthe group's instance template changes. Use the instance template to controlthe app version and configure the VM agent using an all-instancesconfiguration.
If you set the same property using both the MIG's instance template and itsall-instances configuration, the MIG prioritizes the value from theall-instances configuration. For example, if metadata forenable-guest-attributes is set toFALSE in the MIG's instance template andTRUE in the MIG's all-instances configuration then Compute EngineappliesTRUE on all instances in the group. This lets you use anall-instances configuration to override properties that are defined in theinstance template.
Before you begin
- 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.
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. 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.For more information, seeAuthenticate for using REST in the Google Cloud authentication documentation.
Limitations
You can only override the following instance template properties with anall-instances configuration:
- Metadata
- Labels
You cannot canary update an all-instances configuration. When you apply theconfiguration to the group, Compute Engine applies the properties toall new instances, and to existing instances based on yourupdate policy. If you want tocontrol which existing instances get updated when, you can useselective updates.
If you use stateful configuration in your MIG, you cannot set the sameproperty in anyper-instance configurationand at the same time in the group's all-instances configuration.
Set properties in an all-instances configuration
Create and update a MIG's all-instances configuration using thegcloud CLI or REST.
Note: The configuration that you specify for VMs in a MIG is automaticallyapplied to new VMs that are added to the group. To apply the latestconfiguration to existing VMs, seeApply an all-instances configuration to existing VMs.Console
In the Google Cloud console, go to theInstance groups page.
Select the MIG of which you want to set the all-instances configuration.
ClickEdit.
ClickInstance template & overrides to expand the section.
In theAll-instances configuration section, do the following:
- To add or update metadata values, clickManage metadata. Completethe setup and clickSave.
- To add or update labels, clickManage labels. Completethe setup and clickSave.
After you finish setting up the properties in the all-instancesconfiguration, clickSave.
If the MIG's update type is set toAutomatic, then the all-instancesconfiguration which you set is immediately applied to all existing VMs.If the update type isSelective, then you must selectively applythe configuration to existing VMs. For more information, seeApply an all-instances configuration to existing VMs.
gcloud
Add or update an all-instances configuration by using theall-instances-config update command.
gcloud compute instance-groups managed all-instances-config updateINSTANCE_GROUP_NAME \ --metadata=KEY1=VALUE1,KEY2=VALUE2 \ --labels=KEY3=VALUE3,KEY4=VALUE4
Replace the following:
INSTANCE_GROUP_NAME: name of the MIG.KEYSandVALUES:key-value pairs for labels or metadata. If the key does not exist, thenthe update command adds it. For existing keys, their values are updated.
Remember toapply your updated configuration to existing VMs inthe MIG.
REST
Add or update an all-instances configuration by making aPATCH requeston azonalorregionalMIG.
PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME{ "allInstancesConfig": { "properties": { "metadata": { "KEY1": "VALUE1", ... }, "labels": { "KEY2": "VALUE2", ... }, } }}Replace the following:
PROJECT_ID: theprojectin which the MIG exists.REGION: the region where your MIG is located.For a zonal MIG, replaceregions/REGIONwithzones/ZONE.INSTANCE_GROUP_NAME: name of the MIG.KEYSandVALUES:key-value pairs for labels or metadata. If the key does not exist, thenthe request adds it. For existing keys, its value is updated.
Remember toapply your updated configuration to existing VMs inthe MIG.
Apply an all-instances configuration to existing VMs
TheVM configurationthat you specify for VMs in a MIG is automatically applied to new VMs that areadded to the group.
To apply an updated VM configuration–including an updated all-instancesconfiguration–to existing VMs in the group, use one of the following methods:
- Automatic (proactive): Use this method if you want the MIG toautomatically apply new configurations to all or to a subset ofexisting VMs in the group. The level of disruption to running VMs depends onthe update policy that you configure. You can use this method to canary updatenew instance templates. To use this method, set the MIG's update type to"proactive".
- Selective (opportunistic): Use this method if you want to apply theupdate manually or if you want to update all existing VMs in the group atonce. You target any or all VMs to be updated to the latest configuration. Touse this method, set the MIG's update type to "opportunistic".
- Re-creation of VMs: When you re-create a VM in a MIG, the MIG applies anyupdated configuration that has not yet been applied to that VM. For more information, seeRe-create VMs in a MIG.
Automatic (proactive)
If you want to automatically apply an updated all-instances configuration to allexisting VMs everytime you make a change to it, then set the group's updatepolicy type to "proactive". For more information, seeAutomatic (proactive) update type.
You can control the speed of a proactive configuration rollout by using theoptionalmaxUnavailable,maxSurge,andminReadySecsettings.
To use proactive updates you only need to configure it once. After that, the MIGapplies all future VM configuration changes (that is, changes to the group'sall-instances configuration, instance template, and per-instance configurations)automatically to all VMs in the group based on the settings in the group'supdate policy.
To automatically apply configuration updates, use the gcloud CLIor REST.
gcloud
You can configure automatic (proactive) updates by using theupdate command.
gcloud compute instance-groups managed updateINSTANCE_GROUP_NAME \--update-policy-type=proactive \ --update-policy-max-unavailable=MAX_UNAVAILABLE \ --update-policy-max-surge=MAX_SURGE \ --update-policy-min-ready=MIN_READY \ --update-policy-minimal-action=MINIMAL_ACTION \ --update-policy-replacement-method=REPLACEMENT_METHOD
Replace the following:
INSTANCE_GROUP_NAME: the name of the MIG.MAX_UNAVAILABLE(optional): maximum number ofinstances that can be unavailable during the update. For example, if youset theupdate-minimal-actionflag torestartthen this flag limitshow many VMs are restarted at a time. This can be a fixed number (forexample,5) or a percentage of size to the managed instance group (forexample,10%).MAX_SURGE(optional): maximum additional numberof instances that can be created during the update. This can be a fixednumber (for example,5) or a percentage of size to the managed instancegroup (for example,10%).MIN_READY(optional): minimum time for which arestarted or replaced VM should be ready to be considered available. Forexample10sfor 10 seconds. Seegcloud topic datetimesfor information on duration formats.MINIMAL_ACTION(optional): action to perform oneach instance during the configuration update:refresh: apply the new configuration on running instances withoutrestarting them.restart: restart VMs during the update, which is useful if your appreads metadata only during reboot.replace: delete VMs and create new ones to apply the newconfiguration to.
REPLACEMENT_METHOD(optional): specifies whataction is used to replace an instance:recreate: waits for the old instance to be deleted then creates anew instance with the same name as the old one.substitute: creates an instance with a new name while deleting theold instance
REST
You can configure automatic (proactive) updates by making aPATCH requeston azonal or aregionalMIG.
PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME{ "updatePolicy": {"type": "PROACTIVE", "maxUnavailable": { "percent":MAX_UNAVAILABLE }, "maxSurge": { "percent":MAX_SURGE }, "minimalAction":MINIMAL_ACTION, "replacementMethod":REPLACEMENT_METHOD }}Replace the following:
PROJECT_ID: theprojectin which the MIG exists.REGION: the region where your MIG is located.For a zonal MIG, replaceregions/REGIONwithzones/ZONE.INSTANCE_GROUP_NAME: name of the MIG.MAX_UNAVAILABLE(optional): maximum number ofinstances that can be unavailable during the update. For example if youset theupdate-minimal-actionflag toRESTARTthen this flag limitshow many VMs are restarted at a time. This can be a percentage (forexample, specify"percent": 80for 80%) or a fixed number. To specify afixed number, replace"percent":MAX_UNAVAILABLEwith"fixed":MAX_UNAVAILABLE.MAX_SURGE(optional): maximum additional numberof instances that can be created during the update. This can be apercentage or a fixed number.MINIMAL_ACTION(optional): action to perform oneach instance during the configuration update:REFRESH: apply the new configuration on running instances withoutrestarting them.RESTART: restart VMs during the update, which is useful if your appreads metadata only during reboot.REPLACE: delete VMs and create new ones to apply the newconfiguration to.
REPLACEMENT_METHOD(optional): specifies whataction is used to replace an instance:RECREATE: waits for the old instance to be deleted then creates anew instance with the same name as the old one.SUBSTITUTE: creates an instance with a new name while deleting theold instance
When optional flags are omitted, the group uses the values in the group'supdate policy. You cancheck the update policyusing the gcloud CLI or REST.
Selective (opportunistic)
If you want to control when and to which VMs to apply a new configuration to,then set the group's update policy type to "opportunistic". For moreinformation, seeSelective (opportunistic) update type.
When you choose to selectively apply configuration updates, any changes to thegroup's all-instances configuration, instance template, or per-instanceconfigurations are not automatically applied to existing VMs. You mustexplicitly apply an updated configuration to existing VMs in order to updatethem.
Note: When you enable selective updates by setting the group's update policytype to "opportunistic", you must manually initiate the update on existingVMs every time you make changes to the group's configuration.To selectively apply VM configuration updates to VMs in a MIG, use thegcloud CLI or REST.
gcloud
You can configure selective (opportunistic) updates by using theupdate command:
gcloud compute instance-groups managed updateINSTANCE_GROUP_NAME \--update-policy-type=opportunistic
When you set the group's update type toopportunistic, you must initiatethe update when you want to apply the new configuration to existing VMs.
Apply configuration to specific VMs
To update selected instances, use the following command:
gcloud compute instance-groups managed update-instancesINSTANCE_GROUP_NAME \--instancesINSTANCE_NAMES \ --minimal-action=MINIMAL_ACTION \ --most-disruptive-allowed-action=MOST_DISRUPTIVE_ALLOWED_ACTION
Apply configuration to all VMs
To update all existing instances, use the following command:
gcloud compute instance-groups managed update-instancesINSTANCE_GROUP_NAME \--all-instances \ --minimal-action=MINIMAL_ACTION \ --most-disruptive-allowed-action=MOST_DISRUPTIVE_ALLOWED_ACTION
Replace the following:
INSTANCE_GROUP_NAME: name of the MIG.INSTANCE_NAMES: a list of instances to apply thetemplate to.MINIMAL_ACTION(optional): action to perform oneach instance during its configuration update:refresh(default): apply the new configuration on running instanceswithout restarting them.restart: restart VMs during the update, which is useful if your appreads metadata only during reboot.replace: delete VMs and create new ones to apply the newconfiguration to.
MOST_DISRUPTIVE_ALLOWED_ACTION(optional):perform at most this action on each instance. If the configurationupdate requires a more disruptive action than the one specified here,then the update fails and no changes are made.none: no actionrefresh: apply the new configuration without stopping instances,if possible. For example, userefreshto apply changes that onlyaffect metadata or additional disks.restart: apply the new configuration without replacing instances,if possible. For example, stopping instances and starting them againis sufficient to apply changes to machine type.replace: replace old instances according to the--replacement-methodflag.
REST
You can configure selective (opportunistic) updates by making aPATCHrequest on azonal orregionalMIG.
PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME{ "updatePolicy": {"type": "OPPORTUNISTIC" }}When you set the group's update type toOPPORTUNISTIC, you must initiatethe update when you want to apply the new configuration to existing VMs.
Apply configuration to specific VMs
To update specific instances, use the following request:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME/applyUpdatesToInstances{ "instances": [ "zones/ZONE/instances/INSTANCE_NAME_1", "zones/ZONE/instances/INSTANCE_NAME_2" ], "minimalAction": MINIMAL_ACTION, "mostDisruptiveAllowedAction": MOST_DISRUPTIVE_ALLOWED_ACTION}Apply configuration to all VMs
To update all existing instances, use the following request:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME/applyUpdatesToInstances{"allInstances": true, "minimalAction": MINIMAL_ACTION, "mostDisruptiveAllowedAction": MOST_DISRUPTIVE_ALLOWED_ACTION}Replace the following:
PROJECT_ID: theprojectin which the MIG exists.REGION: the region where your MIG is located.For a zonal MIG, replaceregions/REGIONwithzones/ZONE.INSTANCE_GROUP_NAME: name of the MIG.MINIMAL_ACTION(optional): action to perform oneach instance during the configuration update:REFRESH: apply the new configuration on running instances withoutrestarting them.RESTART: restart VMs during the update, which is useful if your appreads metadata only during reboot.REPLACE: delete VMs and create new ones to apply the newconfiguration to.
MOST_DISRUPTIVE_ALLOWED_ACTION(optional):perform at most this action on each instance. If the configurationupdate requires a more disruptive action than the one specified here,then the update fails and no changes are made.NONE: no actionREFRESH: apply the new configuration without stopping instances,if possible. For example, useREFRESHto apply changes that onlyaffect metadata or additional disks.RESTART: apply the new configuration without replacing instances,if possible. For example, stopping instances and starting them againis sufficient to apply changes to machine type.REPLACE: replace old instances according to the group'supdatePolicy.replacementMethodfield.
Verify if an updated all-instances configuration has been applied
You can verify if the latest all-instances configuration has been applied toall VMs in the group by using one of the following ways.
Console
In the Google Cloud console, go to theInstance groups page.
Select the MIG of which you want to view the all-instancesconfiguration.
Go to theDetails tab.
If the latest all-instances configuration is applied to all VMs, then intheAll instances configuration section, theLast modifiedtimestamp and theStatus field must show the values as follows:
- Last modified: Shows the time that you applied theall-instances configuration to all VMs.
- Status: ShowsApplied to all VMs. If the all-instancesis not applied to all VMs, then the status is shown asPending VM update.
gcloud
Use thedescribe commandand include the--format flag to look for thestatus.allInstancesConfig.effective value.
gcloud compute instance-groups managed describeINSTANCE_GROUP_NAME \ --format="(status.allInstancesConfig)"
Sample output:
status: allInstancesConfig:currentRevision: 2022-12-02T10:30:15.012345Z effective: true
If theeffective value is set totrue, then all VMs have the latestconfiguration applied. ThecurrentRevision value shows the timestamp ofthe latest change to the group's all-instances configuration.
If theeffective value is set tofalse, then the latest configuration isnot yet applied to all VMs.
To check the status of each VM, you canlist all of the MIG's VMsor check each VM individually with thedescribe-instance command:
gcloud compute instance-groups managed describe-instanceINSTANCE_GROUP_NAME \ --instanceINSTANCE_NAME
Sample output:
allInstancesConfig: revision: 2022-12-02T10:30:15.012345ZcurrentAction: NONEid: '8393021473297481188'instance: .../projects/PROJECT/zones/ZONE/instances/INSTANCE_NAMEinstanceStatus: RUNNINGname:INSTANCE_NAMEversion: instanceTemplate: .../projects/PROJECT/global/instanceTemplates/INSTANCE_TEMPLATE
To see which VMs have the latest configuration applied, compare therevision timestamp on each VM with thecurrentRevision timestamp on theMIG.
REST
Make aGET request onzonal orregionalMIG to check for the value ofstatus.allInstancesConfig.effective flag.
GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME
Sample response:
{ ... "status": { "isStable": "true", "versionTarget": { "isReached": "true" }, "allInstancesConfig": {"currentRevision": "2022-12-02T10:30:15.012345Z", "effective": "true" }, ... }, ...}If theeffective field is set totrue then all VMs have the latestconfiguration applied. ThecurrentRevision field shows the timestamp ofthe latest change to the group's all-instances configuration.
If theeffective field is set tofalse, then the latest configuration isnot yet applied to all VMs.
To check the status of each instance, list managed instances for thezonalorregionalMIG:
GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME/listManagedInstances
Sample output:
{ "managedInstances": [ ... { "instance": ".../zones/ZONE/instances/INSTANCE_NAME", "instanceStatus": "RUNNING", "currentAction": "NONE","allInstancesConfig": { "revision": "2022-12-02T10:30:15.012345Z" }, "version": { "name": "V1", "instanceTemplate": ".../projects/.../instanceTemplates/INSTANCE_TEMPLATE" } }, { ... } ]}To see which VMs have the latest configuration applied, compare therevision timestamp on each VM with thecurrentRevision timestamp on theMIG.
List properties in an all-instances configuration
An all-instances configuration is part of theMIG's configuration.To review the all-instances configuration, use one of the following ways.
Note: When reviewing your group's all-instances configuration, remember to makesure that you've alsoapplied the configuration to existingVMs.Console
In the Google Cloud console, go to theInstance groups page.
Select the MIG of which you want to view the all-instancesconfiguration.
Go to theDetails tab.
See theAll instances configuration section.
gcloud
Use thedescribe commandand include the--format flag to show the group's all-instancesconfiguration value.
gcloud compute instance-groups managed describeINSTANCE_GROUP_NAME \ --format="(allInstancesConfig)"
The command returns the group's all-instances configuration, if it exists.
REST
Make aGET request on azonal orregionalMIG and look for theallInstancesConfig field.
GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME
If theallInstancesConfig field is not set, then the group has noall-instances configuration.
Delete properties from all-instances configuration
If you delete a property from the MIG's all-instances configuration, and thesame property exists in the MIG's instance template, then VMs in theMIG will re-inherit that property from the instance template once the latestconfiguration is applied to VMs in the MIG. For more information about applyingthe latest configuration to existing VMs, seeApply an all-instances configuration to existing VMs.
To delete properties from an all-instances configuration, use one of thefollowing ways.
Console
In the Google Cloud console, go to theInstance groups page.
Select the MIG from which you want to delete the all-instancesconfiguration.
ClickEdit.
ClickInstance template & overrides to expand the section.
In theAll-instances configuration section, do the following:
- Depending on the property that you want to delete, clickManage metadata orManage labels.
- In theManage metadata or theManage labels pane, hold thepointer over a setting to activate the delete option, and thenclickDelete item.
- ClickSave.
ClickSave to apply the changes to the MIG.
If the MIG's update type is set toAutomatic, then the changes inall-instances configuration is immediately applied to all existing VMs.If the update type isSelective, then you must selectively applythe configuration to existing VMs. For more information, seeApply an all-instances configuration to existing VMs.
gcloud
To delete properties, use theall-instances-configuration delete commandand specify one or more keys for the properties that you want to delete.
gcloud compute instance-groups managed all-instances-config deleteINSTANCE_GROUP_NAME \ --metadata=KEY1[,KEY1]\ --labels=KEY1[,KEY1]
Remember toapply your updated configuration to existing VMs inthe MIG.
REST
To delete properties, make aPATCH request on azonal orregionalMIG and specify anull value as the key for each property that you want toremove.
PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME{ "allInstancesConfig": { "properties": { "metadata": { "KEY1": null, ... }, "labels": { "KEY2": null, ... } } }}Pro Tip: You can create, update, anddelete multipleallInstancesConfig properties in a single APIrequest.
Remember toapply your updated configuration to existing VMs inthe MIG.
What's next
- Learn more aboutautomatically applyingan updated configuration to existing VMs in a MIG.
- Learn more aboutselectively applyingconfiguration updates to existing VMs in a MIG.
- View informationabout your MIG and its VMs.
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.