mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-28 19:20:22 -07:00
Fixed issue with tag changes affecting vpc attach
This commit is contained in:
parent
e5ead91439
commit
6de163cbb2
1 changed files with 40 additions and 40 deletions
|
@ -148,7 +148,7 @@ def attach_vgw(client, module, vpn_gateway_id):
|
||||||
status_achieved, vgw = wait_for_status(client, module, [vpn_gateway_id], 'attached')
|
status_achieved, vgw = wait_for_status(client, module, [vpn_gateway_id], 'attached')
|
||||||
if not status_achieved:
|
if not status_achieved:
|
||||||
module.fail_json(msg='Error waiting for vpc to attach to vgw - please check the AWS console')
|
module.fail_json(msg='Error waiting for vpc to attach to vgw - please check the AWS console')
|
||||||
|
|
||||||
result = response
|
result = response
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ def delete_vgw(client, module, vpn_gateway_id):
|
||||||
response = client.delete_vpn_gateway(VpnGatewayId=vpn_gateway_id)
|
response = client.delete_vpn_gateway(VpnGatewayId=vpn_gateway_id)
|
||||||
except botocore.exceptions.ClientError as e:
|
except botocore.exceptions.ClientError as e:
|
||||||
module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
|
|
||||||
#return the deleted VpnGatewayId as this is not included in the above response
|
#return the deleted VpnGatewayId as this is not included in the above response
|
||||||
result = vpn_gateway_id
|
result = vpn_gateway_id
|
||||||
return result
|
return result
|
||||||
|
@ -318,7 +318,7 @@ def find_vgw(client, module, vpn_gateway_id=None):
|
||||||
])
|
])
|
||||||
except botocore.exceptions.ClientError as e:
|
except botocore.exceptions.ClientError as e:
|
||||||
module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if vpn_gateway_id:
|
if vpn_gateway_id:
|
||||||
try:
|
try:
|
||||||
|
@ -334,7 +334,7 @@ def find_vgw(client, module, vpn_gateway_id=None):
|
||||||
])
|
])
|
||||||
except botocore.exceptions.ClientError as e:
|
except botocore.exceptions.ClientError as e:
|
||||||
module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
|
|
||||||
result = response['VpnGateways']
|
result = response['VpnGateways']
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -363,44 +363,44 @@ def ensure_vgw_present(client, module):
|
||||||
if existing_vgw != [] and existing_vgw[0]['State'] != 'deleted':
|
if existing_vgw != [] and existing_vgw[0]['State'] != 'deleted':
|
||||||
vpn_gateway_id = existing_vgw[0]['VpnGatewayId']
|
vpn_gateway_id = existing_vgw[0]['VpnGatewayId']
|
||||||
vgw, changed = check_tags(client, module, existing_vgw, vpn_gateway_id)
|
vgw, changed = check_tags(client, module, existing_vgw, vpn_gateway_id)
|
||||||
|
|
||||||
if not changed:
|
# if a vpc_id was provided, check if it exists and if it's attached
|
||||||
|
if params['VpcId']:
|
||||||
# if a vpc_id was provided, check if it exists and if it's attached
|
|
||||||
if params['VpcId']:
|
# check that the vpc_id exists. If not, an exception is thrown
|
||||||
|
vpc = find_vpc(client, module)
|
||||||
# check that the vpc_id exists. If not, an exception is thrown
|
current_vpc_attachments = existing_vgw[0]['VpcAttachments']
|
||||||
vpc = find_vpc(client, module)
|
|
||||||
current_vpc_attachments = existing_vgw[0]['VpcAttachments']
|
if current_vpc_attachments != [] and current_vpc_attachments[0]['State'] == 'attached':
|
||||||
|
if current_vpc_attachments[0]['VpcId'] == params['VpcId'] and current_vpc_attachments[0]['State'] == 'attached':
|
||||||
if current_vpc_attachments != [] and current_vpc_attachments[0]['State'] == 'attached':
|
changed = False
|
||||||
if current_vpc_attachments[0]['VpcId'] == params['VpcId'] and current_vpc_attachments[0]['State'] == 'attached':
|
|
||||||
changed = False
|
|
||||||
else:
|
|
||||||
|
|
||||||
# detach the existing vpc from the virtual gateway
|
|
||||||
vpc_to_detach = current_vpc_attachments[0]['VpcId']
|
|
||||||
detach_vgw(client, module, vpn_gateway_id, vpc_to_detach)
|
|
||||||
time.sleep(5)
|
|
||||||
attached_vgw = attach_vgw(client, module, vpn_gateway_id)
|
|
||||||
changed = True
|
|
||||||
else:
|
else:
|
||||||
# attach the vgw to the supplied vpc
|
|
||||||
|
# detach the existing vpc from the virtual gateway
|
||||||
|
vpc_to_detach = current_vpc_attachments[0]['VpcId']
|
||||||
|
detach_vgw(client, module, vpn_gateway_id, vpc_to_detach)
|
||||||
|
time.sleep(5)
|
||||||
attached_vgw = attach_vgw(client, module, vpn_gateway_id)
|
attached_vgw = attach_vgw(client, module, vpn_gateway_id)
|
||||||
|
vgw = find_vgw(client, module, [vpn_gateway_id])
|
||||||
|
changed = True
|
||||||
|
else:
|
||||||
|
# attach the vgw to the supplied vpc
|
||||||
|
attached_vgw = attach_vgw(client, module, vpn_gateway_id)
|
||||||
|
vgw = find_vgw(client, module, [vpn_gateway_id])
|
||||||
|
changed = True
|
||||||
|
|
||||||
|
# if params['VpcId'] is not provided, check the vgw is attached to a vpc. if so, detach it.
|
||||||
|
else:
|
||||||
|
existing_vgw = find_vgw(client, module, [vpn_gateway_id])
|
||||||
|
|
||||||
|
if existing_vgw[0]['VpcAttachments'] != []:
|
||||||
|
if existing_vgw[0]['VpcAttachments'][0]['State'] == 'attached':
|
||||||
|
# detach the vpc from the vgw
|
||||||
|
vpc_to_detach = existing_vgw[0]['VpcAttachments'][0]['VpcId']
|
||||||
|
detach_vgw(client, module, vpn_gateway_id, vpc_to_detach)
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
# if params['VpcId'] is not provided, check the vgw is attached to a vpc. if so, detach it.
|
vgw = find_vgw(client, module, [vpn_gateway_id])
|
||||||
else:
|
|
||||||
existing_vgw = find_vgw(client, module, [vpn_gateway_id])
|
|
||||||
|
|
||||||
if existing_vgw[0]['VpcAttachments'] != []:
|
|
||||||
if existing_vgw[0]['VpcAttachments'][0]['State'] == 'attached':
|
|
||||||
# detach the vpc from the vgw
|
|
||||||
vpc_to_detach = existing_vgw[0]['VpcAttachments'][0]['VpcId']
|
|
||||||
detach_vgw(client, module, vpn_gateway_id, vpc_to_detach)
|
|
||||||
changed = True
|
|
||||||
|
|
||||||
vgw = find_vgw(client, module, [vpn_gateway_id])
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# create a new vgw
|
# create a new vgw
|
||||||
|
@ -468,7 +468,7 @@ def ensure_vgw_absent(client, module):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
changed = False
|
changed = False
|
||||||
deleted_vgw = None
|
deleted_vgw = "Nothing to do"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
#Check that a name and type argument has been supplied if no vgw-id
|
#Check that a name and type argument has been supplied if no vgw-id
|
||||||
|
@ -551,4 +551,4 @@ from ansible.module_utils.basic import *
|
||||||
from ansible.module_utils.ec2 import *
|
from ansible.module_utils.ec2 import *
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
Loading…
Add table
Add a link
Reference in a new issue