Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add disk_encryption_set for data disks in azure_rm_virtualmachine #1309

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions plugins/modules/azure_rm_virtualmachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@
- Size can be changed only when the virtual machine is deallocated.
- Not sure when I(managed_disk_id) defined.
type: int
disk_encryption_set:
description:
- ID of disk encryption set for data disk.
type: str
managed_disk_type:
description:
- Managed data disk type.
Expand Down Expand Up @@ -1112,6 +1116,7 @@ def __init__(self):
options=dict(
lun=dict(type='int', required=True),
disk_size_gb=dict(type='int'),
disk_encryption_set=dict(type='str'),
managed_disk_type=dict(type='str', choices=['Standard_LRS', 'StandardSSD_LRS',
'StandardSSD_ZRS', 'Premium_LRS', 'Premium_ZRS', 'UltraSSD_LRS']),
storage_account_name=dict(type='str'),
Expand Down Expand Up @@ -1865,6 +1870,10 @@ def exec_module(self, **kwargs):
else:
data_disk_vhd = None
data_disk_managed_disk = self.compute_models.ManagedDiskParameters(storage_account_type=data_disk['managed_disk_type'])
if data_disk.get('disk_encryption_set'):
Copy link
Collaborator

@Fred-sun Fred-sun Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean that 'disk_encryption_set' can only be specified if 'managed_disk_type' is not configured for data_disks(self.data_disks.get('managed_disk_type')=None)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. I'm not an expert at Azure but from what I can see, it is only the class ManagedDiskParameters which has the parameter disk_encryption_set as per the Azure Python SDK: https://learn.microsoft.com/en-us/python/api/azure-mgmt-compute/azure.mgmt.compute.v2023_07_01.models.manageddiskparameters?view=azure-python

I'm not sure if other types of disk can be encrypted using a DES. That might be the case. But for example my current customer has a use case where they use managed disk and need encryption with CMK. This would solve that use case at least.

data_disk_managed_disk.disk_encryption_set = self.compute_models.DiskEncryptionSetParameters(
id=data_disk['disk_encryption_set']
)
disk_name = self.name + "-datadisk-" + str(count)
count += 1

Expand Down Expand Up @@ -2116,6 +2125,10 @@ def exec_module(self, **kwargs):
if data_disk.get('managed_disk'):
managed_disk_type = data_disk['managed_disk'].get('storage_account_type')
data_disk_managed_disk = self.compute_models.ManagedDiskParameters(storage_account_type=managed_disk_type)
if data_disk.get('disk_encryption_set'):
data_disk_managed_disk.disk_encryption_set = self.compute_models.DiskEncryptionSetParameters(
id=data_disk['disk_encryption_set']
)
data_disk_vhd = None
else:
data_disk_vhd = data_disk['vhd']['uri']
Expand Down