Creating an image from a disk snapshot
To create an image from a disk snapshot:
-
In the management console
, select the folder where you want to create an image. -
Select Compute Cloud.
-
In the left-hand panel, select
Snapshots. -
In the line with the snapshot, click
and select Create image. -
Specify the image name. Follow these naming requirements:
- It must be from 2 to 63 characters long.
- It can only contain lowercase Latin letters, numbers, and hyphens.
- It must start with a letter and cannot end with a hyphen.
-
Provide a text description for the image, if required.
-
To create an optimized image, enable Optimization.
-
Click Create.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID>
command. You can also set a different folder for any specific command using the --folder-name
or --folder-id
parameter.
-
See the description of the CLI command for creating an image:
yc compute image create --help
-
Get a list of snapshots in the default folder:
yc compute snapshot list
Result:
+----------------------+-----------------+----------------------+--------+----------------------------+ | ID | NAME | PRODUCT IDS | STATUS | DESCRIPTION | +----------------------+-----------------+----------------------+--------+----------------------------+ | fd8rlt1u2rf0l******* | first-snapshot | f2ecl5vhsftd******** | READY | my first snapshot via CLI | | fhmolt1u2rf0******** | second-snapshot | f2eclmol5lps******** | READY | my second snapshot via CLI | +----------------------+-----------------+----------------------+--------+----------------------------+
-
Select
ID
orNAME
of the snapshot in question. -
Create an image in the default folder:
yc compute image create \ --name first-image \ --source-snapshot-name first-snapshot \ --description "my first image via yc"
This command will create an image named
first-image
and described asmy first image via yc
fromfirst-snapshot
.To create an optimized image, use the
--pooled
flag:yc compute image create \ --name first-image \ --source-snapshot-name first-snapshot \ --description "my first image via yc" \ --pooled
If you do not have Terraform yet, install it and configure its Yandex Cloud provider.
-
Define the parameters of the
yandex_compute_image
resource in the configuration file.Here is an example of the configuration file structure:
resource "yandex_compute_image" "image-1" { name = "<image_name>" source_snapshot = "<snapshot_ID>" }
For more information about the resources you can create with Terraform, see the relevant provider documentation
. -
Make sure the configuration files are correct.
-
In the command line, navigate to the directory where you created the configuration file.
-
Run a check using this command:
terraform plan
If the configuration description is correct, the terminal will display a list of the resources being created and their settings. If the configuration contains any errors, Terraform will point them out.
-
-
Deploy the cloud resources.
-
Run this command:
terraform apply
-
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
. -
- Get a list of snapshots using the list REST API method for the Snapshot resource or the SnapshotService/List gRPC API call.
- Create an image using the create REST API method for the Image resource or the ImageService/Create gRPC API call. Specify the snapshot ID in your request.
Once created, the image will get the CREATING
status. Wait until its status changes to READY
before using it.