Skip to content

Commit

Permalink
Add support for ZRS disks in virtualdisk and manageddisk modules
Browse files Browse the repository at this point in the history
  • Loading branch information
andreadecorte committed May 24, 2022
1 parent 70feb11 commit 68b01c5
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 5 deletions.
8 changes: 6 additions & 2 deletions plugins/modules/azure_rm_manageddisk.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@
- If not specified, the disk is created as C(Standard_LRS).
- C(Standard_LRS) is for Standard HDD.
- C(StandardSSD_LRS) (added in 2.8) is for Standard SSD.
- C(StandardSSD_ZRS) is for Standard SSD Zone-redundant.
- C(Premium_LRS) is for Premium SSD.
- C(UltraSSD_LRS) (added in 2.8) is for Ultra SSD, which is in preview mode, and only available on select instance types.
- C(Premium_ZRS) is for Premium SSD Zone-redundant.
- C(UltraSSD_LRS) (added in 2.8) is for Ultra SSD, which is only available on select instance types.
- See U(https://docs.microsoft.com/en-us/azure/virtual-machines/windows/disks-types) for more information about disk types.
choices:
- Standard_LRS
- StandardSSD_LRS
- StandardSSD_ZRS
- Premium_LRS
- Premium_ZRS
- UltraSSD_LRS
create_option:
description:
Expand Down Expand Up @@ -275,7 +279,7 @@ def __init__(self):
),
storage_account_type=dict(
type='str',
choices=['Standard_LRS', 'StandardSSD_LRS', 'Premium_LRS', 'UltraSSD_LRS']
choices=['Standard_LRS', 'StandardSSD_LRS', 'StandardSSD_ZRS', 'Premium_LRS', 'Premium_ZRS', 'UltraSSD_LRS']
),
create_option=dict(
type='str',
Expand Down
6 changes: 5 additions & 1 deletion plugins/modules/azure_rm_virtualmachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@
choices:
- Standard_LRS
- StandardSSD_LRS
- StandardSSD_ZRS
- Premium_LRS
- Premium_ZRS
os_disk_name:
description:
- OS disk name.
Expand Down Expand Up @@ -232,7 +234,9 @@
choices:
- Standard_LRS
- StandardSSD_LRS
- StandardSSD_ZRS
- Premium_LRS
- Premium_ZRS
storage_account_name:
description:
- Name of an existing storage account that supports creation of VHD blobs.
Expand Down Expand Up @@ -879,7 +883,7 @@ def __init__(self):
storage_blob_name=dict(type='str', aliases=['storage_blob']),
os_disk_caching=dict(type='str', aliases=['disk_caching'], choices=['ReadOnly', 'ReadWrite']),
os_disk_size_gb=dict(type='int'),
managed_disk_type=dict(type='str', choices=['Standard_LRS', 'StandardSSD_LRS', 'Premium_LRS']),
managed_disk_type=dict(type='str', choices=['Standard_LRS', 'StandardSSD_LRS', 'StandardSSD_ZRS', 'Premium_LRS', 'Premium_ZRS']),
os_disk_name=dict(type='str'),
proximity_placement_group=dict(type='dict', options=proximity_placement_group_spec),
os_type=dict(type='str', choices=['Linux', 'Windows'], default='Linux'),
Expand Down
58 changes: 57 additions & 1 deletion tests/integration/targets/azure_rm_manageddisk/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
azure_rm_manageddisk_info:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}1"
register: output
register: output

- assert:
that:
Expand Down Expand Up @@ -164,6 +164,60 @@
that:
- not output.changed

- name: Create new managed disk with I(account_type=StandardSSD_ZRS)
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}4"
storage_account_type: "StandardSSD_ZRS"
disk_size_gb: 2
location: westus2
register: output

- assert:
that:
- output.changed
- output.state.storage_account_type == "StandardSSD_ZRS"
- output.state.disk_size_gb == 2

- name: Gather facts to one specific disk
azure_rm_manageddisk_info:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}4"
register: output

- assert:
that:
- "output.ansible_info.azure_managed_disk | length == 1"
- output.ansible_info.azure_managed_disk[0].storage_account_type == "StandardSSD_ZRS"
- output.ansible_info.azure_managed_disk[0].disk_size_gb == 2

- name: Create new managed disk with I(account_type=Premium_ZRS)
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}5"
storage_account_type: "Premium_ZRS"
disk_size_gb: 2
location: westus2
register: output

