# Buggy code
def main():
    argument_spec = ec2_argument_spec()
    argument_spec.update(
        dict(
            vpc_id=dict(),
            peer_vpc_id=dict(),
            peer_region=dict(),
            peering_id=dict(),
            peer_owner_id=dict(),
            tags=dict(required=False, type="dict"),
            profile=dict(),
            state=dict(
                default="present", choices=["present", "absent", "accept", "reject"]
            ),
        )
    )
    module = AnsibleModule(argument_spec=argument_spec)

    if not HAS_BOTO3:
        module.fail_json(msg="json, botocore and boto3 are required.")
    state = module.params.get("state")
    try:
        region, ec2_url, aws_connect_kwargs = get_aws_connection_info(
            module, boto3=True
        )
        client = boto3_conn(
            module,
            conn_type="client",
            resource="ec2",
            region=region,
            endpoint=ec2_url,
            **aws_connect_kwargs,
        )
    except botocore.exceptions.NoCredentialsError as e:
        module.fail_json(msg="Can't authorize connection - " + str(e))

    if state == "present":
        (changed, results) = create_peer_connection(client, module)
        module.exit_json(changed=changed, peering_id=results)
    elif state == "absent":
        remove_peer_connection(client, module)
    else:
        (changed, results) = accept_reject(state, client, module)
        module.exit_json(changed=changed, peering_id=results)


# Traceback (ParamValidationError)
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: Invalid type for parameter Filters[1].Values[0], value: None, type: <type 'NoneType'>, valid types: <type 'basestring'>
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_8K4qEm/ansible_module_ec2_vpc_peer.py\", line 398, in <module>\n    main()\n  File \"/tmp/ansible_8K4qEm/ansible_module_ec2_vpc_peer.py\", line 388, in main\n    (changed, results) = create_peer_connection(client, module)\n  File \"/tmp/ansible_8K4qEm/ansible_module_ec2_vpc_peer.py\", line 262, in create_peer_connection\n    peering_conns = describe_peering_connections(params, client)\n  File \"/tmp/ansible_8K4qEm/ansible_module_ec2_vpc_peer.py\", line 233, in describe_peering_connections\n    {'Name': 'accepter-vpc-info.vpc-id', 'Values': [params['PeerVpcId']]}\n  File \"/usr/lib/python2.6/site-packages/botocore/client.py\", line 314, in _api_call\n    return self._make_api_call(operation_name, kwargs)\n  File \"/usr/lib/python2.6/site-packages/botocore/client.py\", line 586, in _make_api_call\n    api_params, operation_model, context=request_context)\n  File \"/usr/lib/python2.6/site-packages/botocore/client.py\", line 621, in _convert_to_request_dict\n    api_params, operation_model)\n  File \"/usr/lib/python2.6/site-packages/botocore/validate.py\", line 291, in serialize_to_request\n    raise ParamValidationError(report=report.generate_report())\nbotocore.exceptions.ParamValidationError: Parameter validation failed:\nInvalid type for parameter Filters[0].Values[0], value: None, type: <type 'NoneType'>, valid types: <type 'basestring'>\nInvalid type for parameter Filters[1].Values[0], value: None, type: <type 'NoneType'>, valid types: <type 'basestring'>\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 1}

# Fixed code
def main():
    argument_spec = ec2_argument_spec()
    argument_spec.update(
        dict(
            vpc_id=dict(),
            peer_vpc_id=dict(),
            peer_region=dict(),
            peering_id=dict(),
            peer_owner_id=dict(),
            tags=dict(required=False, type="dict"),
            profile=dict(),
            state=dict(
                default="present", choices=["present", "absent", "accept", "reject"]
            ),
        )
    )
    required_if = [
        ("state", "present", ["vpc_id", "peer_vpc_id"]),
        ("state", "accept", ["peering_id"]),
        ("state", "reject", ["peering_id"]),
    ]

    module = AnsibleModule(argument_spec=argument_spec, required_if=required_if)

    if not HAS_BOTO3:
        module.fail_json(msg="json, botocore and boto3 are required.")
    state = module.params.get("state")
    peering_id = module.params.get("peering_id")
    vpc_id = module.params.get("vpc_id")
    peer_vpc_id = module.params.get("peer_vpc_id")
    try:
        region, ec2_url, aws_connect_kwargs = get_aws_connection_info(
            module, boto3=True
        )
        client = boto3_conn(
            module,
            conn_type="client",
            resource="ec2",
            region=region,
            endpoint=ec2_url,
            **aws_connect_kwargs,
        )
    except botocore.exceptions.NoCredentialsError as e:
        module.fail_json(msg="Can't authorize connection - " + str(e))

    if state == "present":
        (changed, results) = create_peer_connection(client, module)
        module.exit_json(changed=changed, peering_id=results)
    elif state == "absent":
        if not peering_id and (not vpc_id or not peer_vpc_id):
            module.fail_json(
                msg="state is absent but one of the following is missing: peering_id or [vpc_id, peer_vpc_id]"
            )

        remove_peer_connection(client, module)
    else:
        (changed, results) = accept_reject(state, client, module)
        module.exit_json(changed=changed, peering_id=results)