Skip to content

Fix virtualnetworkgatewayconnection module not working for IPSec tunnel #1958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions plugins/modules/azure_rm_virtualnetworkgatewayconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,18 @@
type: bool
returned: always
sample: false
local_network_gateway2:
description:
- The reference to local network gateway resource.
type: complex
returned: when-used
contains:
id:
description:
- The ID of the local network gateway resource.
type: str
returned: always
sample: /subscriptions/xxx-xxx/resourceGroups/rg/providers/Microsoft.Network/localNetworkGateways/rpfx001
virtual_network_gateway1:
description:
- The reference to virtual network gateway resource.
Expand All @@ -282,7 +294,7 @@
description:
- The reference to virtual network gateway resource.
type: complex
returned: always
returned: when-used
contains:
id:
description:
Expand Down Expand Up @@ -430,8 +442,9 @@ def create_or_update_network_gateway_connection(self):
response = None
try:
body = dict(location=self.location,
virtual_network_gateway1=dict(id=self.virtual_network_gateway1),
virtual_network_gateway2=dict(id=self.virtual_network_gateway2),
virtual_network_gateway1=dict(id=self.virtual_network_gateway1) if self.virtual_network_gateway1 else None,
virtual_network_gateway2=dict(id=self.virtual_network_gateway2) if self.virtual_network_gateway2 else None,
local_network_gateway2=dict(id=self.local_network_gateway2) if self.local_network_gateway2 else None,
authorization_key=self.authorization_key,
connection_type=self.connection_type,
connection_protocol=self.connection_protocol,
Expand Down
21 changes: 18 additions & 3 deletions plugins/modules/azure_rm_virtualnetworkgatewayconnection_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@
type: bool
returned: always
sample: false
local_network_gateway2:
description:
- The reference to local network gateway resource.
type: complex
returned: when-used
contains:
id:
description:
- The ID of the local network gateway resource.
type: str
returned: always
sample: /subscriptions/xxx-xxx/resourceGroups/rg/providers/Microsoft.Network/localNetworkGateways/rpfx001
virtual_network_gateway1:
description:
- The reference to virtual network gateway resource.
Expand Down Expand Up @@ -316,11 +328,14 @@ def format_response(self, vngwconn):
use_policy_based_traffic_selectors=vngwconn.use_policy_based_traffic_selectors,
virtual_network_gateway1=None,
virtual_network_gateway2=None,
local_network_gateway2=None
)
if vngwconn.virtual_network_gateway2:
if vngwconn.local_network_gateway2 is not None:
result['local_network_gateway2'] = dict(id=vngwconn.local_network_gateway2.id)
if vngwconn.virtual_network_gateway1 is not None:
result['virtual_network_gateway1'] = dict(id=vngwconn.virtual_network_gateway1.id)
if vngwconn.virtual_network_gateway2 is not None:
result['virtual_network_gateway2'] = dict(id=vngwconn.virtual_network_gateway2.id)
if vngwconn.virtual_network_gateway1:
result['virtual_network_gateway1'] = dict(id=vngwconn.virtual_network_gateway2.id)

return result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
vngname: "vng{{ resource_group | hash('md5') | truncate(7, True, '') }}"
vnetname: "vnet{{ resource_group | hash('md5') | truncate(7, True, '') }}"
pubipname: "pip{{ resource_group | hash('md5') | truncate(7, True, '') }}"
rpfx: "{{ resource_group | hash('md5') | truncate(21, True, '') }}"
rpfx: "{{ resource_group | hash('md5') | truncate(22, True, '') }}"

- name: Create a new local network gateway
azure_rm_localnetworkgateway:
Expand All @@ -26,13 +26,13 @@
azure_rm_virtualnetwork:
resource_group: "{{ resource_group }}"
name: "{{ vnetname }}"
address_prefixes: "10.0.0.0/16"
address_prefixes: "30.0.0.0/16"

- name: Add subnet
azure_rm_subnet:
resource_group: "{{ resource_group }}"
name: GatewaySubnet
address_prefix: "10.0.2.0/24"
address_prefix: "30.0.2.0/24"
virtual_network: "{{ vnetname }}"

- name: Create public IP address
Expand All @@ -55,48 +55,14 @@
common: "xyz"
register: network_gateway1_output

- name: Create virtual network
azure_rm_virtualnetwork:
resource_group: "{{ resource_group }}"
name: "{{ vnetname }}02"
address_prefixes: "20.0.0.0/16"

- name: Add subnet
azure_rm_subnet:
resource_group: "{{ resource_group }}"
name: GatewaySubnet
address_prefix: "20.0.2.0/24"
virtual_network: "{{ vnetname }}02"

- name: Create public IP address
azure_rm_publicipaddress:
resource_group: "{{ resource_group }}"
allocation_method: Static
name: "{{ pubipname }}02"
sku: standard

- name: Create secondary virtual network gateway without bgp settings
azure_rm_virtualnetworkgateway:
resource_group: "{{ resource_group }}"
name: "{{ vngname }}02"
ip_configurations:
- name: testipconfig
private_ip_allocation_method: Dynamic
public_ip_address_name: "{{ pubipname }}02"
virtual_network: "{{ vnetname }}02"
tags:
common: "xyz"
register: network_gateway2_output

- name: Create a virtual network connection
azure_rm_virtualnetworkgatewayconnection:
resource_group: "{{ resource_group }}"
name: "new{{ rpfx }}"
virtual_network_gateway1: "{{ network_gateway1_output.id }}"
virtual_network_gateway2: "{{ network_gateway2_output.id }}"
local_network_gateway2: "{{ local_gateway_output.state.id }}"
authorization_key: Password@0329
connection_type: Vnet2Vnet
shared_key: Password@0329
connection_type: IPsec
connection_protocol: IKEv2
routing_weight: 0
dpd_timeout_seconds: 45
Expand All @@ -116,10 +82,9 @@
resource_group: "{{ resource_group }}"
name: "new{{ rpfx }}"
virtual_network_gateway1: "{{ network_gateway1_output.id }}"
virtual_network_gateway2: "{{ network_gateway2_output.id }}"
local_network_gateway2: "{{ local_gateway_output.state.id }}"
authorization_key: Password@0329
connection_type: Vnet2Vnet
shared_key: Password@0329
connection_type: IPsec
connection_protocol: IKEv2
routing_weight: 0
dpd_timeout_seconds: 45
Expand All @@ -139,10 +104,9 @@
resource_group: "{{ resource_group }}"
name: "new{{ rpfx }}"
virtual_network_gateway1: "{{ network_gateway1_output.id }}"
virtual_network_gateway2: "{{ network_gateway2_output.id }}"
local_network_gateway2: "{{ local_gateway_output.state.id }}"
authorization_key: Password@0329
connection_type: Vnet2Vnet
shared_key: Password@0329
connection_type: IPsec
connection_protocol: IKEv2
routing_weight: 1
dpd_timeout_seconds: 60
Expand Down Expand Up @@ -193,12 +157,6 @@
name: "{{ vngname }}"
state: absent

- name: Delete the secondary virtual network gateway
azure_rm_virtualnetworkgateway:
resource_group: "{{ resource_group }}"
name: "{{ vngname }}02"
state: absent

- name: Pause for 5 mimutes to delete the virtual network connection
ansible.builtin.command: sleep 300
changed_when: true
Expand All @@ -208,9 +166,3 @@
resource_group: "{{ resource_group }}"
name: "{{ pubipname }}"
state: absent

- name: Delete the public IP address
azure_rm_publicipaddress:
resource_group: "{{ resource_group }}"
name: "{{ pubipname }}02"
state: absent