Skip to content

Commit d31dea8

Browse files
committed
Updating all scripts.
1 parent 57087c6 commit d31dea8

6 files changed

+148
-17
lines changed

articles/virtual-machines/disk-encryption.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ By default, managed disks use platform-managed encryption keys. All managed disk
4141

4242
For now, customer-managed keys have the following restrictions:
4343

44-
- For Ultra Disks and Premium SSD v2 only: If this feature is enabled for your disk, you cannot disable it.
45-
If you need to work around this, you must copy all the data using either the [Azure PowerShell module](windows/disks-upload-vhd-to-managed-disk-powershell.md#copy-a-managed-disk) or the [Azure CLI](linux/disks-upload-vhd-to-managed-disk-cli.md#copy-a-managed-disk), to an entirely different managed disk that isn't using customer-managed keys.
4644
[!INCLUDE [virtual-machines-managed-disks-customer-managed-keys-restrictions](../../includes/virtual-machines-managed-disks-customer-managed-keys-restrictions.md)]
4745

4846
#### Supported regions

articles/virtual-machines/image-version-encryption.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ When you're using customer-managed keys for encrypting images in an Azure Comput
3838

3939
- Encryption key sets are regional resources, so each region requires a different encryption key set.
4040

41-
- For Ultra Disks and Premium SSD v2 only: You can't copy or share images that use customer-managed keys.
42-
43-
- For Ultra Disks and Premium SSD v2 only: After you've used your own keys to encrypt a disk or image, you can't go back to using platform-managed keys for encrypting those disks or images.
44-
4541
- VM image version source doesn't currently support customer-managed key encryption.
4642

4743
## PowerShell

articles/virtual-machines/scripts/copy-managed-disks-to-same-or-different-subscription.md

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ ms.subservice: disks
99
ms.devlang: azurecli
1010
ms.topic: sample
1111
ms.workload: infrastructure
12-
ms.date: 02/23/2022
12+
ms.date: 02/22/2023
1313
ms.author: ramankum
1414
ms.custom: mvc
1515
---
1616

1717
# Copy managed disks to same or different subscription with CLI
1818

19-
This script copies a managed disk to same or different subscription but in the same region. The copy works only when the subscriptions are part of the same Azure AD tenant.
19+
This article contains two scripts. The first script copies a managed disk that's using platform-managed keys to same or different subscription but in the same region. The second script copies a managed disk that's using customer-managed keys to the same or a different subscription in the same region. Either copy only works when the subscriptions are part of the same Azure AD tenant.
2020

2121
[!INCLUDE [quickstarts-free-trial-note](../../../includes/quickstarts-free-trial-note.md)]
2222

@@ -26,10 +26,57 @@ This script copies a managed disk to same or different subscription but in the s
2626

2727
[!INCLUDE [cli-launch-cloud-shell-sign-in.md](../../../includes/cli-launch-cloud-shell-sign-in.md)]
2828

29-
### Run the script
29+
### Disks with platform-managed keys
3030

3131
:::code language="azurecli" source="~/azure_cli_scripts/virtual-machine/copy-managed-disks-to-same-or-different-subscription/copy-managed-disks-to-same-or-different-subscription.sh" id="FullScript":::
3232

33+
### Disks with customer-managed keys
34+
35+
```azurecli
36+
#Provide the subscription Id of the subscription where managed disk exists
37+
sourceSubscriptionId="<subscriptionId>"
38+
39+
#Provide the name of your resource group where managed disk exists
40+
sourceResourceGroupName=mySourceResourceGroupName
41+
42+
#Provide the name of the managed disk
43+
managedDiskName=myDiskName
44+
45+
#Provide the name of the disk encryption set
46+
diskEncryptionSetName=myName
47+
48+
#Provide the disk encryption set ID
49+
diskEncrpytonSetId=myID
50+
51+
#Provide the disk encryption set resource group
52+
diskEncryptionResourceGroup=myGroup
53+
54+
#Set the context to the subscription Id where managed disk exists
55+
az account set --subscription $sourceSubscriptionId
56+
57+
#Get the managed disk Id
58+
managedDiskId=$(az disk show --name $managedDiskName --resource-group $sourceResourceGroupName --query [id] -o tsv)
59+
60+
#If managedDiskId is blank then it means that managed disk does not exist.
61+
echo 'source managed disk Id is: ' $managedDiskId
62+
63+
#Get the disk encryption set ID
64+
diskEncryptionSetId=$(az disk-encryption-set show --name $diskEncryptionSetName --resource-group $diskEncryptionResourceGroup)
65+
66+
#Provide the subscription Id of the subscription where managed disk will be copied to
67+
targetSubscriptionId=6492b1f7-f219-446b-b509-314e17e1efb0
68+
69+
#Name of the resource group where managed disk will be copied to
70+
targetResourceGroupName=mytargetResourceGroupName
71+
72+
#Set the context to the subscription Id where managed disk will be copied to
73+
az account set --subscription $targetSubscriptionId
74+
75+
#Copy managed disk to different subscription using managed disk Id and disk encryption set ID
76+
#Add --location parameter to change the location
77+
az disk create -g $targetResourceGroupName -n $managedDiskName --source $managedDiskId --disk-encryption-set $diskEncrpytonSetId
78+
```
79+
3380
## Clean up resources
3481

3582
Run the following command to remove the resource group, VM, and all related resources.

articles/virtual-machines/scripts/copy-snapshot-to-same-or-different-subscription.md

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ ms.service: storage
88
ms.subservice: disks
99
ms.topic: sample
1010
ms.workload: infrastructure
11-
ms.date: 02/23/2022
11+
ms.date: 02/22/2023
1212
ms.author: ramankum
1313
ms.custom: mvc
1414
---
1515

1616
# Copy snapshot of a managed disk to same or different subscription with CLI
1717

18-
This script copies a snapshot of a managed disk to same or different subscription. Use this script for the following scenarios:
18+
This article contains two scripts. The first script copies a snapshot of a managed disk that was using platform-managed keys to the same or a different subscription. The second script copies a snapshot of a managed disk that was using customer-managed keys to the same or a different subscription. These scripts can be used for the following scenarios:
1919

2020
- Migrate a snapshot in Premium storage (Premium_LRS) to Standard storage (Standard_LRS or Standard_ZRS) to reduce your cost.
2121
- Migrate a snapshot from locally redundant storage (Premium_LRS, Standard_LRS) to zone redundant storage (Standard_ZRS) to benefit from the higher reliability of ZRS storage.
@@ -32,10 +32,58 @@ This script copies a snapshot of a managed disk to same or different subscriptio
3232

3333
[!INCLUDE [cli-launch-cloud-shell-sign-in.md](../../../includes/cli-launch-cloud-shell-sign-in.md)]
3434

35-
### Run the script
35+
### Disks with platform-managed keys
3636

3737
:::code language="azurecli" source="~/azure_cli_scripts/virtual-machine/copy-snapshot-to-same-or-different-subscription/copy-snapshot-to-same-or-different-subscription.sh" id="FullScript":::
3838

39+
### Disks with customer-managed keys
40+
41+
```azurecli
42+
#Provide the subscription Id of the subscription where snapshot exists
43+
sourceSubscriptionId="<subscriptionId>"
44+
45+
#Provide the name of your resource group where snapshot exists
46+
sourceResourceGroupName=mySourceResourceGroupName
47+
48+
#Provide the disk encryption set ID
49+
diskEncrpytonSetId=myID
50+
51+
#Provide the disk encryption set resource group
52+
diskEncryptionResourceGroup=myGroup
53+
54+
#Provide the name of the snapshot
55+
snapshotName=mySnapshotName
56+
57+
#Set the context to the subscription Id where snapshot exists
58+
az account set --subscription $sourceSubscriptionId
59+
60+
#Get the snapshot Id
61+
snapshotId=$(az snapshot show --name $snapshotName --resource-group $sourceResourceGroupName --query [id] -o tsv)
62+
63+
#If snapshotId is blank then it means that snapshot does not exist.
64+
echo 'source snapshot Id is: ' $snapshotId
65+
66+
#Get the disk encryption set ID
67+
diskEncryptionSetId=$(az disk-encryption-set show --name $diskEncryptionSetName --resource-group $diskEncryptionResourceGroup)
68+
69+
#Provide the subscription Id of the subscription where snapshot will be copied to
70+
#If snapshot is copied to the same subscription then you can skip this step
71+
targetSubscriptionId=6492b1f7-f219-446b-b509-314e17e1efb0
72+
73+
#Name of the resource group where snapshot will be copied to
74+
targetResourceGroupName=mytargetResourceGroupName
75+
76+
#Set the context to the subscription Id where snapshot will be copied to
77+
#If snapshot is copied to the same subscription then you can skip this step
78+
az account set --subscription $targetSubscriptionId
79+
80+
#Copy snapshot to different subscription using the snapshot Id
81+
#We recommend you to store your snapshots in Standard storage to reduce cost. Please use Standard_ZRS in regions where zone redundant storage (ZRS) is available, otherwise use Standard_LRS
82+
#Please check out the availability of ZRS here: https://docs.microsoft.com/en-us/azure/storage/common/storage-redundancy-zrs#support-coverage-and-regional-availability
83+
#To change the region, use the --location parameter
84+
az snapshot create -g $targetResourceGroupName -n $snapshotName --source $snapshotId --disk-encryption-set $diskEncryptionSetID --sku Standard_LRS --encryption-type EncryptionAtRestWithCustomerKey
85+
```
86+
3987
## Clean up resources
4088

4189
Run the following command to remove the resource group, VM, and all related resources.

articles/virtual-machines/scripts/create-managed-disk-from-snapshot.md

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ ms.devlang: azurecli
1515
ms.topic: sample
1616
ms.tgt_pltfrm: vm-linux
1717
ms.workload: infrastructure
18-
ms.date: 02/23/2022
18+
ms.date: 02/22/2023
1919
ms.author: ramankum
2020
ms.custom: mvc
2121
---
2222

2323
# Create a managed disk from a snapshot with CLI (Linux)
2424

25-
This script creates a managed disk from a snapshot. Use it to restore a virtual machine from snapshots of OS and data disks. Create OS and data managed disks from respective snapshots and then create a new virtual machine by attaching managed disks. You can also restore data disks of an existing VM by attaching data disks created from snapshots.
25+
This article contains two scripts for creating a managed disk from a snapshot. The first script is for a managed disk with platform-managed keys and the second script is for a managed disk with customer-manaegd keys. Use these scripts to restore a virtual machine from snapshots of OS and data disks. Create OS and data managed disks from respective snapshots and then create a new virtual machine by attaching managed disks. You can also restore data disks of an existing VM by attaching data disks created from snapshots.
2626

2727
[!INCLUDE [quickstarts-free-trial-note](../../../includes/quickstarts-free-trial-note.md)]
2828

@@ -32,10 +32,52 @@ This script creates a managed disk from a snapshot. Use it to restore a virtual
3232

3333
[!INCLUDE [cli-launch-cloud-shell-sign-in.md](../../../includes/cli-launch-cloud-shell-sign-in.md)]
3434

35-
### Run the script
35+
### Disks with platform-managed keys
3636

3737
:::code language="azurecli" source="~/azure_cli_scripts/virtual-machine/create-managed-disks-from-snapshot/create-managed-disks-from-snapshot.sh" id="FullScript":::
3838

39+
### Disks with customer-managed keys
40+
41+
```azurecli
42+
#Provide the subscription Id of the subscription where you want to create Managed Disks
43+
subscriptionId="<subscriptionId>"
44+
45+
#Provide the name of your resource group
46+
resourceGroupName=myResourceGroupName
47+
48+
#Provide the name of the snapshot that will be used to create Managed Disks
49+
snapshotName=mySnapshotName
50+
51+
#Provide the name of the new Managed Disks that will be create
52+
diskName=myDiskName
53+
54+
#Provide the size of the disks in GB. It should be greater than the VHD file size.
55+
diskSize=128
56+
57+
#Provide the storage type for Managed Disk. Premium_LRS or Standard_LRS.
58+
storageType=Premium_LRS
59+
60+
#Provide the disk encryption set ID
61+
diskEncrpytonSetId=myID
62+
63+
#Provide the disk encryption set resource group
64+
diskEncryptionResourceGroup=myGroup
65+
66+
#Set the context to the subscription Id where Managed Disk will be created
67+
az account set --subscription $subscriptionId
68+
69+
#Get the snapshot Id
70+
snapshotId=$(az snapshot show --name $snapshotName --resource-group $resourceGroupName --query [id] -o tsv)
71+
72+
#Get the disk encryption set ID
73+
diskEncryptionSetId=$(az disk-encryption-set show --name $diskEncryptionSetName --resource-group $diskEncryptionResourceGroup)
74+
75+
#Create a new Managed Disks using the snapshot Id
76+
#Note that managed disk will be created in the same location as the snapshot
77+
#To change the location, add the --location parameter
78+
az disk create -g $resourceGroupName -n $diskName --source $snapshotId --disk-encryption-set $diskEncryptionSetID --location eastus2euap
79+
```
80+
3981
## Clean up resources
4082

4183
Run the following command to remove the resource group, VM, and all related resources.

includes/virtual-machines-managed-disks-customer-managed-keys-restrictions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
author: roygara
66
ms.service: virtual-machines
77
ms.topic: include
8-
ms.date: 10/12/2022
8+
ms.date: 02/21/2023
99
ms.author: rogarana
1010
ms.custom: include file
1111
---
1212
- Only [software and HSM RSA keys](../articles/key-vault/keys/about-keys.md) of sizes 2,048-bit, 3,072-bit and 4,096-bit are supported, no other keys or sizes.
1313
- [HSM](../articles/key-vault/keys/hsm-protected-keys.md) keys require the **premium** tier of Azure Key vaults.
14-
- For Ultra Disks and Premium SSD v2 only: Disks created from custom images that are encrypted using server-side encryption and customer-managed keys must be encrypted using the same customer-managed keys. Your disks and their images must be in the same subscription, the keys used to encrypt your disks can be in a different subscription.
14+
- Disks created from custom images that are encrypted using server-side encryption and customer-managed keys must be encrypted using the same customer-managed keys. Your disks and their images must be in the same subscription, the keys used to encrypt your disks can be in a different subscription.
1515
- For Ultra Disks and Premium SSD v2 only: Snapshots created from disks that are encrypted with server-side encryption and customer-managed keys must be encrypted with the same customer-managed keys.
1616
- Most resources related to your customer-managed keys (disk encryption sets, VMs, disks, and snapshots) must be in the same subscription and region.
1717
- Azure Key Vaults may be used from a different subscription but must be in the same region as your disk encryption set. As a preview, you can use Azure Key Vaults from [different Azure Active Directory tenants](../articles/virtual-machines/disks-cross-tenant-customer-managed-keys.md).

0 commit comments

Comments
 (0)