[Yandex Cloud documentation](../../index.md) > [Yandex Cloud DNS](../index.md) > [Step-by-step guides](index.md) > Zones > Moving a DNS zone to a different folder

# Moving a DNS zone to a different folder

When you create a [DNS zone](../concepts/dns-zone.md), it is placed in the current folder.

In Yandex Cloud, you can move a DNS zone to a different folder.

Learn more about the Yandex Cloud resource hierarchy [here](../../resource-manager/concepts/resources-hierarchy.md).

## Limits {#limits}

Moving a DNS zone does not relocate its [Yandex Monitoring](../../monitoring/index.md) metrics: existing metrics remain in the source folder, and new metrics will be created in the destination folder.

## Moving a DNS zone {#relocate-zone}

### Updating a DNS zone folder {#change-folder}

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

  1. Get a list of all DNS zones in the default folder:

      ```bash
      yc dns zone list
      ```

      Result:

      ```bash
      +----------------------+---------------------+--------------+----------------------------------------------------+
      |          ID          |        NAME         |     ZONE     |   VISIBILITY   |             DESCRIPTION           |
      +----------------------+---------------------+--------------+----------------+-----------------------------------+
      | aet29qhara5j******** | my-public-zone      | example.com. | PUBLIC         | Automatically created DNS for ... |
      | aet2q4fn8i8i******** | my-private-zone     | internal.    | PRIVATE        | Automatically created DNS for ... |
      +----------------------+---------------------+--------------+----------------+-----------------------------------+
      ```      

  1. Get a list of all folders in the default cloud:

      ```bash
      yc resource-manager folder list
      ```

      Result:

      ```bash
      +----------------------+--------------------+------------------+--------+
      |          ID          |        NAME        |      LABELS      | STATUS |
      +----------------------+--------------------+------------------+--------+
      | b1gd129pp9ha******** | my-folder          |                  | ACTIVE |
      | b1g66mft1vop******** | default            |                  | ACTIVE |
      +----------------------+--------------------+------------------+--------+
      ```

  1. View the description of the CLI command for moving a DNS zone:

      ```bash
      yc dns zone move --help
      ```

  1. Move the DNS zone to a different folder with the following parameters: 
      
      * Set `id` to the DNS zone ID, e.g., `aet29qhara5j********`.
      * In `destination-folder-id`, specify the destination folder ID, e.g., `b1g66mft1vop********`.

      ```bash
      yc dns zone move \
        --id aet29qhara5j******** \
        --destination-folder-id b1g66mft1vop********
      ```

      For more information about the `yc dns zone move` command, see the [CLI reference](../../cli/cli-ref/dns/cli-ref/zone/move.md).

