Fixed issue with tag changes affecting vpc attach
This commit is contained in:
parent
526ee48c0d
commit
20df1189b9
1 changed files with 40 additions and 40 deletions
|
@ -364,43 +364,43 @@ def ensure_vgw_present(client, module):
|
|||
vpn_gateway_id = existing_vgw[0]['VpnGatewayId']
|
||||
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)
|
||||
current_vpc_attachments = existing_vgw[0]['VpcAttachments']
|
||||
|
||||
# check that the vpc_id exists. If not, an exception is thrown
|
||||
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':
|
||||
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
|
||||
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':
|
||||
changed = False
|
||||
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)
|
||||
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
|
||||
|
||||
# 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
|
||||
|
||||
vgw = find_vgw(client, module, [vpn_gateway_id])
|
||||
vgw = find_vgw(client, module, [vpn_gateway_id])
|
||||
|
||||
else:
|
||||
# create a new vgw
|
||||
|
@ -468,7 +468,7 @@ def ensure_vgw_absent(client, module):
|
|||
|
||||
else:
|
||||
changed = False
|
||||
deleted_vgw = None
|
||||
deleted_vgw = "Nothing to do"
|
||||
|
||||
else:
|
||||
#Check that a name and type argument has been supplied if no vgw-id
|
||||
|
|
Loading…
Reference in a new issue