[Yandex Cloud documentation](../../../index.md) > [Yandex Compute Cloud](../../index.md) > [Step-by-step guides](../index.md) > Managing a VM > Moving a VM to a different cloud

# Moving a VM to a different cloud

While directly moving a VM to a different cloud is not supported, you can create an image from its boot disk and then create a VM from this image in a different cloud.

1. Use the boot disk of your VM to [create an image](../image-create/create-from-disk.md).
1. Get the boot disk image ID:

    {% list tabs group=instructions %}

    - Management console {#console}

      1. In the [management console](https://console.yandex.cloud), select the folder the disk image is in.
      1. Navigate to **Compute Cloud**.
      1. In the left-hand panel, select ![image](../../../_assets/console-icons/layers.svg) **Images**.
      1. Copy the value from the **ID** column for the image in question.

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

      Get a list of disk images in the default folder:

      ```bash
      yc compute image list
      ```

      Result:

      ```text
      +----------------------+----------------+--------+-------------+--------+
      |          ID          |    NAME        | FAMILY | PRODUCT IDS | STATUS |
      +----------------------+----------------+--------+-------------+--------+
      | xc8n3spmksqm******** | original-image |        |             | READY  |
      +----------------------+----------------+--------+-------------+--------+
      ```

    - 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, prepare the `output` variable with the output data:

          ```hcl
          resource "yandex_compute_snapshot" "snapshot-1" {
            name           = "<image_name>"
            source_disk_id = "<disk_ID>"
          }
          ...
          output "snapshot_id" {
            value = yandex_compute_snapshot.snapshot-1.id
          }
          ```

          Where `value` is the boot disk image ID. In the example above, the boot disk image is described in the `yandex_compute_snapshot` resource named `snapshot-1`.

      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.

      1. Save the boot disk image ID to the `snapshot_id.txt` file using this console command:

          ```bash
          terraform output snapshot_id > snapshot_id.txt
          ```

    - API {#api}

      Use the [list](../../api-ref/Image/list.md) REST API method for the [Image](../../api-ref/Image/index.md) resource or the [ImageService/List](../../api-ref/grpc/Image/list.md) gRPC API call.

    {% endlist %}

1. Get the ID of the target cloud you plan to move your VM to (next: `<target_cloud_ID>`):

    {% list tabs group=instructions %}

    - Management console {#console}

      1. In the [management console](https://console.yandex.cloud), click the cloud in the list on the left.
      1. On the **Overview** tab, copy the **ID** value.

    - CLI {#cli}

      Get a list of clouds with their IDs:

      ```bash
      yc resource-manager cloud list
      ```

      Result:

      ```text
      +----------------------+------------+--------------------------+
      |          ID          |    NAME    |      ORGANIZATION ID     |
      +----------------------+------------+--------------------------+
      | b1g66mft1vop******** | my-cloud-1 |                          |
      | b1gd129pp9ha******** | my-cloud-2 |                          |
      +----------------------+------------+--------------------------+
      ```

    - Terraform {#tf}

      1. In the configuration file, prepare the `output` variable with the output data:

          ```hcl
          resource "yandex_resourcemanager_cloud" "cloud-1" {
            name            = "<cloud_name>"
            organization_id = "<organization_ID>"
          }

          output "destination_cloud_id" {
            value = yandex_resourcemanager_cloud.cloud-1.id
          }
          ```

          Where `destination_cloud_id` is the target cloud ID. In the example above, the cloud is described in the `yandex_resourcemanager_cloud` resource named `cloud-1`.

      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.

      1. Save the target cloud ID named `destination_cloud_id.txt` using this console command:

          ```bash
          terraform output destination_cloud_id > destination_cloud_id.txt
          ```

    - API {#api}

      To get a list of clouds with their IDs, use the [list](../../../resource-manager/api-ref/Cloud/list.md) REST API method for the [Cloud](../../../resource-manager/api-ref/Cloud/index.md) resource or the [CloudService/List](../../../resource-manager/api-ref/grpc/Cloud/list.md) gRPC API call.

    {% endlist %}

1. [Add a user](../../../organization/operations/add-account.md) from the target cloud (where you want to move your VM) to the cloud hosting the folder with the source image.
1. [Assign](../../../iam/operations/roles/grant.md) the target cloud user the `resource-manager.clouds.member` and `compute.images.user` roles for the cloud hosting the folder with the source image.
1. Create a new image in the target cloud:

    {% list tabs group=instructions %}

    - CLI {#cli}

      ```bash
      yc compute image create \
        --name <new_image_name> \
        --source-image-id <source_image_ID> \
        --cloud-id <target_cloud_ID> \
        --folder-id <destination_folder_ID>
      ```


    - API {#api}

      Use the [create](../../api-ref/Image/create.md) REST API method for the [Image](../../api-ref/Image/index.md) resource or the [ImageService/Create](../../api-ref/grpc/Image/create.md) gRPC API call. Specify the image ID in your request.

    {% endlist %}

1. In the target cloud, [create a VM](../vm-create/create-from-user-image.md) from the image you created.