Encrypting an image
If you deactivate the key used to encrypt a disk, image, or snapshot, access to the data will be suspended until you reactivate the key.
Alert
If you destroy the key or its version used to encrypt a disk, image, or snapshot, you will irrevocably lose access to the data. For details, see Destroying key versions.
-
Create a Yandex Key Management Service encryption key. For more information, see Encryption in Compute Cloud.
-
Create an encrypted disk from the snapshot you want to encrypt:
-
In the management console
, select the folder with your source snapshot. -
Select Compute Cloud.
-
In the left-hand panel, select
Disks. -
Click Create disk.
-
Enter a name for the disk.
- 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.
-
Set the disk parameters, such as disk type, block size, and disk size.
-
In the Contents field, select
Snapshotand then select the snapshot you created earlier from the list below. Use the filter to find the snapshot. -
Under Encryption, enable Encrypted disk and select the key you created earlier in the KMS key field.
-
Click Create disk.
Once created, the disk will get the
Creatingstatus. Wait until the disk status changes toReadybefore using it. -
-
Create a snapshot from the encrypted disk created earlier.
-
Delete the encrypted disk.
-
Delete the source snapshot.
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.
-
Create a Yandex Key Management Service encryption key:
yc kms symmetric-key create \ --name <key_name> \ --default-algorithm aes-256 \ --rotation-period 24h \ --deletion-protectionWhere
--nameis the name of the new Key Management Service key.Result:
id: abj73fd9mekk******** folder_id: b1geoelk7fld******** created_at: "2025-05-20T17:27:35Z" name: my-key1 status: ACTIVE primary_version: id: abjdno4pqi67******** key_id: abj73fd9mekk******** status: ACTIVE algorithm: AES_256 created_at: "2025-05-20T17:27:35Z" primary: true default_algorithm: AES_256 rotation_period: 86400s deletion_protection: true -
Get a list of all snapshots in the default folder:
yc compute snapshot listResult:
+----------------------+-----------------------+----------------------+----------+ | ID | NAME | PRODUCT IDS | STATUS | +----------------------+-----------------------+----------------------+----------+ | fd823vsvcmop******** | snap-ubuntu-24-04-lts | f2etq3erab3o******** | READY | | fd8p8l3asgud******** | snap-debian-2025 | f2etq3erab3o******** | READY | +----------------------+-----------------------+----------------------+----------+ -
Create an encrypted disk from the snapshot you want to encrypt:
yc compute disk create <encrypted_disk_name> \ --source-snapshot-name <snapshot_name> \ --kms-key-name <key_name>Where:
--source-snapshot-name: Name of the snapshot used to create the encrypted disk.--kms-key-name: Encryption key name.
Result:
done (53s) id: fhmihpagi991******** folder_id: b1geoelk7fld******** created_at: "2025-05-20T17:39:01Z" name: fromcliencrypted type_id: network-hdd zone_id: ru-central1-a size: "21474836480" block_size: "4096" status: READY source_snapshot_id: fd8lb5jnr2m2******** disk_placement_policy: {} hardware_generation: legacy_features: pci_topology: PCI_TOPOLOGY_V1 kms_key: key_id: abj73fd9mekk******** version_id: abjdno4pqi67********Once created, the disk will get the
Creatingstatus. Wait until the disk status changes toReadybefore using it. -
Get a list of all disks in the default folder:
yc compute disk listResult:
+----------------------+--------------+-------------+---------------+--------+----------------------+-------------------------+ | ID | NAME | SIZE | ZONE | STATUS | INSTANCE IDS | DESCRIPTION | +----------------------+--------------+-------------+---------------+--------+----------------------+-------------------------+ | a7lqgbt0bb9s******** | first-disk | 20401094656 | ru-central1-a | READY | a7lcvu28njbh******** | | | a7lv5j5hm1p1******** | second-disk | 21474836480 | ru-central1-a | READY | | | +----------------------+--------------+-------------+---------------+--------+----------------------+-------------------------+ -
Create a snapshot from the encrypted disk you created earlier:
yc compute snapshot create \ --name <name_of_new_snapshot> \ --disk-name <encrypted_disk_name>Result:
id: fhmu3pfcpicd******** description: Create snapshot created_at: "2025-06-02T16:14:07.523160478Z" created_by: ajevfb0tjfts******** modified_at: "2025-06-02T16:14:07.523160478Z" metadata: '@type': type.googleapis.com/yandex.cloud.compute.v1.CreateSnapshotMetadata snapshot_id: fd8pb5en4j9m******** disk_id: fhmqgef7vh76******** -
Delete the encrypted disk:
yc compute disk delete <encrypted_disk_name>Result:
done (5s) -
Delete the source snapshot:
yc compute snapshot delete <unencrypted_snapshot_name>Result:
done (7s)
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the relevant documentation on the Terraform
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
To encrypt a disk using Terraform:
-
In the Terraform configuration file, describe the resources you want to create:
# Creating a Yandex Key Management Service key resource "yandex_kms_symmetric_key" "my-key" { name = "encrypt-key" default_algorithm = "AES_256" rotation_period = "8760h" deletion_protection = true lifecycle { prevent_destroy = true } } # Creating an encrypted disk resource "yandex_compute_disk" "encrypted-disk" { name = "new-encrypted-disk" type = "network-hdd" zone = "ru-central1-a" size = 20 block_size = 4096 snapshot_id = "<unencrypted_snapshot_ID>" kms_key_id = yandex_kms_symmetric_key.my-key.id } # Creating an encrypted snapshot resource "yandex_compute_snapshot" "encrypted-snapshot" { name = "<encrypted_snapshot_name>" source_disk_id = yandex_compute_disk.encrypted-disk.id depends_on = [yandex_compute_disk.encrypted-disk] }Where:
snapshot_id: Unencrypted snapshot ID.name: Name of the encrypted snapshot you are creating.
For more information about
yandex_compute_snapshotproperties, see the relevant provider documentation. -
Create the resources:
-
In the terminal, go to the directory where you edited the configuration file.
-
Make sure the configuration file is correct using this command:
terraform validateIf the configuration is correct, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou will see a detailed list of resources. No changes will be made at this step. If the configuration contains any errors, Terraform will show them.
-
Apply the changes:
terraform apply -
Type
yesand press Enter to confirm the changes.
Once created, the disk will get the
Creatingstatus. Wait until the disk status changes toReadybefore using it. -
-
Delete the encrypted disk.
-
Delete the source snapshot.
-
Create a Yandex Key Management Service encryption key using the create REST API method for the SymmetricKey resource or the SymmetricKeyService/Create gRPC API call.
-
Create an encrypted disk from a snapshot using the create REST API method for the Disk resource or the DiskService/Create gRPC API call.
To request a list of available snapshots, use the list REST API method or the SnapshotService/List gRPC API call.
Once created, the disk will get the
Creatingstatus. Wait until the disk status changes toReadybefore using it. -
Create a snapshot for or the encrypted disk using the create REST API method for the Snapshot resource or the SnapshotService/Create gRPC API call.
-
Delete the encrypted disk using the delete REST API method for the Disk resource or the DiskService/Delete gRPC API call.
-
Delete the source snapshot using the delete REST API method for the Snapshot resource or the SnapshotService/Delete gRPC API call.