[Yandex Cloud documentation](../../../index.md) > [Yandex IoT Core](../../index.md) > [Step-by-step guides](../index.md) > Managing brokers > Creating a broker

# Creating a broker

{% note warning %}

Yandex IoT Core is no longer available to new users. 

Current users can create resources until November 1, 2026. Afterwards, the service will go read-only and cease to operate on December 1, 2026. For more information on the timing and procedure, see [Service shutdown](../../sunset.md).

{% endnote %}

{% note info %}

The broker is at the [Preview](../../../overview/concepts/launch-stages.md) stage.

{% endnote %}

{% 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 broker.
  1. Navigate to **IoT Core**.
  1. In the left-hand panel, select **Brokers**.
  1. Click **Create broker**.
  1. Under **General information**, specify:

      * Broker **Name**, e.g., `my-broker`.
      * (Optional) **Description**: Additional information about the broker.
      * (Optional) **Password** if you are going to use it instead of a certificate to access the broker. To create a password, you can use [this password generator](https://passwordsgenerator.net/).

          {% note info %}

          Make sure to save your password, as you will need it for [authentication](../../concepts/authorization.md).

          {% endnote %}

      * (Optional) To assign a label to the broker, fill in the **Key** and **Value** fields and click **Add label**.

  1. (Optional) Add a [certificate](../certificates/create-certificates.md):

      * To add a file:

          1. Select the `File` method.
          1. Click **Attach file**.
          1. Select the file with the public key of the certificate and click **Open**.
          1. Click **Add**.

      * To add text:

          1. Select the `Text` method.
          1. Paste the certificate's public key to the **Content** field.
          1. Click **Add**.

  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. Create a broker:

      ```bash
      yc iot broker create --name <broker_name>
      ```

      The naming requirements are as follows:

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

      Result:

      ```text
      id: b91ki3851h**********
      folder_id: aoek49ghmk*********
      created_at: "2022-05-28T11:29:42.420Z"
      name: <broker_name>
      status: ACTIVE
      ```

  1. (Optional) Assign the broker a password for authentication with a [username and password](../../concepts/authorization.md#log-pass):

      ```bash
      yc iot broker password add --broker-name <broker_name>
      ```

      You will be prompted to enter a password. Password requirements:

      * The password must contain numbers, upper-case and lower-case letters, and special characters.
      * It must be at least 14 characters long.

      Result:

      ```text
      broker_id: b91ki3851h**********
      id: aoek49ghmk*********
      created_at: "2022-05-28T11:32:42.420Z"
      ```

  1. (Optional) Add to the broker a certificate for authentication with [certificates](../../concepts/authorization.md#certs):

      ```bash
      yc iot broker certificate add \
         --broker-name <broker_name> \
         --certificate-file <certificate>
      ```

      Where:

      * `--broker-name`: Broker name.
      * `--certificate-file`: Path to the public key of the certificate, such as `cert.pem`.

      Result:

      ```text
      broker_id: b91ki3851h**********
      fingerprint: 1f21cf6d0183d****
      certificate_data: |
         -----BEGIN CERTIFICATE-----
         MIIEpDCCAow...
         -----END CERTIFICATE-----
      created_at: "2023-07-11T16:20:53.466370019Z"
      ```

- 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.
   
  {% note info %}

  To add certificates to a broker, [generate](../certificates/create-certificates.md) them in advance.

  {% endnote %}

  To create a broker:
     
  1. In the configuration file, describe the resource you want to create:

     * `yandex_iot_core_broker`: Broker parameters:
       * `name`: Broker name.
       * `description`: Broker description.
       * `labels`: Broker labels in `key:value` format.
       * `certificates`: List of broker certificates for authentication with [certificates](../certificates/create-certificates.md).

      Here is an example of the resource structure in the configuration file:
      
      ```
      resource "yandex_iot_core_broker" "my_broker" {
        name        = "test-broker"
        description = "test broker for terraform provider documentation"
        labels = {
          test-label = "label-test"
        }

        certificates = [
          file("<path_to_first_certificate_file>"),
          file("<path_to_second_certificate_file>")
        ]
      }

      output "yandex_iot_core_broker_my_broker" {
        value = "${yandex_iot_core_broker.my_broker.id}"
      }
      ```

      For more information about resources you can create with Terraform, see [this provider guide](../../../terraform/resources/iot_core_broker.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.
      
          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:

          ```bash
          yc iot broker list
          ```

- API {#api}

  To create a broker, use the [create](../../broker/api-ref/Broker/create.md) REST API method for the [Broker](../../broker/api-ref/Broker/index.md) resource or the [BrokerService/Create](../../broker/api-ref/grpc/Broker/create.md) gRPC API call.

{% endlist %}