diff --git a/plugins/modules/azure_rm_manageddisk.py b/plugins/modules/azure_rm_manageddisk.py index 90afef11c..461611abb 100644 --- a/plugins/modules/azure_rm_manageddisk.py +++ b/plugins/modules/azure_rm_manageddisk.py @@ -73,6 +73,13 @@ - empty - import - copy + - upload + - fromimage + - restore + - copystart + - importsecure + - uploadpreparedsecure + - copyfromsansnapshot storage_account_id: description: - The full path to the storage account the image is to be imported from. @@ -218,6 +225,52 @@ description: - ARM ID of the DiskAccess resource for using private endpoints on disks. type: str + performance_plus: + description: + - Set this flag to true to get a boost on the performance target of the disk deployed, see here on the respective performance target. + - This flag can only be set on disk creation time and cannot be disabled after enabled. + type: bool + upload_size_bytes: + description: + - If I(create_option=upload), this is the size of the contents of the upload including the VHD footer. + - This value should be between 20972032 (20 MiB + 512 bytes for the VHD footer) and 35183298347520 bytes (32 TiB + 512 bytes for the VHD footer). + type: int + disk_image_reference: + description: + - Disk source information for PIR or user images or Gallery Image. + type: dict + suboptions: + id: + description: + - A relative uri containing either a Platform Image Repository, user image, or Azure Compute Gallery image reference. + type: str + shared_gallery_image_id: + description: + - A relative uri containing a direct shared Azure Compute Gallery image reference. + type: str + community_gallery_image_id: + description: + - A relative uri containing a community Azure Compute Gallery image reference. + type: str + logical_sector_size: + description: + - Logical sector size in bytes for Ultra disks. + - Supported values are 512 ad 4096. 4096 is the default. + type: int + default: 4096 + security_data_uri: + description: + - If I(create_option=importsecure), this is the URI of a blob to be imported into VM guest state. + type: str + elastic_san_resource_id: + description: + - Required if I(create_option=copyfromsansnapshot). + - This is the ARM id of the source elastic san volume snapshot. + type: str + source_resource_id: + description: + - If I(create_option=copy), this is the ARM id of the source snapshot or disk. + type: str extends_documentation_fragment: - azure.azcollection.azure - azure.azcollection.azure_tags @@ -244,6 +297,16 @@ os_type: windows storage_account_type: Premium_LRS +- name: Create managed disk with I(create_option=upload) + azure_rm_manageddisk: + resource_group: myResourceGroup + name: mymanageddisk + storage_account_type: "Standard_LRS" + upload_size_bytes: 20972032 + network_access_policy: DenyAll + public_network_access: Disabled + create_option: upload + - name: Mount the managed disk to VM azure_rm_manageddisk: name: mymanageddisk @@ -404,6 +467,48 @@ type: str returned: always sample: '/subscriptions/*********/resourceGroups/myRG/providers/Microsoft.Compute/diskAccesses/diskacc' + performance_plus: + description: + - The flag of the performance target of the disk deployed. + type: bool + returned: always + sample: False + upload_size_bytes: + description: + - This is the size of the contents of the upload including the VHD footer. + type: int + returned: always + sample: None + disk_image_reference: + description: + - Disk source information for PIR or user images or Gallery Image. + type: dict + returned: always + sample: None + logical_sector_size: + description: + - Logical sector size in bytes for Ultra disks. + type: int + returned: always + sample: None + security_data_uri: + description: + - This is the URI of a blob to be imported into VM guest state. + type: str + returned: always + sample: None + elastic_san_resource_id: + description: + - This is the ARM id of the source elastic san volume snapshot. + type: str + returned: always + sample: None + source_resource_id: + description: + - This is the ARM id of the source snapshot or disk. + type: str + returned: always + sample: None changed: description: - Whether or not the resource has changed. @@ -453,7 +558,23 @@ def managed_disk_to_dict(managed_disk): tier=managed_disk.tier, public_network_access=managed_disk.public_network_access, network_access_policy=managed_disk.network_access_policy, - disk_access_id=managed_disk.disk_access_id + disk_access_id=managed_disk.disk_access_id, + storage_account_id=create_data.storage_account_id, + upload_size_bytes=create_data.upload_size_bytes, + logical_sector_size=create_data.logical_sector_size, + security_data_uri=create_data.security_data_uri, + performance_plus=create_data.performance_plus, + elastic_san_resource_id=create_data.elastic_san_resource_id, + gallery_image_reference=dict( + id=create_data.gallery_image_reference.id, + shared_gallery_image_id=create_data.gallery_image_reference.shared_gallery_image_id, + community_gallery_image_id=create_data.gallery_image_reference.community_gallery_image_id + ) if create_data.gallery_image_reference is not None else None, + image_reference=dict( + id=create_data.gallery_image_reference.id, + shared_gallery_image_id=create_data.gallery_image_reference.shared_gallery_image_id, + community_gallery_image_id=create_data.gallery_image_reference.community_gallery_image_id + ) if create_data.image_reference is not None else None ) @@ -484,7 +605,8 @@ def __init__(self): ), create_option=dict( type='str', - choices=['empty', 'import', 'copy'] + choices=['empty', 'import', 'copy', 'upload', 'fromimage', 'restore', 'copystart', 'importsecure', + 'uploadpreparedsecure', 'copyfromsansnapshot'] ), storage_account_id=dict( type='str' @@ -551,12 +673,39 @@ def __init__(self): ), disk_access_id=dict( type='str' + ), + performance_plus=dict(type='bool'), + upload_size_bytes=dict(type='int'), + disk_image_reference=dict( + type='dict', + options=dict( + id=dict(type='str'), + shared_gallery_image_id=dict(type='str'), + community_gallery_image_id=dict(type='str') + ) + ), + logical_sector_size=dict( + type='int', + default=4096 + ), + security_data_uri=dict( + type='str' + ), + elastic_san_resource_id=dict( + type='str' + ), + source_resource_id=dict( + type='str' ) ) required_if = [ ('create_option', 'import', ['source_uri', 'storage_account_id']), - ('create_option', 'copy', ['source_uri']), + ('create_option', 'copy', ['source_resource_id']), ('create_option', 'empty', ['disk_size_gb']), + ('create_option', 'upload', ['upload_size_bytes']), + ('create_option', 'fromimage', ['disk_image_reference']), + ('create_option', 'importsecure', ['security_data_uri']), + ('create_option', 'copyfromsansnapshot', ['elastic_san_resource_id']), ('network_access_policy', 'AllowPrivate', ['disk_access_id']) ] self.results = dict( @@ -588,6 +737,9 @@ def __init__(self): self.network_access_policy = None self.write_accelerator_enabled = None self.disk_access_id = None + self.performance_plus = None + self.upload_size_bytes = None + self.source_resource_id = None mutually_exclusive = [['managed_by_extended', 'managed_by']] @@ -754,14 +906,49 @@ def generate_managed_disk_property(self): storage_account_type = self.disk_models.DiskSku(name=self.storage_account_type) disk_params['sku'] = storage_account_type disk_params['disk_size_gb'] = self.disk_size_gb - creation_data['create_option'] = self.disk_models.DiskCreateOption.empty + if self.create_option == 'import': creation_data['create_option'] = self.disk_models.DiskCreateOption.import_enum creation_data['source_uri'] = self.source_uri creation_data['storage_account_id'] = self.storage_account_id elif self.create_option == 'copy': creation_data['create_option'] = self.disk_models.DiskCreateOption.copy - creation_data['source_resource_id'] = self.source_uri + creation_data['source_resource_id'] = self.source_resource_id + elif self.create_option == 'upload': + creation_data['create_option'] = self.disk_models.DiskCreateOption.upload + creation_data['performance_plus'] = self.performance_plus + creation_data['upload_size_bytes'] = self.upload_size_bytes + elif self.create_option == 'fromimage': + creation_data['create_option'] = self.disk_models.DiskCreateOption.FromImage + if self.disk_image_reference.get('id') is not None: + image_reference = self.disk_models.ImageDiskReference(id=self.disk_image_reference.get('id')) + creation_data['image_reference'] = image_reference + else: + image_reference = self.disk_models.ImageDiskReference(shared_gallery_image_id=self.disk_image_reference.get('shared_gallery_image_id'), + community_gallery_image_id=self.disk_image_reference.get('community_gallery_image_id')) + creation_data['gallery_image_reference'] = image_reference + + elif self.create_option == 'restore': + creation_data['create_option'] = self.disk_models.DiskCreateOption.Restore + pass + elif self.create_option == 'copystart': + creation_data['create_option'] = self.disk_models.DiskCreateOption.CopyStart + pass + elif self.create_option == 'importsecure': + creation_data['create_option'] = self.disk_models.DiskCreateOption.ImportSecure + creation_data['source_uri'] = self.source_uri + creation_data['storage_account_id'] = self.storage_account_id + creation_data['security_data_uri'] = self.security_data_uri + elif self.create_option == 'uploadpreparedsecure': + creation_data['create_option'] = self.disk_models.DiskCreateOption.UploadPreparedSecure + creation_data['upload_size_bytes'] = self.upload_size_bytes + elif self.create_option == 'copyfromsansnapshot': + creation_data['create_option'] = self.disk_models.DiskCreateOption.CopyFromSanSnapshot + creation_data['elastic_san_resource_id'] = self.elastic_san_resource_id + else: + creation_data['create_option'] = self.disk_models.DiskCreateOption.empty + creation_data['logical_sector_size'] = self.logical_sector_size + creation_data['performance_plus'] = self.performance_plus if self.os_type: disk_params['os_type'] = self.disk_models.OperatingSystemTypes(self.os_type.capitalize()) else: diff --git a/plugins/modules/azure_rm_manageddisk_info.py b/plugins/modules/azure_rm_manageddisk_info.py index d30f42f9a..e6161f82b 100644 --- a/plugins/modules/azure_rm_manageddisk_info.py +++ b/plugins/modules/azure_rm_manageddisk_info.py @@ -196,6 +196,48 @@ type: str returned: always sample: '/subscriptions/*********/resourceGroups/myRG/providers/Microsoft.Compute/diskAccesses/diskacc' + performance_plus: + description: + - The flag of the performance target of the disk deployed. + type: bool + returned: always + sample: False + upload_size_bytes: + description: + - This is the size of the contents of the upload including the VHD footer. + type: int + returned: always + sample: None + disk_image_reference: + description: + - Disk source information for PIR or user images or Gallery Image. + type: dict + returned: always + sample: None + logical_sector_size: + description: + - Logical sector size in bytes for Ultra disks. + type: int + returned: always + sample: None + security_data_uri: + description: + - This is the URI of a blob to be imported into VM guest state. + type: str + returned: always + sample: None + elastic_san_resource_id: + description: + - This is the ARM id of the source elastic san volume snapshot. + type: str + returned: always + sample: None + source_resource_id: + description: + - This is the ARM id of the source snapshot or disk. + type: str + returned: always + sample: None ''' from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase @@ -323,7 +365,23 @@ def managed_disk_to_dict(self, managed_disk): tier=managed_disk.tier, network_access_policy=managed_disk.network_access_policy, public_network_access=managed_disk.public_network_access, - disk_access_id=managed_disk.disk_access_id + disk_access_id=managed_disk.disk_access_id, + storage_account_id=create_data.storage_account_id, + upload_size_bytes=create_data.upload_size_bytes, + logical_sector_size=create_data.logical_sector_size, + security_data_uri=create_data.security_data_uri, + performance_plus=create_data.performance_plus, + elastic_san_resource_id=create_data.elastic_san_resource_id, + gallery_image_reference=dict( + id=create_data.gallery_image_reference.id, + shared_gallery_image_id=create_data.gallery_image_reference.shared_gallery_image_id, + community_gallery_image_id=create_data.gallery_image_reference.community_gallery_image_id + ) if create_data.gallery_image_reference is not None else None, + image_reference=dict( + id=create_data.gallery_image_reference.id, + shared_gallery_image_id=create_data.gallery_image_reference.shared_gallery_image_id, + community_gallery_image_id=create_data.gallery_image_reference.community_gallery_image_id + ) if create_data.image_reference is not None else None ) diff --git a/tests/integration/targets/azure_rm_manageddisk/tasks/main.yml b/tests/integration/targets/azure_rm_manageddisk/tasks/main.yml index 8ce68db7f..3d8211259 100644 --- a/tests/integration/targets/azure_rm_manageddisk/tasks/main.yml +++ b/tests/integration/targets/azure_rm_manageddisk/tasks/main.yml @@ -74,7 +74,7 @@ resource_group: "{{ resource_group }}" name: "md{{ rpfx }}2" create_option: "copy" - source_uri: "{{ output.state.id }}" + source_resource_id: "{{ output.state.id }}" disk_size_gb: 1 register: disk2