Skip to content

Commit

Permalink
Add parameter zones to azure_rm_loadbalancer (#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fred-sun authored Mar 31, 2022
1 parent fc66c06 commit 7ac2d19
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
52 changes: 41 additions & 11 deletions plugins/modules/azure_rm_loadbalancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@
description:
- The reference of the subnet resource.
- Should be an existing subnet's resource id.
zones:
description:
- list of availability zones denoting the IP allocated for the resource needs to come from.
- This must be specified I(sku=Standard) and I(subnet) when setting zones.
type: list
elements: str
backend_address_pools:
description:
- List of backend address pools.
Expand Down Expand Up @@ -419,6 +426,10 @@
),
subnet=dict(
type='str'
),
zones=dict(
type='list',
elements='str'
)
)

Expand Down Expand Up @@ -770,17 +781,36 @@ def exec_module(self, **kwargs):
)] if self.protocol else None

# create new load balancer structure early, so it can be easily compared
frontend_ip_configurations_param = [self.network_models.FrontendIPConfiguration(
name=item.get('name'),
public_ip_address=self.get_public_ip_address_instance(item.get('public_ip_address')) if item.get('public_ip_address') else None,
private_ip_address=item.get('private_ip_address'),
private_ip_allocation_method=item.get('private_ip_allocation_method'),
subnet=self.network_models.Subnet(
id=item.get('subnet'),
private_endpoint_network_policies=None,
private_link_service_network_policies=None
) if item.get('subnet') else None
) for item in self.frontend_ip_configurations] if self.frontend_ip_configurations else None
if not load_balancer:
frontend_ip_configurations_param = [self.network_models.FrontendIPConfiguration(
name=item.get('name'),
public_ip_address=self.get_public_ip_address_instance(item.get('public_ip_address')) if item.get('public_ip_address') else None,
private_ip_address=item.get('private_ip_address'),
private_ip_allocation_method=item.get('private_ip_allocation_method'),
zones=item.get('zones'),
subnet=self.network_models.Subnet(
id=item.get('subnet'),
private_endpoint_network_policies=None,
private_link_service_network_policies=None
) if item.get('subnet') else None
) for item in self.frontend_ip_configurations] if self.frontend_ip_configurations else None
else:
old_front = load_balancer.frontend_ip_configurations
new_front = self.frontend_ip_configurations
frontend_ip_configurations_param = [self.network_models.FrontendIPConfiguration(
name=new_front[index].get('name'),
public_ip_address=self.get_public_ip_address_instance(
new_front[index].get('public_ip_address')
) if new_front[index].get('public_ip_address') else None,
private_ip_address=new_front[index].get('private_ip_address'),
private_ip_allocation_method=new_front[index].get('private_ip_allocation_method'),
zones=new_front[index].get('zones') if new_front[index].get('zones') else old_front[index].zones,
subnet=self.network_models.Subnet(
id=new_front[index].get('subnet'),
private_endpoint_network_policies=None,
private_link_service_network_policies=None
) if new_front[index].get('subnet') else None
) for index in range(len(new_front))] if new_front else None

backend_address_pools_param = [self.network_models.BackendAddressPool(
name=item.get('name')
Expand Down
1 change: 1 addition & 0 deletions plugins/modules/azure_rm_loadbalancer_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
myAzureResourceGroup/providers/Microsoft.Network/publicIPAddresses/testpip"
}
},
"zones": ["1", "2", "3"],
"type": "Microsoft.Network/loadBalancers/frontendIPConfigurations"
}
],
Expand Down
12 changes: 10 additions & 2 deletions tests/integration/targets/azure_rm_loadbalancer/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@

- name: assert complex load balancer created
assert:
that: output.changed
that:
- output.changed

- name: delete load balancer
azure_rm_loadbalancer:
Expand Down Expand Up @@ -263,11 +264,16 @@
azure_rm_loadbalancer:
resource_group: '{{ resource_group }}'
name: "{{ lbname_d }}"
sku: Standard
frontend_ip_configurations:
- name: frontendipconf0
private_ip_address: 10.10.0.10
private_ip_allocation_method: Static
subnet: "{{ subnet.state.id }}"
zones:
- 1
- 2
- 3
backend_address_pools:
- name: backendaddrpool0
probes:
Expand All @@ -291,7 +297,9 @@

- name: assert complex load balancer created
assert:
that: output.changed
that:
- output.changed
- output.state.frontend_ip_configurations[0].zones | length == 3

- name: delete load balancer
azure_rm_loadbalancer:
Expand Down

0 comments on commit 7ac2d19

Please sign in to comment.