[Yandex Cloud documentation](../../index.md) > [Yandex Application Load Balancer](../index.md) > [Step-by-step guides](index.md) > L7 load balancers > Moving a VM to a target group in a different availability zone

# Moving a VM to a target group in a new availability zone


To move an [L7 load balancer](../concepts/application-load-balancer.md) backend [VM](../../compute/concepts/vm.md) to a [target group](../concepts/target-group.md) in a new [availability zone](../../overview/concepts/geo-scope.md):

1. Enable load balancer traffic in the new availability zone:

    {% list tabs group=instructions %}

    - Management console {#console}

      1. In the [management console](https://console.yandex.cloud), select the folder with your load balancer.
      1. Navigate to **Application Load Balancer**.
      1. Click ![image](../../_assets/console-icons/ellipsis.svg) next to the load balancer you need, then select **Edit**.
      1. In the window that opens, under **Allocation**, enable traffic in the availability zone where you plan to move your VM.
      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. See the description of the CLI command for enabling load balancer traffic:

          ```bash
          yc application-load-balancer load-balancer enable-traffic --help
          ```

      1. Get a list of all L7 load balancers in the default folder:

          ```bash
          yc application-load-balancer load-balancer list
          ```

          Result:

          ```text
          +----------------------+-----------------------+-------------+----------------+---------+
          |          ID          |         NAME          |  REGION ID  | LISTENER COUNT | STATUS  |
          +----------------------+-----------------------+-------------+----------------+---------+
          | ds732hi8pn9n******** |      sample-alb1      | ru-central1 |              1 |  ACTIVE |
          | f3da23i86n2v******** |      sample-alb2      | ru-central1 |              1 |  ACTIVE |
          +----------------------+-----------------------+-------------+----------------+---------+
          ```

      1. Enable traffic in the new availability zone:

          ```bash
          yc application-load-balancer load-balancer enable-traffic <load_balancer_name> \
            --zone <availability_zone>
          ```

          Where `--zone` is the availability zone where you plan to move your VMs.

          Result:

          ```text
          id: ds7pmslal3km********
          name: sample-alb1
          folder_id: b1gmit33ngp3********
          status: ACTIVE
          region_id: ru-central1
          network_id: enpn46stivv8********
          allocation_policy:
            locations:
              - zone_id: ru-central1-a
                subnet_id: e9bavnqlbiuk********
                disable_traffic: true
              - zone_id: ru-central1-b
                  subnet_id: e2lgp8o00g06********
              - zone_id: ru-central1-d
                  subnet_id: b0cv501fvp13********
          log_group_id: ckgah4eo2j0r********
          security_group_ids:
            - enpdjc5bitmj********
          created_at: "2023-08-09T08:34:24.887765763Z"
          log_options: {}
          ```

    - 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 L7 load balancer configuration file and, under `allocation_policy`, specify the new availability zone and the ID of the previously created subnet:

         ```hcl
         ...
           allocation_policy {
             location {
               zone_id   = [
                 "<previous_availability_zone>",
                 "<new_availability_zone>"
               ]
               subnet_id = [
                 "<subnet_ID_in_previous_availability_zone>",
                 "<ID_of_subnet_in_new_availability_zone>"
               ]
             }
           }
         }
         ...
         ```

         Where:
         * `zone_id`: Availability zones where the load balancer will receive traffic.
         * `subnet_id`: IDs of the subnets in these availability zones.

         For more information about resource properties in Terraform, see the [relevant provider documentation](../../terraform/resources/alb_load_balancer.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 load balancer will start receiving traffic in the new availability zone. You can check this in the [management console](https://console.yandex.cloud) or using this CLI command:

         ```bash
         yc alb load-balancer get <load_balancer_name>
         ```

         {% note warning "Timeouts" %}
         
         The Terraform provider limits operations with Application Load Balancer load balancers to 10 minutes.
         
         Operations in excess of this time will be interrupted.
         
         {% cut "How do I modify these limits?" %}
         
         Add the `timeouts` section to the load balancer description, e.g.:
         
         ```hcl
         resource "yandex_alb_load_balancer" "<load_balancer_name>" {
           ...
           timeouts {
             create = "60m"
             update = "60m"
             delete = "60m"
           }
         }
         ```
         
         {% endcut %}
         
         {% endnote %}

   - API {#api}

     Use the [update](../api-ref/LoadBalancer/update.md) REST API method for the [LoadBalancer](../api-ref/LoadBalancer/index.md) resource or the [LoadBalancerService/Update](../api-ref/grpc/LoadBalancer/update.md) gRPC API call.

   {% endlist %}

1. [Set up](../../vpc/operations/security-group-add-rule.md) a [security group](../../vpc/concepts/security-groups.md) for the load balancer if needed. For proper load balancer operation, its security groups must allow outbound connections to the subnet addresses in your VM’s new availability zone.
1. [Move](../../compute/operations/vm-control/vm-change-zone.md) your VM to the new availability zone.
1. [Add](target-group-update.md#add-targets) new VMs to the load balancer's target group and [delete](target-group-update.md#remove-targets) the old ones.
1. Make sure the load balancer identifies your VM status as `HEALTHY`:

   {% list tabs group=instructions %}

   - Management console {#console}

     1. In the [management console](https://console.yandex.cloud), select the folder with your load balancer.
     1. Navigate to **Application Load Balancer**.
     1. Select the load balancer you need.
     1. Navigate to the ![image](../../_assets/console-icons/heart-pulse.svg) **Health checks** tab.
     1. Expand the list of targets. Make sure the target group VMs have the `HEALTHY` [status](../../compute/concepts/vm-statuses.md).

   - API {#api}

     Use the [getTargetStates](../api-ref/LoadBalancer/getTargetStates.md) REST API method for the [LoadBalancer](../api-ref/LoadBalancer/index.md) resource or the [LoadBalancerService/GetTargetStates](../api-ref/grpc/LoadBalancer/getTargetStates.md) gRPC API call.

   {% endlist %}

   The load balancer will not recognize a VM [status](../../compute/concepts/vm-statuses.md) as `HEALTHY` immediately after adding it to the target group. This may take a few minutes depending on your backend settings.

   If the load balancer consistently identifies your VM status as `UNHEALTHY` over an extended period, check its [security group](../concepts/application-load-balancer.md#security-groups) configuration.