1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Allow ec2_vpc_net to work in non classiclink regions (#34336)

describe_vpc_classic_link only works in regions that support
EC2-Classic.
This commit is contained in:
Will Thames 2018-01-04 06:36:02 +10:00 committed by Ryan Brown
parent b40c779e46
commit 1412d6eb18

View file

@ -196,9 +196,17 @@ def vpc_exists(module, vpc, name, cidr_block, multi):
def get_vpc(module, connection, vpc_id): def get_vpc(module, connection, vpc_id):
try: try:
vpc_obj = connection.describe_vpcs(VpcIds=[vpc_id])['Vpcs'][0] vpc_obj = connection.describe_vpcs(VpcIds=[vpc_id])['Vpcs'][0]
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Failed to describe VPCs")
try:
classic_link = connection.describe_vpc_classic_link(VpcIds=[vpc_id])['Vpcs'][0].get('ClassicLinkEnabled') classic_link = connection.describe_vpc_classic_link(VpcIds=[vpc_id])['Vpcs'][0].get('ClassicLinkEnabled')
vpc_obj['ClassicLinkEnabled'] = classic_link vpc_obj['ClassicLinkEnabled'] = classic_link
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: except botocore.exceptions.ClientError as e:
if e.response["Error"]["Message"] == "The functionality you requested is not available in this region.":
vpc_obj['ClassicLinkEnabled'] = False
else:
module.fail_json_aws(e, msg="Failed to describe VPCs")
except botocore.exceptions.BotoCoreError as e:
module.fail_json_aws(e, msg="Failed to describe VPCs") module.fail_json_aws(e, msg="Failed to describe VPCs")
return vpc_obj return vpc_obj