diff --git a/changelogs/fragments/1109-ec2_vpc_net_info_keyerror.yml b/changelogs/fragments/1109-ec2_vpc_net_info_keyerror.yml new file mode 100644 index 00000000000..7c7303fa5bb --- /dev/null +++ b/changelogs/fragments/1109-ec2_vpc_net_info_keyerror.yml @@ -0,0 +1,3 @@ +bugfixes: + - ec2_vpc_net_info - fix KeyError (https://github.com/ansible-collections/amazon.aws/pull/1109). + - ec2_vpc_net_info - remove hardcoded ``ClassicLinkEnabled`` parameter when request for ``ClassicLinkDnsSupported`` failed (https://github.com/ansible-collections/amazon.aws/pull/1109). \ No newline at end of file diff --git a/plugins/modules/ec2_vpc_net_info.py b/plugins/modules/ec2_vpc_net_info.py index 21e2a75472f..eb10b957775 100644 --- a/plugins/modules/ec2_vpc_net_info.py +++ b/plugins/modules/ec2_vpc_net_info.py @@ -204,12 +204,12 @@ def describe_vpcs(connection, module): # loop through the ClassicLink Enabled results and add the value for the correct VPC for item in cl_enabled['Vpcs']: if vpc['VpcId'] == item['VpcId']: - vpc['ClassicLinkEnabled'] = item['ClassicLinkEnabled'] + vpc['ClassicLinkEnabled'] = item.get('ClassicLinkEnabled', False) if cl_dns_support: # loop through the ClassicLink DNS support results and add the value for the correct VPC for item in cl_dns_support['Vpcs']: if vpc['VpcId'] == item['VpcId']: - vpc['ClassicLinkDnsSupported'] = item['ClassicLinkDnsSupported'] + vpc['ClassicLinkDnsSupported'] = item.get('ClassicLinkDnsSupported', False) # add the two DNS attributes if dns_support: @@ -233,7 +233,7 @@ def describe_classic_links(module, connection, vpc, attribute, error_message): else: result = connection.describe_vpc_classic_link_dns_support(VpcIds=[vpc], aws_retry=True) except is_boto3_error_code('UnsupportedOperation'): - result = {'Vpcs': [{'VpcId': vpc, 'ClassicLinkEnabled': False}]} + result = {'Vpcs': [{'VpcId': vpc}]} except is_boto3_error_code('InvalidVpcID.NotFound'): module.warn(error_message.format(attribute, vpc)) except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: # pylint: disable=duplicate-except