From afbcc3a196dfed9f2690e9b260274f0496ea350b Mon Sep 17 00:00:00 2001 From: Microsoft Visual Studio China Ansible on Azure robot <37099836+ansibleazurebot@users.noreply.github.com> Date: Wed, 24 Apr 2019 17:38:48 +0800 Subject: [PATCH] Merged changes of Azure modules from Ansible repo (#97) --- files/sha.json | 6 +- library/_azure_rm_managed_disk_facts.py | 3 +- library/_azure_rm_virtualmachine_scaleset.py | 6 + library/azure_rm_functionapp.py | 4 +- library/azure_rm_functionapp_facts.py | 2 +- library/azure_rm_loadbalancer.py | 2 +- library/azure_rm_loadbalancer_facts.py | 2 +- library/azure_rm_manageddisk_facts.py | 3 +- library/azure_rm_resourcegroup_facts.py | 5 +- library/azure_rm_virtualmachinescaleset.py | 6 + module_utils/azure_rm_common.py | 9 +- .../targets/azure_rm_keyvault/tasks/main.yml | 8 +- .../targets/azure_rm_manageddisk/aliases | 1 - .../azure_rm_manageddisk/tasks/main.yml | 400 ++---------------- .../targets/azure_rm_resourcegroup/aliases | 4 + .../azure_rm_resourcegroup/meta/main.yml | 2 + .../azure_rm_resourcegroup/tasks/main.yml | 39 ++ 17 files changed, 123 insertions(+), 379 deletions(-) create mode 100644 tests/integration/targets/azure_rm_resourcegroup/aliases create mode 100644 tests/integration/targets/azure_rm_resourcegroup/meta/main.yml create mode 100644 tests/integration/targets/azure_rm_resourcegroup/tasks/main.yml diff --git a/files/sha.json b/files/sha.json index 74d6b00..4729731 100644 --- a/files/sha.json +++ b/files/sha.json @@ -1,6 +1,6 @@ { - "lib/ansible/module_utils/azure_rm_common.py": "8b1b22ddc7dad0d901ecbd96a982e34429bdfdb9", - "lib/ansible/modules/cloud/azure": "22f666c9620396fb1ff7f4559b91182674e99008", + "lib/ansible/module_utils/azure_rm_common.py": "204db4d0444b2d1d3929774b5ac11b71893d3fb6", + "lib/ansible/modules/cloud/azure": "8de2acb81979cf09f661a74e1bc25bf4a3f453da", "packaging/requirements/requirements-azure.txt": "8b1b22ddc7dad0d901ecbd96a982e34429bdfdb9", - "test/integration/targets": "dcbfa60413ece9d3e68fa44fa303a79003bbec75" + "test/integration/targets": "0d3d0025055e03f778ef8f13abc4e8adb2f774b8" } \ No newline at end of file diff --git a/library/_azure_rm_managed_disk_facts.py b/library/_azure_rm_managed_disk_facts.py index 41ef9d7..3c329a7 100644 --- a/library/_azure_rm_managed_disk_facts.py +++ b/library/_azure_rm_managed_disk_facts.py @@ -138,7 +138,8 @@ def managed_disk_to_dict(managed_disk): disk_size_gb=managed_disk.disk_size_gb, os_type=managed_disk.os_type.lower() if managed_disk.os_type else None, storage_account_type=managed_disk.sku.name if managed_disk.sku else None, - managed_by=managed_disk.managed_by + managed_by=managed_disk.managed_by, + zone=managed_disk.zones[0] if managed_disk.zones and len(managed_disk.zones) > 0 else '' ) diff --git a/library/_azure_rm_virtualmachine_scaleset.py b/library/_azure_rm_virtualmachine_scaleset.py index fdd8919..040bb46 100644 --- a/library/_azure_rm_virtualmachine_scaleset.py +++ b/library/_azure_rm_virtualmachine_scaleset.py @@ -839,9 +839,15 @@ def exec_module(self, **kwargs): .ip_configurations[0].load_balancer_backend_address_pools = load_balancer_backend_address_pools vmss_resource.virtual_machine_profile.network_profile.network_interface_configurations[0] \ .ip_configurations[0].load_balancer_inbound_nat_pools = load_balancer_inbound_nat_pools + vmss_resource.virtual_machine_profile.network_profile.network_interface_configurations[0] \ + .ip_configurations[0].application_gateway_backend_address_pools = None elif self.application_gateway: vmss_resource.virtual_machine_profile.network_profile.network_interface_configurations[0] \ .ip_configurations[0].application_gateway_backend_address_pools = application_gateway_backend_address_pools + vmss_resource.virtual_machine_profile.network_profile.network_interface_configurations[0] \ + .ip_configurations[0].load_balancer_backend_address_pools = None + vmss_resource.virtual_machine_profile.network_profile.network_interface_configurations[0] \ + .ip_configurations[0].load_balancer_inbound_nat_pools = None if self.data_disks is not None: data_disks = [] diff --git a/library/azure_rm_functionapp.py b/library/azure_rm_functionapp.py index 2a93626..fe4fb6a 100644 --- a/library/azure_rm_functionapp.py +++ b/library/azure_rm_functionapp.py @@ -81,7 +81,7 @@ - azure_tags author: - - "Thomas Stringer (@tstringer)" + - "Thomas Stringer (@trstringer)" ''' EXAMPLES = ''' @@ -365,6 +365,8 @@ def necessary_functionapp_settings(self): function_app_settings.append(NameValuePair(name='WEBSITE_CONTENTSHARE', value=self.name)) else: function_app_settings.append(NameValuePair(name='FUNCTIONS_EXTENSION_VERSION', value='~2')) + function_app_settings.append(NameValuePair(name='WEBSITES_ENABLE_APP_SERVICE_STORAGE', value=False)) + function_app_settings.append(NameValuePair(name='AzureWebJobsStorage', value=self.storage_connection_string)) return function_app_settings diff --git a/library/azure_rm_functionapp_facts.py b/library/azure_rm_functionapp_facts.py index fee2f80..91df7de 100644 --- a/library/azure_rm_functionapp_facts.py +++ b/library/azure_rm_functionapp_facts.py @@ -37,7 +37,7 @@ - azure author: - - "Thomas Stringer (@tstringer)" + - "Thomas Stringer (@trstringer)" ''' EXAMPLES = ''' diff --git a/library/azure_rm_loadbalancer.py b/library/azure_rm_loadbalancer.py index 2289258..3e15607 100644 --- a/library/azure_rm_loadbalancer.py +++ b/library/azure_rm_loadbalancer.py @@ -332,7 +332,7 @@ - azure_tags author: - - "Thomas Stringer (@tstringer)" + - "Thomas Stringer (@trstringer)" - "Yuwei Zhou (@yuwzho)" ''' diff --git a/library/azure_rm_loadbalancer_facts.py b/library/azure_rm_loadbalancer_facts.py index 5a9b564..4202a18 100644 --- a/library/azure_rm_loadbalancer_facts.py +++ b/library/azure_rm_loadbalancer_facts.py @@ -39,7 +39,7 @@ - azure author: - - "Thomas Stringer (@tstringer)" + - "Thomas Stringer (@trstringer)" ''' EXAMPLES = ''' diff --git a/library/azure_rm_manageddisk_facts.py b/library/azure_rm_manageddisk_facts.py index 41ef9d7..3c329a7 100644 --- a/library/azure_rm_manageddisk_facts.py +++ b/library/azure_rm_manageddisk_facts.py @@ -138,7 +138,8 @@ def managed_disk_to_dict(managed_disk): disk_size_gb=managed_disk.disk_size_gb, os_type=managed_disk.os_type.lower() if managed_disk.os_type else None, storage_account_type=managed_disk.sku.name if managed_disk.sku else None, - managed_by=managed_disk.managed_by + managed_by=managed_disk.managed_by, + zone=managed_disk.zones[0] if managed_disk.zones and len(managed_disk.zones) > 0 else '' ) diff --git a/library/azure_rm_resourcegroup_facts.py b/library/azure_rm_resourcegroup_facts.py index 73bfa25..d051e73 100644 --- a/library/azure_rm_resourcegroup_facts.py +++ b/library/azure_rm_resourcegroup_facts.py @@ -145,7 +145,8 @@ def __init__(self): self.results = dict( changed=False, - ansible_facts=dict(azure_resourcegroups=[]) + ansible_facts=dict(azure_resourcegroups=[]), + resourcegroups=[] ) self.name = None @@ -170,6 +171,8 @@ def exec_module(self, **kwargs): for item in self.results['ansible_facts']['azure_resourcegroups']: item['resources'] = self.list_by_rg(item['name']) + self.results['resourcegroups'] = self.results['ansible_facts']['azure_resourcegroups'] + return self.results def get_item(self): diff --git a/library/azure_rm_virtualmachinescaleset.py b/library/azure_rm_virtualmachinescaleset.py index fdd8919..040bb46 100644 --- a/library/azure_rm_virtualmachinescaleset.py +++ b/library/azure_rm_virtualmachinescaleset.py @@ -839,9 +839,15 @@ def exec_module(self, **kwargs): .ip_configurations[0].load_balancer_backend_address_pools = load_balancer_backend_address_pools vmss_resource.virtual_machine_profile.network_profile.network_interface_configurations[0] \ .ip_configurations[0].load_balancer_inbound_nat_pools = load_balancer_inbound_nat_pools + vmss_resource.virtual_machine_profile.network_profile.network_interface_configurations[0] \ + .ip_configurations[0].application_gateway_backend_address_pools = None elif self.application_gateway: vmss_resource.virtual_machine_profile.network_profile.network_interface_configurations[0] \ .ip_configurations[0].application_gateway_backend_address_pools = application_gateway_backend_address_pools + vmss_resource.virtual_machine_profile.network_profile.network_interface_configurations[0] \ + .ip_configurations[0].load_balancer_backend_address_pools = None + vmss_resource.virtual_machine_profile.network_profile.network_interface_configurations[0] \ + .ip_configurations[0].load_balancer_inbound_nat_pools = None if self.data_disks is not None: data_disks = [] diff --git a/module_utils/azure_rm_common.py b/module_utils/azure_rm_common.py index b46144c..a25fa12 100644 --- a/module_utils/azure_rm_common.py +++ b/module_utils/azure_rm_common.py @@ -27,7 +27,7 @@ choices=['auto', 'cli', 'env', 'credential_file', 'msi'] ), profile=dict(type='str'), - subscription_id=dict(type='str', no_log=True), + subscription_id=dict(type='str'), client_id=dict(type='str', no_log=True), secret=dict(type='str', no_log=True), tenant=dict(type='str', no_log=True), @@ -1149,8 +1149,9 @@ def _get_profile(self, profile="default"): return None - def _get_msi_credentials(self, subscription_id_param=None): - credentials = MSIAuthentication() + def _get_msi_credentials(self, subscription_id_param=None, **kwargs): + client_id = kwargs.get('client_id', None) + credentials = MSIAuthentication(client_id=client_id) subscription_id = subscription_id_param or os.environ.get(AZURE_CREDENTIAL_ENV_MAPPING['subscription_id'], None) if not subscription_id: try: @@ -1206,7 +1207,7 @@ def _get_credentials(self, params): if auth_source == 'msi': self.log('Retrieving credenitals from MSI') - return self._get_msi_credentials(arg_credentials['subscription_id']) + return self._get_msi_credentials(arg_credentials['subscription_id'], client_id=params.get('client_id', None)) if auth_source == 'cli': if not HAS_AZURE_CLI_CORE: diff --git a/tests/integration/targets/azure_rm_keyvault/tasks/main.yml b/tests/integration/targets/azure_rm_keyvault/tasks/main.yml index eafb40a..a50f818 100644 --- a/tests/integration/targets/azure_rm_keyvault/tasks/main.yml +++ b/tests/integration/targets/azure_rm_keyvault/tasks/main.yml @@ -155,7 +155,7 @@ # azure_rm_keyvaultkey tests # -- name: create a kevyault key +- name: create a keyvault key block: - azure_rm_keyvaultkey: keyvault_uri: https://vault{{ rpfx }}.vault.azure.net @@ -172,7 +172,7 @@ state: absent key_name: testkey -- name: delete a kevyault key +- name: delete a keyvault key azure_rm_keyvaultkey: keyvault_uri: https://vault{{ rpfx }}.vault.azure.net state: absent @@ -185,7 +185,7 @@ # # azure_rm_keyvaultsecret tests # -- name: create a kevyault secret +- name: create a keyvault secret block: - azure_rm_keyvaultsecret: keyvault_uri: https://vault{{ rpfx }}.vault.azure.net @@ -203,7 +203,7 @@ state: absent secret_name: testsecret -- name: delete a kevyault secret +- name: delete a keyvault secret azure_rm_keyvaultsecret: keyvault_uri: https://vault{{ rpfx }}.vault.azure.net state: absent diff --git a/tests/integration/targets/azure_rm_manageddisk/aliases b/tests/integration/targets/azure_rm_manageddisk/aliases index 6f0d233..371e749 100644 --- a/tests/integration/targets/azure_rm_manageddisk/aliases +++ b/tests/integration/targets/azure_rm_manageddisk/aliases @@ -1,5 +1,4 @@ cloud/azure shippable/azure/group3 destructive -disabled azure_rm_manageddisk_facts diff --git a/tests/integration/targets/azure_rm_manageddisk/tasks/main.yml b/tests/integration/targets/azure_rm_manageddisk/tasks/main.yml index 7966133..89d7ac9 100644 --- a/tests/integration/targets/azure_rm_manageddisk/tasks/main.yml +++ b/tests/integration/targets/azure_rm_manageddisk/tasks/main.yml @@ -7,31 +7,13 @@ - name: Clearing (if) previous disks were created azure_rm_manageddisk: resource_group: "{{ resource_group }}" - name: "{{ item }}" + name: "md{{ rpfx }}{{ item }}" + managed_by: '' state: absent with_items: - - "md{{ rpfx }}os" - - "md{{ rpfx }}3" - - "md{{ rpfx }}2" - - "md{{ rpfx }}1" - - - name: Create managed disk (Check Mode) - azure_rm_manageddisk: - resource_group: "{{ resource_group }}" - name: "md{{ rpfx }}1" - storage_account_type: "Standard_LRS" - disk_size_gb: 1 - tags: - testing: testing - delete: never - register: output - check_mode: yes - - - name: Assert status succeeded (Check Mode) - assert: - that: - - output.changed - - output.state + - 1 + - 2 + - 3 - name: Test invalid account name (should give error) azure_rm_manageddisk: @@ -45,7 +27,7 @@ - name: Assert task failed assert: { that: "output['failed'] == True" } - - name: Create new managed disk succesfully + - name: Create managed disk (Check Mode) azure_rm_manageddisk: resource_group: "{{ resource_group }}" name: "md{{ rpfx }}1" @@ -55,71 +37,33 @@ testing: testing delete: never register: output + check_mode: yes - - name: Assert status succeeded and results include an Id value + - name: Assert status succeeded (Check Mode) assert: that: - output.changed - - output.state.disk_size_gb == 1 - - output.state.id is defined - - output.state.os_type == None - - output.state.storage_account_type == "Standard_LRS" + - output.state - - name: Create new managed disk with zone + - name: Create new managed disk succesfully azure_rm_manageddisk: resource_group: "{{ resource_group }}" - name: "md{{ rpfx }}3" + name: "md{{ rpfx }}1" storage_account_type: "Standard_LRS" disk_size_gb: 1 - zone: 1 tags: testing: testing delete: never register: output - - name: Assert status succeeded and results include an zone value + - name: Assert status succeeded and results include an Id value assert: that: - output.changed - - output.state.zone == ["1"] - - - name: Change the operating system type of the managed disk to linux - azure_rm_manageddisk: - resource_group: "{{ resource_group }}" - name: "md{{ rpfx }}1" - disk_size_gb: 1 - os_type: linux - storage_account_type: "Standard_LRS" - tags: - testing: testing - delete: never - register: output - - - assert: - that: - - output.changed - - output.state.os_type == 'linux' - - - name: Create new managed disk with an os_type specified at creation - azure_rm_manageddisk: - resource_group: "{{ resource_group }}" - name: "md{{ rpfx }}os" - storage_account_type: "Standard_LRS" - disk_size_gb: 1 - os_type: windows - register: win - - - name: Assert status of os_type specified at creation - assert: - that: - - win.changed - - win.state.os_type == 'windows' - - - name: Clean up managed disk created with os_type - azure_rm_manageddisk: - resource_group: "{{ resource_group }}" - name: "md{{ rpfx }}os" - state: absent + - output.state.disk_size_gb == 1 + - output.state.id is defined + - output.state.os_type == None + - output.state.storage_account_type == "Standard_LRS" - name: Copy disk to a new managed disk azure_rm_manageddisk: @@ -128,27 +72,31 @@ create_option: "copy" source_uri: "{{ output.state.id }}" disk_size_gb: 1 - register: copy + register: disk2 - name: Assert status succeeded and results include an Id value assert: that: - - copy.changed - - copy.state.id is defined + - disk2.changed + - disk2.state.id is defined - - name: Update a new disk without changes + - name: Create disk to a new managed disk with zone and os type azure_rm_manageddisk: resource_group: "{{ resource_group }}" - name: "md{{ rpfx }}1" - storage_account_type: "Standard_LRS" + name: "md{{ rpfx }}3" + source_uri: "{{ output.state.id }}" disk_size_gb: 1 - register: output + zone: "1" + os_type: windows + register: disk3 - name: Assert status succeeded and results include an Id value assert: that: - - not output.changed - - output.state.id is defined + - disk3.changed + - disk3.state.id is defined + - disk3.state.zone == "1" + - disk3.state.os_type == "windows" - name: Change storage account type to an invalid type azure_rm_manageddisk: @@ -162,101 +110,26 @@ - name: Assert storage account type change failed assert: { that: "output['failed'] == True" } - - name: Change disk size to incompatible size - azure_rm_manageddisk: - resource_group: "{{ resource_group }}" - name: "md{{ rpfx }}1" - disk_size_gb: 3000000 - register: output - ignore_errors: yes - - - name: Assert disk size change to incompatible size failure - assert: { that: "output['failed'] == True" } - - - name: Change disk to bigger size + - name: Update disk options (os_type, account_type, size, tags) azure_rm_manageddisk: resource_group: "{{ resource_group }}" name: "md{{ rpfx }}1" disk_size_gb: 2 - register: output - - - name: Assert status succeeded - assert: - that: - - output.changed - - output.state.disk_size_gb == 2 - - - name: Change disk to Standard SSD - azure_rm_manageddisk: - resource_group: "{{ resource_group }}" - name: "md{{ rpfx }}1" + os_type: linux storage_account_type: "StandardSSD_LRS" - disk_size_gb: 2 + tags: + galaxy: "no" + delete: never register: output - - name: Assert status succeeded - assert: - that: - - output.changed - - output.state.storage_account_type == "StandardSSD_LRS" - - - name: Gather facts to one specific disk - azure_rm_manageddisk_facts: - resource_group: "{{ resource_group }}" - name: "md{{ rpfx }}1" - - assert: - that: - - "azure_managed_disk | length == 1" - - azure_managed_disk[0].storage_account_type == "StandardSSD_LRS" - - - name: Change disk to Premium (SSD) - azure_rm_manageddisk: - resource_group: "{{ resource_group }}" - name: "md{{ rpfx }}1" - storage_account_type: "Premium_LRS" - disk_size_gb: 2 - register: output - - - name: Assert status succeeded - assert: that: - output.changed - - output.state.storage_account_type == "Premium_LRS" - - - name: Update disk tags - azure_rm_manageddisk: - resource_group: "{{ resource_group }}" - name: "md{{ rpfx }}1" - disk_size_gb: 2 - tags: - testing: testing - delete: never - galaxy: 'no' - register: output - - - name: Assert disk incremented tags - assert: - that: - - "output.state.tags | length == 3" - - "output.state.tags.galaxy == 'no'" - - - name: Update disk tags - azure_rm_manageddisk: - resource_group: "{{ resource_group }}" - name: "md{{ rpfx }}1" - disk_size_gb: 2 - tags: - testing: testing - delete: never - register: output - - - name: Assert disk tags are 2 - assert: - that: - - "output.state.tags | length == 2" - - "output.state.tags.testing == 'testing'" - - "output.state.tags.delete == 'never'" + - output.state.storage_account_type == "StandardSSD_LRS" + - output.state.disk_size_gb == 2 + - "output.state.tags | length == 2" + - "output.state.tags.galaxy == 'no'" + - output.state.os_type == 'linux' - name: Gather facts to one specific disk azure_rm_manageddisk_facts: @@ -266,18 +139,10 @@ - assert: that: - "azure_managed_disk | length == 1" - - azure_managed_disk[0].storage_account_type == "Premium_LRS" + - azure_managed_disk[0].storage_account_type == "StandardSSD_LRS" - azure_managed_disk[0].disk_size_gb == 2 - "azure_managed_disk[0].os_type == 'linux'" - - name: Gather facts - azure_rm_manageddisk_facts: - resource_group: "{{ resource_group }}" - - - assert: - that: - - "azure_managed_disk | length > 0" - - set_fact: parameter: "{{parameter |combine({item.key: item.value})}}" when: "{{item.key not in ['id', 'changed'] and item.value != None}}" @@ -298,191 +163,6 @@ that: - not output.changed - - name: Create virtual network - azure_rm_virtualnetwork: - resource_group: "{{ resource_group }}" - name: "tr{{ rpfx }}" - address_prefixes: "10.10.0.0/16" - - - name: Add subnet - azure_rm_subnet: - resource_group: "{{ resource_group }}" - name: "tr{{ rpfx }}" - address_prefix: "10.10.0.0/24" - virtual_network: "tr{{ rpfx }}" - - - name: Create public ip - azure_rm_publicipaddress: - resource_group: "{{ resource_group }}" - allocation_method: Static - name: "tr{{ rpfx }}" - - - name: Create security group - azure_rm_securitygroup: - resource_group: "{{ resource_group }}" - name: "tr{{ rpfx }}" - - - name: Create NIC - azure_rm_networkinterface: - resource_group: "{{ resource_group }}" - name: "tr{{ rpfx }}" - virtual_network: "tr{{ rpfx }}" - subnet: "tr{{ rpfx }}" - public_ip_name: "tr{{ rpfx }}" - security_group: "tr{{ rpfx }}" - - - name: Create virtual machine - azure_rm_virtualmachine: - resource_group: "{{ resource_group }}" - name: "tr{{ rpfx }}" - admin_username: adminuser - admin_password: Password123! - os_type: Linux - managed_disk_type: Premium_LRS - vm_size: Standard_DS1_v2 - network_interfaces: "tr{{ rpfx }}" - image: - offer: UbuntuServer - publisher: Canonical - sku: 16.04-LTS - version: latest - - - name: Mount the disk to virtual machine (check mode) - azure_rm_manageddisk: - resource_group: "{{ resource_group }}" - name: "md{{ rpfx }}1" - disk_size_gb: 2 - managed_by: "tr{{ rpfx }}" - tags: - testing: testing - delete: never - register: mounted - check_mode: yes - - - assert: - that: - - not mounted.state.managed_by - - - name: Mount the disk to virtual machine - azure_rm_manageddisk: - resource_group: "{{ resource_group }}" - name: "md{{ rpfx }}1" - disk_size_gb: 2 - managed_by: "tr{{ rpfx }}" - tags: - testing: testing - delete: never - register: mounted - - - assert: - that: - - "'tr{{ rpfx }}' in mounted.state.managed_by" - - - name: Mount the disk to virtual machine (idempotent) - azure_rm_manageddisk: - resource_group: "{{ resource_group }}" - name: "md{{ rpfx }}1" - disk_size_gb: 2 - tags: - testing: testing - delete: never - register: mounted - - - assert: - that: - - not mounted.changed - - "'tr{{ rpfx }}' in mounted.state.managed_by" - - - name: Unmount the disk to virtual machine (check mode) - azure_rm_manageddisk: - resource_group: "{{ resource_group }}" - name: "md{{ rpfx }}1" - disk_size_gb: 2 - managed_by: '' - tags: - testing: testing - delete: never - check_mode: yes - register: mounted - - - assert: - that: - - mounted.changed - - - name: Unmount the disk to virtual machine - azure_rm_manageddisk: - resource_group: "{{ resource_group }}" - name: "md{{ rpfx }}1" - disk_size_gb: 2 - managed_by: '' - tags: - testing: testing - delete: never - register: mounted - - - assert: - that: - - mounted.changed - - not mounted.state.managed_by - - - name: Unmount the disk to virtual machine (idempotent) - azure_rm_manageddisk: - resource_group: "{{ resource_group }}" - name: "md{{ rpfx }}1" - managed_by: '' - disk_size_gb: 2 - tags: - testing: testing - delete: never - register: mounted - - - assert: - that: - - not mounted.changed - - not mounted.state.managed_by - - - name: Update disk size - azure_rm_manageddisk: - resource_group: "{{ resource_group }}" - name: "md{{ rpfx }}1" - disk_size_gb: 4 - tags: - testing: testing - delete: never - register: output - - - assert: - that: - - output.state.disk_size_gb == 4 - - - name: Attach the disk to virtual machine again - azure_rm_manageddisk: - resource_group: "{{ resource_group }}" - name: "md{{ rpfx }}1" - disk_size_gb: 4 - managed_by: "tr{{ rpfx }}" - tags: - testing: testing - delete: never - register: mounted - - - assert: - that: - - mounted.changed - - "'tr{{ rpfx }}' in mounted.state.managed_by" - - - name: Change disk size to incompatible size - azure_rm_manageddisk: - resource_group: "{{ resource_group }}" - name: "md{{ rpfx }}1" - state: absent - managed_by: "tr{{ rpfx }}" - register: output - ignore_errors: yes - - - name: Assert delete failed since disk is attached to VM - assert: { that: "output['failed'] == True" } - - name: Delete managed disk (Check Mode) azure_rm_manageddisk: resource_group: "{{ resource_group }}" diff --git a/tests/integration/targets/azure_rm_resourcegroup/aliases b/tests/integration/targets/azure_rm_resourcegroup/aliases new file mode 100644 index 0000000..3b0b9bf --- /dev/null +++ b/tests/integration/targets/azure_rm_resourcegroup/aliases @@ -0,0 +1,4 @@ +cloud/azure +shippable/azure/group3 +destructive +azure_rm_resourcegroup_facts diff --git a/tests/integration/targets/azure_rm_resourcegroup/meta/main.yml b/tests/integration/targets/azure_rm_resourcegroup/meta/main.yml new file mode 100644 index 0000000..95e1952 --- /dev/null +++ b/tests/integration/targets/azure_rm_resourcegroup/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - setup_azure diff --git a/tests/integration/targets/azure_rm_resourcegroup/tasks/main.yml b/tests/integration/targets/azure_rm_resourcegroup/tasks/main.yml new file mode 100644 index 0000000..db45127 --- /dev/null +++ b/tests/integration/targets/azure_rm_resourcegroup/tasks/main.yml @@ -0,0 +1,39 @@ +- name: Get resource group facts + azure_rm_resourcegroup_facts: + register: rg + +- assert: + that: + - rg.resourcegroups | length >= 1 + +- name: Get resource group facts + azure_rm_resourcegroup_facts: + name: "{{ resource_group }}" + list_resources: yes + register: rg + +- assert: + that: + - rg.resourcegroups | length == 1 + - rg.resourcegroups[0].resources | length >= 0 + +- name: Create resource group (idempontent) + azure_rm_resourcegroup: + name: "{{ resource_group }}" + location: "{{ rg.resourcegroups[0].location }}" + register: output + +- assert: + that: + - not output.changed + +- name: delete resource group + azure_rm_resourcegroup: + name: "{{ resource_group }}" + state: absent + check_mode: yes + register: output + +- assert: + that: + - output.changed \ No newline at end of file