From fef5f01b11da0688ecd04ea00e1e83759c870b0a Mon Sep 17 00:00:00 2001 From: Zim Kalinowski Date: Thu, 22 Mar 2018 10:10:29 +0800 Subject: [PATCH] =?UTF-8?q?adding=20possibility=20to=20specify=20resource?= =?UTF-8?q?=20group=20for=20referred=20virtual=20net=E2=80=A6=20(#36768)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * adding possibility to specify resource group for referred virtual network * fixed sanity issues * removed trailing whitespace * added test * fixed documentation * try to fix unstable test * Tidied up the description of virtual_network_resource_group --- .../cloud/azure/azure_rm_networkinterface.py | 16 +++++++++++++++- .../azure_rm_networkinterface/tasks/main.yml | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/cloud/azure/azure_rm_networkinterface.py b/lib/ansible/modules/cloud/azure/azure_rm_networkinterface.py index 7b8f50eff64..ff0718fc31e 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_networkinterface.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_networkinterface.py @@ -50,6 +50,15 @@ options: description: - Valid azure location. Defaults to location of the resource group. default: resource_group location + required: false + virtual_network_resource_group: + description: + - The resource group of I(virtual_network_name). + - If not set then this is the same resource group as I(resource_group). + - This can be used to specify the resource group of a virtual network that is in another resource group + than the network interface. + - If I(virtual_network_name) is specified as a virtual network id, this parameter is ignored. + version_added: 2.6 virtual_network_name: description: - Name or id of an existing virtual network with which the network interface will be associated. Required @@ -366,6 +375,7 @@ class AzureRMNetworkInterface(AzureRMModuleBase): public_ip_address_name=dict(type='str', aliases=['public_ip_address', 'public_ip_name']), public_ip=dict(type='bool', default=True), subnet_name=dict(type='str', aliases=['subnet']), + virtual_network_resource_group=dict(type='str'), virtual_network_name=dict(type='str', aliases=['virtual_network']), public_ip_allocation_method=dict(type='str', choices=['Dynamic', 'Static'], default='Dynamic'), ip_configurations=dict(type='list', default=None, elements='dict', options=ip_configuration_spec), @@ -386,6 +396,7 @@ class AzureRMNetworkInterface(AzureRMModuleBase): self.public_ip_address_name = None self.public_ip = None self.subnet_name = None + self.virtual_network_resource_group = None self.virtual_network_name = None self.public_ip_allocation_method = None self.state = None @@ -422,7 +433,10 @@ class AzureRMNetworkInterface(AzureRMModuleBase): # parse the virtual network resource group and name virtual_network_dict = parse_resource_id(self.virtual_network_name) virtual_network_name = virtual_network_dict.get('name') - virtual_network_resource_group = virtual_network_dict.get('resource_group', self.resource_group) + virtual_network_resource_group = virtual_network_dict.get('resource_group', self.virtual_network_resource_group) + + if virtual_network_resource_group is None: + virtual_network_resource_group = self.resource_group if self.state == 'present' and not self.ip_configurations: # construct the ip_configurations array for compatiable diff --git a/test/integration/targets/azure_rm_networkinterface/tasks/main.yml b/test/integration/targets/azure_rm_networkinterface/tasks/main.yml index ec1bd1f613c..d220ad39e2c 100644 --- a/test/integration/targets/azure_rm_networkinterface/tasks/main.yml +++ b/test/integration/targets/azure_rm_networkinterface/tasks/main.yml @@ -28,6 +28,24 @@ that: - output.changed +- name: Create NIC using virtual_network_resource_group parameter + azure_rm_networkinterface: + resource_group: "{{ resource_group }}" + name: testnic001rg + virtual_network: testnic001 + virtual_network_resource_group: "{{ resource_group_secondary }}" + subnet: testnic001 + public_ip_name: testnic001 + public_ip_allocation_method: Static + security_group: testnic001 + register: output + +- name: Delete NIC + azure_rm_networkinterface: + resource_group: "{{ resource_group }}" + name: testnic001rg + state: absent + - name: Create NIC azure_rm_networkinterface: resource_group: "{{ resource_group }}"