Transferring VMs between folders or clouds
Issue description
You need to transfer a VM instance from one cloud or folder to another cloud or folder.
Solution
To transfer a VM between clouds, complete the following steps:
- Create an image from the disk of the required VM
- Add an IAM user to the cloud with the image you want to transfer;
- Assign the IAM user the minimum required roles of
resource-manager.clouds.member
andcompute.images.user
. - Set up the YC CLI tool for the user in the target cloud.
- Get the ID of your image. For this, in the web interface, find the ID field in the Images tab, or get the ID using the YC CLI
yc compute image list
command. - Get the ID of the cloud where the original image is located. For this, in the web interface, find the ID field on the cloud's home page, or get the ID using the YC CLI
yc resource-manager cloud list
command. - Create a new image in the target cloud using the YC CLI tool:
yc compute image create --name <new_image_name> \
--source-image-id <ID_of_original_image> \
--cloud-id <ID_of_cloud_where_original_image_is_located>
After performing these actions, create a new VM instance from the resulting image.
To change the folder of a VM instance, complete the following steps:
-
In the CLI:
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the
--folder-name
or--folder-id
parameter.-
Get a list of all VMs in the default folder:
yc compute instance list
Result:
+----------------------+-----------------+---------------+---------+----------------------+ | ID | NAME | ZONE ID | STATUS | DESCRIPTION | +----------------------+-----------------+---------------+---------+----------------------+ | fhm0b28lgfp4tkoa3jl6 | first-instance | ru-central1-a | RUNNING | my first vm via CLI | | fhm9gk85nj7gcoji2f8s | second-instance | ru-central1-a | RUNNING | my second vm via CLI | +----------------------+-----------------+---------------+---------+----------------------+
-
Get a list of all folders in the default cloud:
yc resource-manager folder list
Result:
+----------------------+--------------------+------------------+--------+ | ID | NAME | LABELS | STATUS | +----------------------+--------------------+------------------+--------+ | b1gd129pp9ha0vnvf5g7 | my-folder | | ACTIVE | | b1g66mft1vopnevbn57j | default | | ACTIVE | +----------------------+--------------------+------------------+--------+
-
View the description of the CLI command for moving a VM:
yc compute instance move --help
-
Move the VM to another folder with the following parameters:
- In
id
, enter the ID of the VM, for example,fhm0b28lgfp4tkoa3jl6
. - In
destination-folder-id
, enter the ID of the destination folder, for example,b1gd129pp9ha0vnvf5g7
.
yc compute instance move \ --id fhm0b28lgfp4tkoa3jl6 \ --destination-folder-id b1gd129pp9ha0vnvf5g7
For more information about the
yc compute instance move
command, see the CLI reference. - In
-