# Buggy code
def main():
    argument_spec = ec2_argument_spec()
    argument_spec.update(
        dict(
            az=dict(default=None, required=False),
            cidr=dict(default=None, required=True),
            ipv6_cidr=dict(default="", required=False),
            state=dict(default="present", choices=["present", "absent"]),
            tags=dict(
                default={}, required=False, type="dict", aliases=["resource_tags"]
            ),
            vpc_id=dict(default=None, required=True),
            map_public=dict(default=False, required=False, type="bool"),
            assign_instances_ipv6=dict(default=False, required=False, type="bool"),
            wait=dict(type="bool", default=True),
            wait_timeout=dict(type="int", default=300, required=False),
            purge_tags=dict(default=True, type="bool"),
        )
    )

    required_if = [("assign_instances_ipv6", True, ["ipv6_cidr"])]

    module = AnsibleAWSModule(
        argument_spec=argument_spec, supports_check_mode=True, required_if=required_if
    )

    if module.params.get("assign_instances_ipv6") and not module.params.get(
        "ipv6_cidr"
    ):
        module.fail_json(
            msg="assign_instances_ipv6 is True but ipv6_cidr is None or an empty string"
        )

    region, ec2_url, aws_connect_params = get_aws_connection_info(module, boto3=True)
    connection = boto3_conn(
        module,
        conn_type="client",
        resource="ec2",
        region=region,
        endpoint=ec2_url,
        **aws_connect_params,
    )

    state = module.params.get("state")

    try:
        if state == "present":
            result = ensure_subnet_present(connection, module)
        elif state == "absent":
            result = ensure_subnet_absent(connection, module)
    except botocore.exceptions.ClientError as e:
        module.fail_json(
            msg=e.message,
            exception=traceback.format_exc(),
            **camel_dict_to_snake_dict(e.response),
        )

    module.exit_json(**result)


# Traceback (ClientError)
Traceback (most recent call last):
File "/tmp/ansible_dPE6PL/ansible_module_ec2_vpc_net.py", line 203, in get_vpc
classic_link = connection.describe_vpc_classic_link(VpcIds=[vpc_id])['Vpcs'][0].get('ClassicLinkEnabled')
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 317, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 615, in _make_api_call
raise error_class(parsed_response, operation_name)
ClientError: An error occurred (InvalidVpcID.NotFound) when calling the DescribeVpcClassicLink operation: The vpc ID 'vpc-1b2bda60' does not exist

# Fixed code
def main():
    argument_spec = ec2_argument_spec()
    argument_spec.update(
        dict(
            az=dict(default=None, required=False),
            cidr=dict(default=None, required=True),
            ipv6_cidr=dict(default="", required=False),
            state=dict(default="present", choices=["present", "absent"]),
            tags=dict(
                default={}, required=False, type="dict", aliases=["resource_tags"]
            ),
            vpc_id=dict(default=None, required=True),
            map_public=dict(default=False, required=False, type="bool"),
            assign_instances_ipv6=dict(default=False, required=False, type="bool"),
            wait=dict(type="bool", default=True),
            wait_timeout=dict(type="int", default=300, required=False),
            purge_tags=dict(default=True, type="bool"),
        )
    )

    required_if = [("assign_instances_ipv6", True, ["ipv6_cidr"])]

    module = AnsibleAWSModule(
        argument_spec=argument_spec, supports_check_mode=True, required_if=required_if
    )

    if module.params.get("assign_instances_ipv6") and not module.params.get(
        "ipv6_cidr"
    ):
        module.fail_json(
            msg="assign_instances_ipv6 is True but ipv6_cidr is None or an empty string"
        )

    region, ec2_url, aws_connect_params = get_aws_connection_info(module, boto3=True)
    connection = boto3_conn(
        module,
        conn_type="client",
        resource="ec2",
        region=region,
        endpoint=ec2_url,
        **aws_connect_params,
    )

    state = module.params.get("state")

    try:
        if state == "present":
            result = ensure_subnet_present(connection, module)
        elif state == "absent":
            result = ensure_subnet_absent(connection, module)
    except botocore.exceptions.ClientError as e:
        module.fail_json_aws(e)

    module.exit_json(**result)