Replace, remove, or delete workload policies

This document explains how to replace, remove, or delete workload policies from managed instance groups (MIGs). These actions are useful in the following scenarios:

  • Replace a workload policy: you can change how Compute Engine instances are located within your MIG, or switch to a different workload policy that better fits your workload's requirements.

  • Remove a workload policy: you can stop using specific placement rules if your workload no longer needs them, reverting the MIG to default compute instance placement behavior.

  • Delete a workload policy: you can permanently delete workload policies that you no longer need.

To learn how to create a workload policy, see Create workload policies for MIGs .

Limitations

You can replace or remove a workload policy from a MIG only if there are no compute instances in the MIG.

Before you begin

  • 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:

    gcloud

    1. Install 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 .

    2. 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.

      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.

Required roles

To get the permissions that you need to replace, remove, or delete workload policies, ask your administrator to grant you the Compute Instance Admin (v1) ( roles/compute.instanceAdmin.v1 ) IAM role on your project. For more information about granting roles, see Manage access to projects, folders, and organizations .

This predefined role contains the permissions required to replace, remove, or delete workload policies. To see the exact permissions that are required, expand the Required permissionssection:

Required permissions

The following permissions are required to replace, remove, or delete workload policies:

  • To replace or remove a workload policy from a MIG: compute.instances.update on the project
  • To delete a workload policy: compute.resourcePolicies.delete on the project

You might also be able to get these permissions with custom roles or other predefined roles .

Replace a workload policy in a MIG

To replace a workload policy in a MIG with a different, existing workload policy, select one of the following options:

gcloud

  1. Manually set the size of the MIG to 0 .

  2. To replace the workload policy in your MIG, use the gcloud compute instance-groups managed update command with the --workload-policy flag. Based on the MIG type, include one of the following flags:

    • To replace the workload policy in a zonal MIG, include the --zone flag:

       gcloud compute instance-groups managed update MIG_NAME 
      \
          --workload-policy= WORKLOAD_POLICY 
      \
          --zone= ZONE 
       
      
    • To replace the workload policy in a regional MIG, include the --region flag:

       gcloud compute instance-groups managed update MIG_NAME 
      \
          --workload-policy= WORKLOAD_POLICY 
      \
          --region= REGION 
       
      

    Replace the following:

    • MIG_NAME : the name of the MIG.

    • WORKLOAD_POLICY : the name of the workload policy that you want to apply to your MIG.

    • ZONE : the zone where your zonal MIG exists.

    • REGION : the region where your regional MIG and the workload policy exist.

REST

  1. Manually set the size of the MIG to 0 .

  2. To replace the workload policy in your MIG, make a PATCH request to one of the following methods:

    • To replace the workload policy in a zonal MIG, make a PATCH request to the compute.instanceGroupManagers.patch method :

       PATCH https://compute.googleapis.com/compute/v1/projects/ PROJECT_ID 
      /zones/ ZONE 
      /instanceGroupManagers/ MIG_NAME 
      {
        "workloadPolicy": "projects/ PROJECT_ID 
      /regions/ REGION 
      /resourcePolicies/ WORKLOAD_POLICY 
      "
      } 
      
    • To replace the workload policy in a regional MIG, make a PATCH request to the compute.regionInstanceGroupManagers.patch method :

       PATCH https://compute.googleapis.com/compute/v1/projects/ PROJECT_ID 
      /regions/ REGION 
      /instanceGroupManagers/ MIG_NAME 
      {
        "workloadPolicy": "projects/ PROJECT_ID 
      /regions/ REGION 
      /resourcePolicies/ WORKLOAD_POLICY 
      "
      } 
      

    Replace the following:

    • PROJECT_ID : the ID of the project where your MIG and the workload policy exist.

    • ZONE : the zone where your zonal MIG exists.

    • REGION : the region where your regional MIG and the workload policy exist.

    • MIG_NAME : the name of your MIG.

    • WORKLOAD_POLICY : the name of the workload policy that you want to apply to your MIG.

Remove a workload policy from a MIG

To remove a workload policy from a MIG, select one of the following options:

gcloud

  1. Manually set the size of the MIG to 0 .

  2. To remove a workload policy from a MIG, use the gcloud compute instance-groups managed update command with the --remove-workload-policy flag. Based on the MIG type, include one of the following flags:

    • To remove a workload policy from a zonal MIG, include the --zone flag:

       gcloud compute instance-groups managed update MIG_NAME 
      \
          --remove-workload-policy= WORKLOAD_POLICY 
      \
          --zone= ZONE 
       
      
    • To remove a workload policy from a regional MIG, include the --region flag:

       gcloud compute instance-groups managed update MIG_NAME 
      \
          --remove-workload-policy= WORKLOAD_POLICY 
      \
          --region= REGION 
       
      

    Replace the following:

    • MIG_NAME : the name of your MIG.

    • WORKLOAD_POLICY : the name of the workload policy that is applied to your MIG.

    • ZONE : the zone where your zonal MIG exists.

    • REGION : the region where your regional MIG exists.

REST

  1. Manually set the size of the MIG to 0 .

  2. To remove a workload policy from a MIG, make a PATCH request to one of the following methods:

    • To remove a workload policy from a zonal MIG, make a request to the compute.instanceGroupManagers.patch method :

       PATCH https://compute.googleapis.com/compute/v1/projects/ PROJECT_ID 
      /zones/ ZONE 
      /instanceGroupManagers/ MIG_NAME 
      {
        "workloadPolicy": ""
      } 
      
    • To remove a workload policy from a regional MIG, make a request to the compute.regionInstanceGroupManagers.patch method :

       PATCH https://compute.googleapis.com/compute/v1/projects/ PROJECT_ID 
      /regions/ REGION 
      /instanceGroupManagers/ MIG_NAME 
      {
        "workloadPolicy": ""
      } 
      

    Replace the following:

    • PROJECT_ID : the ID of the project where your MIG and the workload policy exist.

    • ZONE : the zone where your zonal MIG exists.

    • REGION : the region where your regional MIG and the workload policy exist.

    • MIG_NAME : the name of your MIG.

Delete a workload policy

You can't delete a workload policy that's applied to a MIG. Before you delete the policy, you must remove it from the MIG .

To delete a workload policy, select one of the following options:

gcloud

To delete a workload policy, use the gcloud compute resource-policies delete command :

 gcloud compute resource-policies delete WORKLOAD_POLICY 
\
    --region= REGION 
 

Replace the following:

  • WORKLOAD_POLICY : the name of an existing workload policy.

  • REGION : the region where the workload policy exists.

REST

To delete a workload policy, make a DELETE request to the resourcePolicies.delete method :

 DELETE https://compute.googleapis.com/compute/v1/projects/ PROJECT_ID 
/regions/ REGION 
/resourcePolicies/ POLICY_NAME 
 

Replace the following:

  • PROJECT_ID : the ID of the project where the workload policy exists.

  • REGION : the region where the workload policy exists.

  • POLICY_NAME : the name of an existing workload policy.

What's next

Design a Mobile Site
View Site in Mobile | Classic
Share by: