[Yandex Cloud documentation](../../index.md) > [Yandex Application Load Balancer](../index.md) > [Step-by-step guides](index.md) > Target groups > Creating a target group

# Creating an Application Load Balancer target group

Create [VMs](../../compute/concepts/vm.md) in your previously selected [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) by following [this guide](../../compute/operations/index.md#vm-create).

To create a [target group](../concepts/target-group.md):

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder where you want to create your target group.
  1. Navigate to **Application Load Balancer**.
  1. In the left-hand panel, select ![image](../../_assets/console-icons/target.svg) **Target groups**.
  1. Click **Create target group**.
  1. Specify the target group name and description.
  1. Under **Targets**, select a VM from the list or add the target manually:
     1. In the **IP address** field, specify the target's IP and select its [subnet](../../vpc/concepts/network.md#subnet).
     1. Optionally, if the target's [IP address](../../vpc/concepts/address.md) does not belong to [Yandex Virtual Private Cloud](../../vpc/index.md), select **Outside VPC**.

        For example, you can specify a private IPv4 address from your data center connected to Yandex Cloud through [Yandex Cloud Interconnect](../../interconnect/index.md). This IP address must belong to the [RFC 1918 private address range](https://datatracker.ietf.org/doc/html/rfc1918#section-3). For more information, see [Subnets](../../vpc/concepts/network.md#subnet).


     1. Click **Add target resource**.
  1. Click **Create**.

- 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](../../cli/index.md) command for creating a target group:

     ```bash
     yc alb target-group create --help
     ```

  1. Run this command, with the target group name, [subnet](../../vpc/concepts/network.md#subnet) name, and VM’s [internal IP addresses](../../vpc/concepts/address.md#internal-addresses) specified:

     ```bash
     yc alb target-group create \
       --name <target_group_name> \
       --target subnet-name=<subnet_name>,ip-address=<VM_1_internal_IP_address> \
       --target subnet-name=<subnet_name>,ip-address=<VM_2_internal_IP_address> \
       --target subnet-name=<subnet_name>,ip-address=<VM_3_internal_IP_address>
     ```

     Result:

      ```text
      id: a5d751meibht********
      name: <target_group_name>
      folder_id: aoerb349v3h4********
      targets:
      - ip_address: <VM_1_internal_IP_address>
        subnet_id: fo2tgfikh3he********
      - ip_address: <VM_2_internal_IP_address>
        subnet_id: fo2tgfikh3he********
      - ip_address: <VM_3_internal_IP_address>
        subnet_id: fo2tgfikh3he********
      created_at: "2021-02-11T11:16:27.770674538Z
      ```

      You can also create a target group with resources outside [Yandex Virtual Private Cloud](../../vpc/index.md), e.g., in your data center connected to Yandex Cloud via [Yandex Cloud Interconnect](../../interconnect/index.md). Target IP addresses must belong to the [RFC 1918 private address range](https://datatracker.ietf.org/doc/html/rfc1918#section-3). For more information, see [Subnets](../../vpc/concepts/network.md#subnet).


      Run this command, with the target group name and resource’s private IPv4 addresses specified:

      ```bash
      yc alb target-group create \
        --name <target_group_name> \
        --target private-ip-address=true,ip-address=<resource_1_IPv4_private_address> \
        --target private-ip-address=true,ip-address=<resource_2_IPv4_private_address> \
        --target private-ip-address=true,ip-address=<resource_3_IPv4_private_address>
      ```

      Result:

      ```text
      id: ds7s2dld2usr********
      name: <target_group_name>
      folder_id: aoerb349v3h4********
      targets:
        - ip_address: <resource_1_IPv4_private_address>
          private_ipv4_address: true
        - ip_address: <resource_2_IPv4_private_address>
          private_ipv4_address: true
        - ip_address: <resource_3_IPv4_private_address>
          private_ipv4_address: true
      created_at: "2023-07-25T08:55:14.172526884Z"
      ```

- Terraform {#tf}

  With [Terraform](https://www.terraform.io/), you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
  
  Terraform is distributed under the [Business Source License](https://github.com/hashicorp/terraform/blob/main/LICENSE). The [Yandex Cloud provider for Terraform](https://github.com/yandex-cloud/terraform-provider-yandex) is distributed under the [MPL-2.0](https://www.mozilla.org/en-US/MPL/2.0/) license.
  
  For more information about the provider resources, see the guides on the [Terraform](https://www.terraform.io/docs/providers/yandex/index.html) website or [its mirror](../../terraform/index.md).

  If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
  
  
  To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../terraform/authentication.md) using the appropriate method.

  1. In the Terraform configuration file, describe the resource you want to create:

     ```hcl
     resource "yandex_alb_target_group" "foo" {
       name           = "<target_group_name>"

       target {
         subnet_id    = "<subnet_ID>"
         ip_address   = "<VM_1_internal_IP_address>"
       }

       target {
         subnet_id    = "<subnet_ID>"
         ip_address   = "<VM_2_internal_IP_address>"
       }

       target {
         subnet_id    = "<subnet_ID>"
         ip_address   = "<VM_3_internal_IP_address>"
       }
     }
     ```

     Where `yandex_alb_target_group` specifies target group settings:
     * `name`: Target group name.
     * `target`: Target settings:
       * `subnet_id`: ID of the [subnet](../../vpc/concepts/network.md#subnet) hosting the VM. You can get the list of available subnets using the `yc vpc subnet list` [CLI](../../cli/index.md) command.
       * `ip_address`: VM internal IP address. You can get the list of [internal IP addresses](../../vpc/concepts/address.md#internal-addresses) using the following CLI command: `yc vpc subnet list-used-addresses --id <subnet_ID>`.

     You can also create a target group with resources outside [Yandex Virtual Private Cloud](../../vpc/index.md), e.g., in your data center connected to Yandex Cloud via [Yandex Cloud Interconnect](../../interconnect/index.md):

     ```hcl
     resource "yandex_alb_target_group" "foo" {
       name                   = "<target_group_name>"

       target {
         private_ipv4_address = true
         ip_address           = "<resource_1_IPv4_private_address>"
       }

       target {
         private_ipv4_address = true
         ip_address           = "<resource_2_IPv4_private_address>"
       }

       target {
         private_ipv4_address = true
         ip_address           = "<resource_3_IPv4_private_address>"
       }
     }
     ```


     Where `yandex_alb_target_group` specifies target group settings:
     * `name`: Target group name.
     * `target`: Target settings:
       * `private_ipv4_address`: Setting indicating that the IP address is outside Virtual Private Cloud.
       * `ip_address`: Resource’s private IPv4 address. This IP address must belong to the [RFC 1918 private address range](https://datatracker.ietf.org/doc/html/rfc1918#section-3). For more information, see [Subnets](../../vpc/concepts/network.md#subnet).

     For more information about `yandex_alb_target_group` properties, see [this Terraform provider guide](../../terraform/resources/alb_target_group.md).
  1. Create the resources:

     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.

     Terraform will create all the required resources. You can check the new resources in the [management console](https://console.yandex.cloud) or using this [CLI](../../cli/index.md) command:

     ```bash
     yc alb target-group list
     ```

     {% note warning "Timeouts" %}
     
     The Terraform provider limits operations with Application Load Balancer target groups 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 target group description, e.g.:
     
     ```hcl
     resource "yandex_alb_target_group" "<target_group_name>" {
       ...
       timeouts {
         create = "60m"
         update = "60m"
         delete = "60m"
       }
     }
     ```
     
     {% endcut %}
     
     {% endnote %}

- API {#api}

  Use the [create](../api-ref/TargetGroup/create.md) REST API method for the [TargetGroup](../api-ref/TargetGroup/index.md) resource or the [TargetGroupService/Create](../api-ref/grpc/TargetGroup/create.md) gRPC API call.

{% endlist %}

#### Useful links {#see-also}

* [Fault-tolerant website with load balancing via a Yandex Application Load Balancer](../tutorials/application-load-balancer-website/index.md)
* [Writing load balancer logs to PostgreSQL](../tutorials/logging.md)
* [Creating an L7 load balancer with DDoS protection using the management console or CLI](../tutorials/alb-with-ddos-protection/console.md)