[Yandex Cloud documentation](../../../index.md) > [Yandex Compute Cloud](../../index.md) > [Step-by-step guides](../index.md) > Managing an instance group > Moving an instance group to a different availability zone

# Moving an instance group to a different availability zone


If your instance group is connected to a load balancer, follow these guides as appropriate:
* [Moving an instance group with a network load balancer to a different availability zone](move-group-with-nlb.md)
* [Moving an instance group with an L7 load balancer to a different availability zone](move-group-with-alb.md)

To move an instance group to a different availability zone:
1. [Create](../../../vpc/operations/subnet-create.md) a subnet in the availability zone you want to move your instance group to.
1. Add the group instances to the new availability zone:

    {% list tabs group=instructions %}
    
    - Management console {#console}
    
      1. In the [management console](https://console.yandex.cloud), open the [folder](../../../resource-manager/concepts/resources-hierarchy.md#folder) containing the [instance group](../../concepts/instance-groups/index.md) you need.
      1. Navigate to **Compute Cloud**.
      1. In the left-hand panel, select ![image](../../../_assets/console-icons/layers-3-diagonal.svg) **Instance groups**.
      1. Select the instance group to update.
      1. In the top-right corner, click ![image](../../../_assets/console-icons/pencil.svg) **Edit**.
      1. Under **Allocation**, add the [availability zone](../../../overview/concepts/geo-scope.md) you want to move the instance group to. 
      1. If your instance group is a [manually scaled](../../concepts/instance-groups/scale.md#fixed-scale) one, under **Scaling**, specify a group size sufficient to place instances in all the selected availability zones.
    
         You will be able to reset the number of instances back to the initial one after all the instances in the group are moved to the new availability zone and deleted from the previous one.
      1. If your instance group is an [autoscaling](../../concepts/instance-groups/scale.md#auto-scale) one and has the `OPPORTUNISTIC` [shutdown strategy](../../concepts/instance-groups/policies/deploy-policy.md#strategy), change the strategy to `PROACTIVE` in the **Stop VMs by strategy** field.
    
         You will be able to reset the shutdown strategy back to `OPPORTUNISTIC` after all the instances in the group are moved to the new availability zone and deleted from the previous one.
      1. Click **Save**.
    
    - CLI {#cli}
    
      If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).
    
      The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
    
      1. Open the [instance group](../../concepts/instance-groups/index.md) [specification](../../concepts/instance-groups/specification.md) file and edit the [instance template](../../concepts/instance-groups/instance-template.md):
         * Under `allocation_policy`, add a new [availability zone](../../../overview/concepts/geo-scope.md).
         * Under `network_interface_specs`, add the ID of the previously created [subnet](../../../vpc/concepts/network.md#subnet).
         * If your instance group is a [manually scaled](../../concepts/instance-groups/scale.md#fixed-scale) one, under `scale_policy`, specify a group size sufficient to place instances in all the selected availability zones.
    
           You will be able to reset the number of instances back to the initial one after all the instances in the group are moved to the new availability zone and deleted from the previous one.
         * If your instance group is an [autoscaling](../../concepts/instance-groups/scale.md#auto-scale) one and has the `OPPORTUNISTIC` [shutdown strategy](../../concepts/instance-groups/policies/deploy-policy.md#strategy), change the strategy to `PROACTIVE` under `deploy_policy`.
    
           You will be able to reset the shutdown strategy back to `OPPORTUNISTIC` after all the instances in the group are moved to the new availability zone and deleted from the previous one.
      1. See the description of the CLI command for updating an instance group:
    
         ```bash
         yc compute instance-group update --help
         ```
    
      1. Get a list of all instance groups in the default [folder](../../../resource-manager/concepts/resources-hierarchy.md#folder):
    
         ```bash
         yc compute instance-group list
         ```
    
         Result:
    
         ```text
         +----------------------+---------------------------------+--------+--------+
         |          ID          |              NAME               | STATUS |  SIZE  |
         +----------------------+---------------------------------+--------+--------+
         | cl15sjqilrei******** | first-fixed-group-with-balancer | ACTIVE |      3 |
         | cl19s7dmihgm******** | test-group                      | ACTIVE |      2 |
         +----------------------+---------------------------------+--------+--------+
         ```
    
      1. Update the instance group:
    
         ```bash
         yc compute instance-group update \
           --id <instance_group_ID> \
           --file <instance_specification_file>
         ```
    
         Where:
         * `--id`: Instance group ID.
         * `--file`: Path to the instance group specification file.
    
         Result:
    
         ```text
         id: cl15sjqilrei********
         ...
         allocation_policy:
         zones:
         - zone_id: <previous_availability_zone>
         - zone_id: <new_availability_zone>
         ...
         ```
    
    - Terraform {#tf}
    
      If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
      1. Open the Terraform configuration file for the [instance group](../../concepts/instance-groups/index.md). Specify the new [availability zone](../../../overview/concepts/geo-scope.md) under `allocation_policy` and the ID of the previously created [subnet](../../../vpc/concepts/network.md#subnet) under `network_interface`.
    
         ```hcl
         ...
         network_interface {
           subnet_ids = [
             "<ID_of_subnet_in_previous_availability_zone>",
             "<ID_of_subnet_in_new_availability_zone>"
           ]
         }
         ...
         allocation_policy {
           zones = [
             "<previous_availability_zone>",
             "<new_availability_zone>"
           ]
         }
         ...
         ```
    
         Where:
         * `zones`: Availability zones to host the instance group, both the new and previous ones.
         * `subnet_ids`: IDs of subnets in the availability zones to host the instance group.
    
         If your instance group is a [manually scaled](../../concepts/instance-groups/scale.md#fixed-scale) one, under `scale_policy`, specify a group size sufficient to place instances in all the selected availability zones.
    
         ```hcl
         ...
         scale_policy {
           fixed_scale {
             size = <number_of_instances_in_group>
           }
         }
         ...
         ```
    
         You will be able to reset the number of instances back to the initial one after all the instances in the group are moved to the new availability zone and deleted from the previous one.
    
         If your instance group is an [autoscaling](../../concepts/instance-groups/scale.md#auto-scale) one and has the `OPPORTUNISTIC` [shutdown strategy](../../concepts/instance-groups/policies/deploy-policy.md#strategy), change the strategy to `PROACTIVE`:
    
         ```hcl
         ...
         deploy_policy {
           strategy = "proactive" 
         }
         ...
         ```
    
         You will be able to reset the shutdown strategy back to `OPPORTUNISTIC` after all the instances in the group are moved to the new availability zone and deleted from the previous one.
    
         For more information about resource properties in Terraform, see [this provider guide](../../../terraform/resources/compute_instance_group.md).
      1. Apply the changes:
    
         1. In the terminal, navigate to the configuration file directory.
         1. Make sure the configuration is correct using this command:
         
            ```bash
            terraform validate
            ```
         
            If the configuration is valid, you will get this message:
         
            ```bash
            Success! The configuration is valid.
            ```
         
         1. Run this command:
         
            ```bash
            terraform plan
            ```
         
            You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
         1. Apply the configuration changes:
         
            ```bash
            terraform apply
            ```
         
         1. Type `yes` and press **Enter** to confirm the changes.
    
         This will add the new availability zone for your instance group. You can check the updates using the [management console](https://console.yandex.cloud) or this [CLI](../../../cli/quickstart.md) command:
    
         ```bash
         yc compute instance-group get <instance_group_name>
         ```
    
    - API {#api}
    
      Use the [update](../../instancegroup/api-ref/InstanceGroup/update.md) REST API method for the [InstanceGroup](../../instancegroup/api-ref/InstanceGroup/index.md) resource or the [InstanceGroupService/Update](../../instancegroup/api-ref/grpc/InstanceGroup/update.md) gRPC API call.
    
      If your instance group is a [manually scaled](../../concepts/instance-groups/scale.md#fixed-scale) one, specify a group size sufficient to place instances in all the selected availability zones. You will be able to reset the number of instances back to the initial one after all the instances in the group are moved to the new availability zone and deleted from the previous one.
    
      If your instance group is an [autoscaling](../../concepts/instance-groups/scale.md#auto-scale) one and has the `OPPORTUNISTIC` [shutdown strategy](../../concepts/instance-groups/policies/deploy-policy.md#strategy), change the strategy to `PROACTIVE`. You will be able to reset the shutdown strategy back to `OPPORTUNISTIC` after all the instances in the group are moved to the new availability zone and deleted from the previous one.
    
    {% endlist %}
    
    Wait until the instances appear in the new availability zone and get the `Running Actual` status.

1. Delete the group instances from the previous availability zone:

    {% list tabs group=instructions %}
    
    - Management console {#console}
    
      1. In the [management console](https://console.yandex.cloud), open the [folder](../../../resource-manager/concepts/resources-hierarchy.md#folder) containing the [instance group](../../concepts/instance-groups/index.md) you need.
      1. Navigate to **Compute Cloud**.
      1. In the left-hand panel, select ![image](../../../_assets/console-icons/layers-3-diagonal.svg) **Instance groups**.
      1. Select the instance group to update.
      1. In the top-right corner, click ![image](../../../_assets/console-icons/pencil.svg) **Edit**.
      1. Under **Allocation**, deselect the previous [availability zone](../../../overview/concepts/geo-scope.md).
      1. Click **Save**.
    
    - CLI {#cli}
    
      1. Open the [instance group](../../concepts/instance-groups/index.md) [specification](../../concepts/instance-groups/specification.md) file and edit the [instance template](../../concepts/instance-groups/instance-template.md):
         * Delete the previous availability zone from the `allocation_policy` section.
         * Delete the ID of the [subnet](../../../vpc/concepts/network.md#subnet) in the previous availability zone from the `network_interface_specs` section.
      1. Update the instance group:
    
         ```bash
         yc compute instance-group update \
           --id <instance_group_ID> \
           --file <instance_specification_file>
         ```
    
         Where:
         * `--id`: Instance group ID.
         * `--file`: Path to the instance group specification file.
    
         Result:
    
         ```text
         id: cl15sjqilrei********
         ...
         allocation_policy:
         zones:
         - zone_id: <new_availability_zone>
         ...
         ```
    
    - Terraform {#tf}
    
      1. Open the Terraform configuration file for the [instance group](../../concepts/instance-groups/index.md). Delete the previous [availability zone](../../../overview/concepts/geo-scope.md) from the `allocation_policy` section and the ID of the [subnet](../../../vpc/concepts/network.md#subnet) in the previous availability zone from the `network_interface` section:
    
         ```hcl
         ...
         network_interface {
           subnet_ids = ["<ID_of_subnet_in_new_availability_zone>"]
         }
         ...
         allocation_policy {
           zones = ["<new_availability_zone>"]
         }
         ...
         ```
    
         Where:
         * `zones`: Availability zone to move the instance group to. You can specify multiple availability zones.
         * `subnet_ids`: ID of the subnet in the availability zone you want to move your instance group to.
    
         For more information about resource properties in Terraform, see [this provider guide](../../../terraform/resources/compute_instance_group.md).
      1. Apply the changes:
    
         1. In the terminal, navigate to the configuration file directory.
         1. Make sure the configuration is correct using this command:
         
            ```bash
            terraform validate
            ```
         
            If the configuration is valid, you will get this message:
         
            ```bash
            Success! The configuration is valid.
            ```
         
         1. Run this command:
         
            ```bash
            terraform plan
            ```
         
            You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
         1. Apply the configuration changes:
         
            ```bash
            terraform apply
            ```
         
         1. Type `yes` and press **Enter** to confirm the changes.
    
         The group instances will be deleted from the previous availability zone. You can check the updates using the [management console](https://console.yandex.cloud) or this [CLI](../../../cli/quickstart.md) command:
    
         ```bash
         yc compute instance-group get <instance_group_name>
         ```
    
    - API {#api}
    
      Use the [update](../../instancegroup/api-ref/InstanceGroup/update.md) REST API method for the [InstanceGroup](../../instancegroup/api-ref/InstanceGroup/index.md) resource or the [InstanceGroupService/Update](../../instancegroup/api-ref/grpc/InstanceGroup/update.md) gRPC API call.
    
    {% endlist %}

### See also {#see-also}

* [Moving an instance group with a network load balancer to a different availability zone](move-group-with-nlb.md)
* [Moving an instance group with an L7 load balancer to a different availability zone](move-group-with-alb.md)