[Yandex Cloud documentation](../../index.md) > [Yandex Resource Manager](../index.md) > [Step-by-step guides](index.md) > Managing labels

# Managing labels

You can add, delete, or update resource [labels](../concepts/labels.md#services) in the management console, Yandex Cloud CLI, and Terraform.

Labels are supported in certain [services](../concepts/labels.md#services). Label management in some services, such as [Object Storage](../../storage/operations/buckets/tagging.md), may be different.

## Adding a label {#add-label}

{% list tabs group=instructions %}

- Management console {#console}

  The example below shows how to add a label to a Compute Cloud VM instance. You can add a label to another resource in the same way.

  1. In the [management console](https://console.yandex.cloud), click ![image](../../_assets/console-icons/layout-side-content-left.svg) or ![image](../../_assets/console-icons/chevron-down.svg) in the top panel and select the folder your VM is in.
  1. In the list of services, select **Compute Cloud**.
  1. In the left-hand panel, select ![image](../../_assets/console-icons/server.svg) **Virtual machines**.
  1. Select the VM you need from the list.
  1. Click ![horizontal-ellipsis](../../_assets/console-icons/ellipsis.svg) and select **Edit**.
  1. In the **Labels** field, click **Add label**.
  1. Enter the key and value, and press **Enter**.

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

  To add or update an existing service resource label, run this command:

  ```
  yc <service_name> <resource_type> add-labels <resource_name_or_ID> \
    --labels <label_name>=<label_value>
  ```

  **Example**

  Adding a label to a VM:

  > ```
  > yc compute instance add-labels cl123g4dridnn5cn****-**** --labels project=test
  > ```
  >
  > Result:
  >
  > ```
  > done (5s)
  > id: fhm1pr2bu3p4********
  > folder_id: b1g23ga45mev********
  > created_at: "2020-08-07T11:29:18Z"
  > name: cl123g4dridnn5cn****-****
  > labels:
  >   project: test
  > zone_id: ru-central1-a
  > ...
  > ```

- 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. In the configuration file, add the following fragment to the resource:

      ```
        labels = {
          <label_key> = "<label_value>"
        }
      ```

  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.

  That will add the label to the resource. You can check the new label using the [management console](https://console.yandex.cloud) or this [CLI](../../cli/quickstart.md) command:

  ```
  yc <service_name> <resource_type> get <resource_name_or_ID>
  ```

  **Example**

  Defining a label for a Yandex Lockbox secret:

  > ```
  > resource "yandex_lockbox_secret" "my_secret" {
  >   name   = lockbox-test-secret
  >   labels = {
  >     label-test-key = "label-test-value"
  >   }
  > }
  > ```

{% endlist %}

You can create a label with multiple values. For example, create a label named `my-cloud` with multiple values:

* `my-vm`: For the VM.
* `my-disk`: For the disk.

## Updating a label {#update-label}

You can only edit resource labels using the Yandex Cloud CLI and Terraform.

{% list tabs group=instructions %}

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

  {% note warning %}
  
  The existing labels (`labels`) will be completely overwritten by the ones you provide in your request.
  
  {% endnote %}

  To edit a label of a service resource, use this command:

  ```
  yc <service_name> <resource_type> update <resource_name_or_ID> \
    --labels <label_name>=<label_value>
  ```

  **Example**

  Editing labels for Kubernetes cluster:

  > ```
  > yc managed-kubernetes cluster update k8s-gpu --labels new_lable=test_label
  > ```
  >
  > Result:
  >
  > ```
  > done (1m36s)
  > id: cat1hknor234********
  > folder_id: b1g23ga45mev********
  > created_at: "2020-08-07T11:15:59Z"
  > name: cluster
  > labels:
  >   new_lable: test_label
  > status: RUNNING
  > ...
  > ```

- 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. In the configuration file, find the following fragment:

      ```
        labels = {
          <label_key> = <label_value>
        }
      ```

  1. Update both the key and the value.
  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.

  After that, the label for the resource will be updated. You can check the label update using the [management console](https://console.yandex.cloud) or this [CLI](../../cli/quickstart.md) command:

  ```
  yc <service_name> <resource_type> get <resource_name_or_ID>
  ```

{% endlist %}

## Deleting a label {#remove-label}

{% list tabs group=instructions %}

- Management console {#console}

  The example below shows how to delete a label from a Compute Cloud VM. You can delete a label from another resource in the same way.

  1. In the [management console](https://console.yandex.cloud), click ![image](../../_assets/console-icons/layout-side-content-left.svg) or ![image](../../_assets/console-icons/chevron-down.svg) in the top panel and select the folder your VM is in.
  1. In the list of services, select **Compute Cloud**.
  1. In the left-hand panel, select ![image](../../_assets/console-icons/server.svg) **Virtual machines**.
  1. Select the VM you need from the list.
  1. Click ![horizontal-ellipsis](../../_assets/console-icons/ellipsis.svg) and select **Edit**.
  1. In the **Labels** field, select the appropriate label and click ![cross](../../_assets/console-icons/xmark.svg) next to its name.

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

  Delete a service resource label:

  ```
  yc <service_name> <resource_type> remove-labels <resource_name_or_ID> \
    --labels <label_name>
  ```

  **Example**

  Removing a label from a Managed Service for MySQL® cluster:

  > ```
  > yc managed-mysql cluster remove-labels mysql123 --labels my_lable
  > ```
  >
  > Result:
  >
  > ```
  > id: c1qmjaatlurm********
  > folder_id: b1g23ga45mev********
  > created_at: "2020-08-20T11:53:20.015543Z"
  > name: mysql123
  > environment: PRODUCTION
  > ...
  > ```

- 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. In the configuration file, find the following fragment:

      ```
        labels = {
          <label_key> = "<label_value>"
        }
      ```

  1. Delete the fragment.
  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.

  After that, the label will be removed from the resource. You can check the deletion of the label using the [management console](https://console.yandex.cloud) or this [CLI](../../cli/quickstart.md) command:

  ```
  yc <service_name> <resource_type> get <resource_name_or_ID>
  ```

{% endlist %}