- assert:
that:
- output.changed
- output.state.storage_account_type == "Premium_ZRS"
- output.state.disk_size_gb == 2

- name: Gather facts to one specific disk
azure_rm_manageddisk_info:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}5"
register: output

- assert:
that:
- "output.ansible_info.azure_managed_disk | length == 1"
- output.ansible_info.azure_managed_disk[0].storage_account_type == "Premium_ZRS"
- output.ansible_info.azure_managed_disk[0].disk_size_gb == 2

- name: Delete managed disk (Check Mode)
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
Expand All @@ -188,6 +242,8 @@
- 1
- 2
- 3
- 4
- 5

- name: Delete virtual machine
azure_rm_virtualmachine:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ all:
network: 10.42.3.0/24
subnet: 10.42.3.0/28

azure_test_minimal_manageddisk:
network: 10.42.3.0/24
subnet: 10.42.3.0/28

azure_test_dual_nic:
network: 10.42.4.0/24
subnet: 10.42.4.0/28
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/targets/azure_rm_virtualmachine/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- name: Run Azurue VM tests in parallel
- name: Run Azure VM tests in parallel
hosts: all
gather_facts: no
strategy: free
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
- name: Create virtual network
azure_rm_virtualnetwork:
resource_group: "{{ resource_group }}"
name: "{{ network_name }}-disk"
address_prefixes: "{{ network }}"
location: westus2

- name: Create subnet
azure_rm_subnet:
resource_group: "{{ resource_group }}"
name: "{{ subnet_name }}"
address_prefix: "{{ subnet }}"
virtual_network: "{{ network_name }}-disk"

- name: Create network interface
azure_rm_networkinterface:
resource_group: "{{ resource_group }}"
name: "{{ interface_name }}-disk"
virtual_network: "{{ network_name }}-disk"
subnet: "{{ subnet_name }}"
location: westus2

- name: Create minimal VM with defaults and a custom managed disk type
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}"
admin_username: "testuser"
ssh_password_enabled: false
managed_disk_type: StandardSSD_ZRS
public_ip_allocation_method: Disabled
location: westus2
network_interface_names:
- name: "{{ interface_name }}-disk"
resource_group: "{{ resource_group }}"
ssh_public_keys:
- path: /home/testuser/.ssh/authorized_keys
key_data: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDfoYlIV4lTPZTv7hXaVwQQuqBgGs4yeNRX0SPo2+HQt9u4X7IGwrtXc0nEUm6LfaCikMH58bOL8f20NTGz285kxdFHZRcBXtqmnMz2rXwhK9gwq5h1khc+GzHtdcJXsGA4y0xuaNcidcg04jxAlN/06fwb/VYwwWTVbypNC0gpGEpWckCNm8vlDlA55sU5et0SZ+J0RKVvEaweUOeNbFZqckGPA384imfeYlADppK/7eAxqfBVadVvZG8IJk4yvATgaIENIFj2cXxqu2mQ/Bp5Wr45uApvJsFXmi+v/nkiOEV1QpLOnEwAZo6EfFS4CCQtsymxJCl1PxdJ5LD4ZOtP xiuxi.sun@qq.com"
vm_size: Standard_B1ms
virtual_network: "{{ network_name }}-disk"
image:
offer: UbuntuServer
publisher: Canonical
sku: 16.04-LTS
version: latest
register: vm_output

- name: Assert status succeeded
assert:
that:
- vm_output.changed

- name: Delete VM
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}"
remove_on_absent: all_autocreated
state: absent

- name: Destroy NIC
azure_rm_networkinterface:
resource_group: "{{ resource_group }}"
name: "{{ interface_name }}-disk"
state: absent
ignore_errors: true

- name: Delete network security group
azure_rm_securitygroup:
resource_group: "{{ resource_group }}"
name: "{{ interface_name }}-disk"
state: absent

- name: Destroy disk
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}"
state: absent

- name: Destroy subnet
azure_rm_subnet:
resource_group: "{{ resource_group }}"
virtual_network: "{{ network_name }}"
name: "{{ subnet_name }}-disk"
state: absent

- name: Destroy virtual network
azure_rm_virtualnetwork:
resource_group: "{{ resource_group }}"
name: "{{ network_name }}-disk"
state: absent

0 comments on commit 68b01c5

Please sign in to comment.