How to move a VM across folders or clouds
Case description
You need to move a VM from one cloud or folder to another.
Solution
To move a VM across clouds, complete the following steps:
-
Add an IAM user to the cloud with the image you want to transfer.
-
Assign the IAM user the minimum required roles:
resource-manager.clouds.memberandcompute.images.user. -
Set up YC CLI for the user in the target cloud.
-
Get the ID of your image. To do this, in the management console
, find the ID field on the Images tab. Alternatively, you can get the ID by running this YC CLI command:yc compute image list. -
Get the ID of the cloud where the original image is located. To do this, in the management console
, find the ID field. Alternatively, you can get the ID by running this YC CLI command:yc resource-manager cloud list. -
With your YC CLI, create a new image in the target cloud:
yc compute image create --name <new_image_name> \ --source-image-id <original_image_ID> \ --cloud-id <original_image_home_cloud_ID>
After performing these actions, create a new VM from the image you got.
To change a VM folder, follow these steps in your CLI:
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating 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 all VMs in the default folder:
yc compute instance listResult:
+----------------------+-----------------+--------------------+---------+----------------------+ | ID | NAME | ZONE ID | STATUS | DESCRIPTION | +----------------------+-----------------+--------------------+---------+----------------------+ | fhm***************** | first-instance | ru-central1-a | RUNNING | my first vm via CLI | | fhm***************** | 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 listResult:
+----------------------+--------------------+------------------+--------+ | ID | NAME | LABELS | STATUS | +----------------------+--------------------+------------------+--------+ | b1g***************** | my-folder | | ACTIVE | | b1g***************** | default | | ACTIVE | +----------------------+--------------------+------------------+--------+ -
See the description of the CLI command for moving a VM:
yc compute instance move --help -
Move the VM to a different folder by specifying the following values:
- In
id, enter the VM ID, e.g.,fhm*****************. - In
destination-folder-id, specify the destination folder ID, e.g.,b1g*****************.
yc compute instance move \ --id fhm***************** \ --destination-folder-id b1g*****************For more information about
yc compute instance move, see the CLI reference. - In