# Buggy code
def update_vpc_tags(connection, module, vpc_id, tags, name):
    if tags is None:
        tags = dict()

    tags.update({"Name": name})
    try:
        current_tags = dict(
            (t["Key"], t["Value"])
            for t in connection.describe_tags(
                Filters=[{"Name": "resource-id", "Values": [vpc_id]}]
            )["Tags"]
        )
        if tags != current_tags:
            if not module.check_mode:
                tags = ansible_dict_to_boto3_tag_list(tags)
                vpc_obj = AWSRetry.backoff(
                    delay=1,
                    tries=5,
                    catch_extra_error_codes=["InvalidVpcID.NotFound"],
                )(connection.create_tags)(Resources=[vpc_id], Tags=tags)
            return True
        else:
            return False
    except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg="Failed to update tags")


# Traceback (boto.exception.EC2ResponseError)
Traceback (most recent call last):
File "/tmp/ansible_oqa3j78q/ansible_module_ec2_vpc_dhcp_option.py", line 233, in ensure_tags
vpc_conn.create_tags(resource_id, to_add, dry_run=check_mode)
File "/usr/local/lib/python3.6/dist-packages/boto/ec2/connection.py", line 4219, in create_tags
return self.get_status('CreateTags', params, verb='POST')
File "/usr/local/lib/python3.6/dist-packages/boto/connection.py", line 1227, in get_status
raise self.ResponseError(response.status, response.reason, body)
boto.exception.EC2ResponseError: EC2ResponseError: 400 Bad Request
<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>InvalidDhcpOptionsID.NotFound</Code><Message>The dhcpOptions ID 'dopt-6cf05914' does not exist</Message></Error></Errors><RequestID>d602f51a-66b5-445f-9b5b-38ffdbccda29</RequestID></Response>

# Fixed code
def update_vpc_tags(connection, module, vpc_id, tags, name):
    if tags is None:
        tags = dict()

    tags.update({"Name": name})
    try:
        current_tags = dict(
            (t["Key"], t["Value"])
            for t in connection.describe_tags(
                Filters=[{"Name": "resource-id", "Values": [vpc_id]}]
            )["Tags"]
        )
        if tags != current_tags:
            if not module.check_mode:
                tags = ansible_dict_to_boto3_tag_list(tags)
                vpc_obj = AWSRetry.backoff(
                    delay=1,
                    tries=5,
                    catch_extra_error_codes=["InvalidVpcID.NotFound"],
                )(connection.create_tags)(Resources=[vpc_id], Tags=tags)

                # Wait for tags to be updated
                expected_tags = boto3_tag_list_to_ansible_dict(tags)
                filters = [
                    {"Name": "tag:{0}".format(key), "Values": [value]}
                    for key, value in expected_tags.items()
                ]
                connection.get_waiter("vpc_available").wait(
                    VpcIds=[vpc_id], Filters=filters
                )

            return True
        else:
            return False
    except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg="Failed to update tags")