[Yandex Cloud documentation](../../index.md) > [Yandex Application Load Balancer](../index.md) > [Step-by-step guides](index.md) > L7 load balancers > Editing an L7 load balancer

# Editing an L7 load balancer

To change L7 load balancer settings:

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder the load balancer is in.
  1. Navigate to **Application Load Balancer**.
  1. Click your load balancer's name.
  1. Click ![image](../../_assets/console-icons/ellipsis.svg) and select **Edit**.
  1. Edit the load balancer settings:

      1. Under **Network settings**, change the [security groups](../concepts/application-load-balancer.md#security-groups):

          * `No groups`: Allows any incoming and outgoing traffic for the load balancer. This is the least secure option.
          * `Auto`: The load balancer creation process automatically provisions a security group allowing any incoming traffic on port `80` and TCP health check traffic on port `30080`. This security group also allows any outgoing traffic from the load balancer.
          * `From list`: For more traffic management flexibility, [create](../../vpc/operations/security-group-create.md) your own security groups. You can assign up to five security groups to your load balancer.

          {% note info %}
          
            Security group rules must specify IP ranges in CIDR format. You cannot assign a group that uses a different security group.
          
            {% endnote %}

      1. Under **Allocation**, enable or disable incoming traffic for each [availability zone](../../overview/concepts/geo-scope.md) using the **Receive traffic** option.

      1. Under **Autoscaling settings**, set the [resource unit](../concepts/application-load-balancer.md#lcu-scaling) limit.

      1. Under **Log settings**:

          1. Change the Cloud Logging [log group](../../logging/concepts/log-group.md) storing your load balancer logs.
          1. Edit [log discard rules](../concepts/application-load-balancer.md#discard-logs-rules):
    
              * **HTTP codes**: Update the HTTP status codes.
              * **HTTP code classes**: Update the HTTP status code classes.
              * **gRPC codes**: Update the gRPC codes.
              * **Share of discarded logs**: Update the log discard rate.
    
              To add another rule, click **Add discard rule**.
    
      1. Under **Listeners**, change listener settings.

  1. At the bottom of the page, 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 updating load balancer settings:

     ```bash
     yc alb load-balancer update --help
     ```

  1. Run this command with new load balancer settings specified. For example, specify the load balancer [security groups](../concepts/application-load-balancer.md#security-groups):

     ```bash
     yc alb load-balancer update <load_balancer_name> \
       --security-group-id <list_of_security_group_IDs>
     ```

     Where `--security-group-id` is a comma separated list of one to five new [security group](../concepts/application-load-balancer.md#security-groups) IDs. If you skip it, the load balancer will accept all traffic.

     Result:

     ```bash
     id: a5d88ep483cm********
     name: test-balancer2-updated
     folder_id: aoe197919j8e********
     status: ACTIVE
     region_id: ru-central1
     network_id: c64l1c06d151********
     listeners:
     - name: test-listener
       endpoints:
       - addresses:
         - external_ipv4_address:
             address: 130.193.32.206
         ports:
         - "80"
       http:
         handler:
           http_router_id: a5dv7tjdo9gt********
     allocation_policy:
       locations:
       - zone_id: ru-central1-a
         subnet_id: buc4gsmpj8hv********
     log_group_id: eolul9ap0bv0********
     security_group_ids:
       - enpulh2tbrep********
       - enpg05a3ck35********
     created_at: "2021-04-26T12:12:13.624832586Z"
     ```

  1. Optionally, update the [Yandex Cloud Logging](../../logging/index.md) [logging](../logs-ref.md) settings:

      1. See the description of the CLI command for managing load balancer logging:

          ```bash
          yc alb load-balancer logging --help
          ```

      1. Add a new log discard rule:

          ```bash
          yc alb load-balancer logging <load_balancer_name> \
            --log-group-id <log_group_ID> \
            --enable \
            --discard codes=[200,3XX,GRPC_OK],percent=90
          ```

          Where:

          * `--log-group-id`: [Log group](../../logging/concepts/log-group.md) ID.
          * `--discard`: [Log discard rule](../concepts/application-load-balancer.md#discard-logs-rules). Rule options:
            * `codes`: HTTP codes, HTTP code classes, or gRPC codes.
            * `percent`: Log discard rate.

          Result:

          ```text
          done (42s)
          id: ds76g2zpgp3f********
          name: test-load-balancer
          folder_id: b1gug7dbelh********
          ...
          log_options:
            log_group_id: e23p9bcvh6gr********
            discard_rules:
              - http_codes:
                  - "200"
                http_code_intervals:
                  - HTTP_3XX
                grpc_codes:
                  - OK
                discard_percent: "90"
          ```

  1. Specify new listener settings:

     * HTTP listener:

       1. See the description of the CLI command for updating L7 load balancer HTTP listener settings:

          ```bash
          yc alb load-balancer update-listener --help
          ```

       1. Run this command with new listener settings specified:

          ```bash
          yc alb load-balancer update-listener <load_balancer_name> \
            --listener-name <listener_name> \
            --http-router-id <HTTP_router_ID> \
            --external-ipv4-endpoint port=<listener_port>
          ```

     * Stream listener:

       1. See the description of the CLI command for updating the L7 load balancer Stream listener settings:

          ```bash
          yc alb load-balancer update-stream-listener --help
          ```

       1. Run this command with new listener settings specified:

          ```bash
          yc alb load-balancer update-stream-listener <load_balancer_name> \
            --listener-name=<listener_name> \
            --backend-group-id=<backend_group_ID> \
            --external-ipv4-endpoint port=<listener_port>
          ```

     The result of updating two listeners:

     ```bash
     done (42s)
     id: ds76g8b2op3f********
     name: test-load-balancer
     folder_id: b1gu6g9ielh6********
     status: ACTIVE
     network_id: enp0uulja5s3********
     listeners:
     - name: tslistener
       endpoints:
       - addresses:
         - external_ipv4_address:
             address: 51.250.64.197
         ports:
         - "80"
       http:
         handler:
           http_router_id: ds7d7b14b3fs********
     - name: teststreamlistener
       endpoints:
       - addresses:
         - external_ipv4_address:
             address: 51.250.64.197
         ports:
         - "443"
       stream:
         handler:
           backend_group_id: ds77tero4f5h********
     allocation_policy:
       locations:
       - zone_id: ru-central1-a
         subnet_id: e9bs1hp7lgdl********
     log_group_id: ckgs4u5km3u8********
     security_group_ids:
     - enp49ot04g63********
     created_at: "2022-04-04T02:12:40.160629110Z"
     log_options:
       log_group_id: e23p9bfjvsgr********
       discard_rules:
         - http_codes:
             - "200"
           http_code_intervals:
             - HTTP_3XX
           grpc_codes:
             - OK
           discard_percent: "90"
     ```

  1. Optinally, update the [resource unit](../concepts/application-load-balancer.md#lcu-scaling) limit:

     1. See the description of the CLI command for setting up limits:
     
        ```bash
        yc alb load-balancer autoscale --help
        ```
     
     1. Specify limits by running this command:
     
        ```bash
        yc alb load-balancer autoscale <load_balancer_name_or_ID> \
          --min-zone-size <resource_unit_minimum_per_zone> \
          --max-size <resource_unit_maximum_total>
        ```
     
        Where:
     
        * `--min-zone-size`: Resource unit minimum per availability zone The default minimum is 2. You cannot set a minimum below 2.
        * `--max-size`: Resource unit maximum total. By default, it is unlimited. Make sure this value is no less than (number of load balancer availability zones) × (minimum number of resource units per zone).
     
        You can specify one or both settings at once using this command.
     
        For example:
     
        ```bash
        yc alb load-balancer autoscale test-balancer2 \
          --min-zone-size 3 \
          --max-size 10
        ```
     
        Result:
     
        ```text
        id: a5d88ep483cm********
        name: test-balancer2
        folder_id: aoe197919j8e********
        status: ACTIVE
        region_id: ru-central1
        network_id: c64l1c06d151********
        allocation_policy:
          locations:
            - zone_id: ru-central1-a
              subnet_id: buc4gsmpj8hv********
        created_at: "2022-06-02T12:12:13.624832586Z"
        auto_scale_policy:
          min_zone_size: 3
          max_size: 10
        ```

- 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).
  
  
  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. Open the Terraform configuration file and edit the fragment describing the L7 load balancer:

     ```hcl
     ...
     resource "yandex_alb_load_balancer" "test-balancer" {
       name        = "my-load-balancer"
       network_id  = yandex_vpc_network.test-network.id

       allocation_policy {
         location {
           zone_id   = "ru-central1-a"
           subnet_id = yandex_vpc_subnet.test-subnet.id
           security_group_ids = ["<list_of_security_group_IDs>"]
         }
       }

       listener {
         name = "my-listener"
         endpoint {
           address {
             external_ipv4_address {
             }
           }
           ports = [ 9000 ]
         }
         http {
           handler {
             http_router_id = yandex_alb_http_router.test-router.id
           }
         }
       }

       log_options {
         log_group_id = "<log_group_ID>"
         discard_rule {
           http_codes          = ["200"]
           http_code_intervals = ["HTTP_2XX"]
           grpc_codes          = ["GRPC_OK"]
           discard_percent     = 15
         }
       }
     }
     ...
     ```

     For more information about `yandex_alb_load_balancer` properties in Terraform, see [this provider guide](../../terraform/resources/alb_load_balancer.md).

  1. Check the configuration 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 changes.

     You can check whether the L7 load balancer configuration was updated correctly in the [management console](https://console.yandex.cloud) or using this [CLI](../../cli/quickstart.md) 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 %}

## Deleting a listener {#delete-listener}

To delete a listener from your L7 load balancer:

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder the load balancer is in.
  1. Navigate to **Application Load Balancer**.
  1. Click ![image](../../_assets/console-icons/ellipsis.svg) next to the load balancer and select **Edit**.
  1. Under **Listeners**, next to the appropriate listener name, click ![image](../../_assets/console-icons/ellipsis.svg) and select **Delete**.
  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 deleting a listener:

     ```bash
     yc alb load-balancer remove-listener --help
     ```

  1. Run this command:

     ```bash
     yc alb load-balancer remove-listener <load_balancer_name_or_ID> \
       --listener-name=<listener_name>
     ```

     Result:

     ```text
     done (50s)
     ```

- 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).
  
  
  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. Open the Terraform configuration file and delete the `listener` section from the L7 load balancer description.

     ```hcl
     ...
     resource "yandex_alb_load_balancer" "test-balancer" {
       name        = "my-load-balancer"
       network_id  = yandex_vpc_network.test-network.id

       allocation_policy {
         location {
           zone_id   = "ru-central1-a"
           subnet_id = yandex_vpc_subnet.test-subnet.id
         }
       }

       listener {
         name = "my-listener"
         endpoint {
           address {
             external_ipv4_address {
             }
           }
           ports = [ 9000 ]
         }
         http {
           handler {
             http_router_id = yandex_alb_http_router.test-router.id
           }
         }
       }
     }
     ...
     ```

     For more information about `yandex_alb_load_balancer` properties in Terraform, see [this provider guide](../../terraform/resources/alb_load_balancer.md).

  1. Validate your configuration 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 changes.

     You can check whether the L7 load balancer configuration was updated correctly in the [management console](https://console.yandex.cloud) or using this [CLI](../../cli/quickstart.md) command:

     ```bash
     yc alb load-balancer get <L7_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 [removeListener](../api-ref/LoadBalancer/removeListener.md) REST API method for the [LoadBalancer](../api-ref/LoadBalancer/index.md) resource or the [LoadBalancerService/RemoveListener](../api-ref/grpc/LoadBalancer/removeListener.md) gRPC API call.

{% endlist %}