- 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. [Configure](../../resource-manager/operations/folder/set-access-bindings.md) access permissions for the target folder. The account from the source folder you are going to use to perform the operation must have at least the `dns.editor` [role](../security/index.md) for the target folder.

  1. [Get the target folder ID](../../resource-manager/operations/folder/get-id.md).
  1. In the configuration file, update the `folder_id` parameter in the `yandex_dns_zone` resource:

      ```hcl
      resource "yandex_dns_zone" "zone1" {
          name        = "<zone_name>"
          description = "<zone_description>"
          zone        = "<domain_zone>."
          public      = true
          folder_id   = "<target_folder_ID>"
      }
      ```

      Where:

      * `name`: Zone name. It must be unique within a folder.
      * `description`: Zone description. 
      * `zone`: Domain zone name. Note that the zone name must end with a trailing dot. You cannot create top-level domain (TLD) zones. To create a domain name with non-Latin characters, use [Punycode](https://en.wikipedia.org/wiki/Punycode) encoding.
      * `public`: Zone visibility, public or private.
      * `folder_id`: ID of the folder to place the DNS zone in (by default, specified from the [environment variable](../../tutorials/infrastructure-management/terraform-quickstart.md#get-credentials)).

      For more on the properties of the `yandex_dns_zone` resource, see [this provider guide](../../terraform/resources/dns_zone.md).

  1. Apply the new configuration:

      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 move the DNS zone to the specified destination folder without re-creating it. You can check the update using the [management console](https://console.yandex.cloud).

- API {#api}

  Use the [move](../api-ref/DnsZone/move.md) REST API method for the [DnsZone](../api-ref/DnsZone/index.md) resource or the [DnsZoneService/Move](../api-ref/grpc/DnsZone/move.md) gRPC API call.

  #### REST API example {#rest-api}

  Below is an example of a Bash script for Linux.
  
  To use it, [get authenticated](../api-ref/authentication.md) with the API and install [cURL](https://curl.haxx.se).

  1. Create a script file:

      ```bash
      sudo touch <file_name>
      ```

  1. Open the file to write the script to:

      ```bash
      sudo nano <file_name>
      ```
  
  1. Place the script in the file:

      ```bash
      #!/bin/bash

      # Creating variables

      export IAM_TOKEN=`yc iam create-token`
      
      dnsZoneId='<DNS_zone_ID>'
      destinationFolderId='<folder_ID>'
      
      # Moving a DNS zone

      curl \
        --request POST \
        --header "Authorization: Bearer ${IAM_TOKEN}" \
        --header "Content-Type: application/json" \
        --data '{ "destinationFolderId": "'"${destinationFolderId}"'" }' \
        "https://dns.api.cloud.yandex.net/dns/v1/zones/${dnsZoneId}:move"
      ```

      Where:

      * `IAM_TOKEN`: IAM token for API authentication.
      * `dnsZoneId`: ID of the DNS zone to move.
      * `destinationFolderId`: ID of the folder to move the DNS zone to.

  1. Make the file executable:

      ```bash
      chmod +x <file_name>
      ```

  1. Run the script:

      ```bash
      ./<file_name>
      ```

  #### gRPC API example {#grpc-api}

  Below is an example Bash script for calling the gRPC API using `grpcurl`.

  1. Install `grpcurl`:
        
        * Using Bash:
        
            ```bash
            curl -L https://github.com/fullstorydev/grpcurl/releases/download/v1.9.3/grpcurl_1.9.3_linux_x86_64.tar.gz | tar -xz
            sudo mv grpcurl /usr/local/bin/
            ```
            
        * Using Golang:

            ```go
            go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest
            ```

  1. Create a script file:

      ```bash
      sudo touch <file_name>
      ```

  1. Open the file to write the script to:

      ```bash
      nano <file_name>
      ```

  1. Place the script in the file:

      ```bash
      #!/bin/bash

      # Creating variables

      export IAM_TOKEN=$(yc iam create-token)

      dnsZoneId='<DNS_zone_ID>'
      destinationFolderId='<folder_ID>'

      # Moving a DNS zone

      grpcurl \
      -d "{
          \"dns_zone_id\": \"${dnsZoneId}\",
          \"destination_folder_id\": \"${destinationFolderId}\"
      }" \
      -H "authorization: Bearer ${IAM_TOKEN}" \
      -H "x-client-request-id: $(uuidgen)" \
      dns.api.cloud.yandex.net:443 \
      yandex.cloud.dns.v1.DnsZoneService/Move
      ```

      Where:

      * `IAM_TOKEN`: IAM token for API authentication.
      * `dnsZoneId`: ID of the DNS zone to move.
      * `destinationFolderId`: ID of the folder to move the DNS zone to.
      * `x-client-request-id`: Unique request ID for tracing.

  1. Make the file executable:

      ```bash
      chmod +x <file_name>
      ```

  1. Run the script:

      ```bash
      ./<file_name>
      ```
 
    This will return an operation in JSON format:

    ```json
    {
        "id": "dns-zone-move-123456789",
        "description": "Update DNS Zone",
        "createdAt": "2026-02-19T09:52:35.239149422Z",
        "createdBy": "aje6f5h1h2h3********",
        "modifiedAt": "2026-02-19T09:52:35.239218092Z",
        "done": true,
        "metadata": {
            "@type": "type.googleapis.com/yandex.cloud.dns.v1.MoveDnsZoneMetadata",
            "dnsZoneId": "aet29qhara5j********"
        },
        "response": {
            "@type": "type.googleapis.com/yandex.cloud.dns.v1.DnsZone",
            "createdAt": "2026-02-19T07:09:53.853Z",
            "folderId": "b1g66mft1vop********",
            "id": "aet29qhara5j********",
            "name": "my-public-zone",
            "publicVisibility": {},
            "zone": "example.com."
        }
    }
    ```

    Where:

    * `id`: Unique operation ID.
    * `metadata.dnsZoneId`: ID of the DNS zone to move.
    * `response`: Updated DNS zone after migration.
    * `done`: Operation completion status.

    For a detailed description of the method, see the [gRPC API reference](../api-ref/grpc/DnsZone/move.md).

{% endlist %}