Fix ec2 filter by empty tag value (#3605)

* Fix ec2 filter by empty tag value

Return `None` instead of an empty string when the tag key does not exist
and replace the falsy check with a more explicit `is None`, which allows
empty string values to correctly pass through the filter comparator.

Behavior confirmed against a real AWS backend.

Closes #3603

* Make test case more explicit

Test case now pulled directly from the issue report (#3603).

Co-authored-by: Bert Blommers <bblommers@users.noreply.github.com>
This commit is contained in:
Brian Pandola 2021-01-24 04:00:25 -08:00 committed by GitHub
commit 38124ab1c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 2 deletions

View file

@ -249,7 +249,7 @@ class TaggedEC2Resource(BaseModel):
if tag["key"] == tagname:
return tag["value"]
return ""
return None
elif filter_name == "tag-key":
return [tag["key"] for tag in tags]
elif filter_name == "tag-value":

View file

@ -458,7 +458,7 @@ def filter_internet_gateways(igws, filter_dict):
def is_filter_matching(obj, filter, filter_value):
value = obj.get_filter_value(filter)
if not filter_value:
if filter_value is None:
return False
if isinstance(value, six.string_types):