[Yandex Cloud documentation](../../index.md) > [Yandex Cloud Logging](../index.md) > [Step-by-step guides](index.md) > Managing a log group > Creating a log group

# Creating a log group

{% list tabs group=instructions %}

- Management console {#console}

    1. In the [management console](https://console.yandex.cloud), select the folder where you want to create a [log group](../concepts/log-group.md).
    1. [Go](../../console/operations/select-service.md#select-service) to **Cloud Logging**.
    1. Click **Create group**.
    1. Optionally, enter a name and description for the log group. Follow these naming requirements:

        * Length: between 3 and 63 characters.
        * It can only contain lowercase Latin letters, numbers, and hyphens.
        * It must start with a letter and cannot end with a hyphen.

    1. Set the log group record retention period.

    1. Optionally, select a [data stream](../../data-streams/concepts/glossary.md#stream-concepts) or create a new one to which the records added to your log group will be redirected.


    1. Click **Create group**.

- 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 create a [log group](../concepts/log-group.md), run this command:

    ```
    yc logging group create \
      --name=group \
      --retention-period=1h \
      --data-stream=<stream_ID>
    ```

    Where:
    * `--name`: Log group name.
    * `--retention-period`: Retention period for log group records. This is an optional setting.

        You can only set the record retention period in hours, minutes, or seconds, e.g., `1h` or `1440m`.

    * `--data-stream`: [Data stream](../../data-streams/concepts/glossary.md#stream-concepts) ID in Yandex Data Streams. This is an optional setting. The specified stream will automatically receive the records added to your log group. A stream ID comprises the availability zone, folder ID, Yandex Managed Service for YDB database ID, and stream name.

        >For example, your stream ID will appear as `/ru-central1/aoeu1kuk2dht********/cc8029jgtuab********/aws_stream` if:
        >* `aws_stream`: Stream name.
        >* `ru-central1`: Availability zone.
        >* `aoeu1kuk2dht********`: Folder ID.
        >* `cc8029jgtuab********`: Yandex Managed Service for YDB database ID.


    Result:

    ```
    done (1s)
    id: af3flf29t8**********
    folder_id: aoek6qrs8t**********
    cloud_id: aoegtvhtp8**********
    created_at: "2023-06-24T09:56:38.970Z"
    name: group
    status: ACTIVE
    retention_period: 3600s
    data_stream: /ru-central1/aoeu1kuk2dht********/cc8029jgtuab********/aws_stream
    ```

- 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 configuration file, describe the resources you want to create:

     * `name`: [Log group](../concepts/log-group.md) name. This is an optional setting. Use the following name format:

          * Length: between 3 and 63 characters.
          * It can only contain lowercase Latin letters, numbers, and hyphens.
          * It must start with a letter and cannot end with a hyphen.

     * `folder_id`: [Folder ID](../../resource-manager/operations/folder/get-id.md). This is an optional setting. It defaults to the value specified in the provider settings.

     * `retention_period`: Retention period for log group records. This is an optional setting.

         You can only set the record retention period in hours, minutes, or seconds, e.g., `1h` or `1440m`.

     Here is an example of the configuration file structure:

     ```hcl
     resource "yandex_logging_group" "group1" {
       name             = "<log_group_name>"
       folder_id        = "<folder_ID>"
       retention_period = "5h"
     }
     ```

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

  1. Make sure the configuration files are correct.

     1. In the terminal, navigate to the directory where you created your configuration file.
     1. Run a check using this command:

        ```
        terraform plan
        ```

     If the configuration is correct, the terminal will display a list of the resources and their settings. Otherwise, Terraform will show any detected errors. 

  1. Deploy the cloud resources.

     1. If the configuration is correct, run this command:

        ```
        terraform apply
        ```

     1. Confirm creating the resources by typing `yes` and pressing **Enter**.

     This will create all the resources you need in the specified folder. You can check the new resources and their settings using the [management console](https://console.yandex.cloud) or this [CLI](../../cli/quickstart.md) command:

        ```
        yc logging group list
        ```

- API {#api}

  To create a [log group](../concepts/log-group.md), use the [create](../api-ref/LogGroup/create.md) REST API method for the [LogGroup](../api-ref/LogGroup/index.md) resource or the [LogGroupService/Create](../api-ref/grpc/LogGroup/create.md) gRPC API call.

  **Request example**

  The example below uses `grpcurl`. To run this example, [authenticate](../api-ref/authentication.md) with the API and clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository.

  Create a file named `payload.json`:

  ```json
  {
     "folder_id": "<folder_ID>",
     "name": "new-group",
     "description": "Description of a log group created with grpcurl",
     "labels": {
       "compute": "instance-logging"
     }
  }
  ```

  Send this request:

  ```bash
  grpcurl -rpc-header "Authorization: Bearer $(yc iam create-token)" \
    -d @ \
    -import-path ~/cloudapi/ \
    -import-path ~/cloudapi/third_party/googleapis/ \
    -proto ~/cloudapi/yandex/cloud/logging/v1/log_group_service.proto \
  logging.api.cloud.yandex.net:443 yandex.cloud.logging.v1.LogGroupService.Create < payload.json
  ```

  Response:

  ```text
  {
    "id": "e23nitus5cg9********",
    "description": "Create log group",
    "createdAt": "2023-11-23T14:54:23.077532292Z",
    "createdBy": "ajeugsk5ubk6********",
    "modifiedAt": "2023-11-23T14:54:23.077532292Z",
    "metadata": {
      "@type": "type.googleapis.com/yandex.cloud.logging.v1.CreateLogGroupMetadata",
      "logGroupId": "e23pjn86385t********"
    }
  }
  ```

{% endlist %}