Add tags to Elastic IP Addresses (#3310)

* Make ElasticAddress a tagged resource

To be able to filter on tags on ElasticAddresses, I need to have tags.

* remove unneeded commented lines

Was beginning of how to to it before further checking how it is done with other resources.

* do not ignore network-interface-owner-id filter

* add TODO about currently hardcoded region

* remove hardcoding region

* add testing for tags

creating and allocation, adding tags and querying for it

* separate test for tags into own method

* Linting

Co-authored-by: Bert Blommers <info@bertblommers.nl>
This commit is contained in:
Wolfgang Bauer 2020-09-25 16:25:30 +02:00 committed by GitHub
commit a4701dbbe6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 5 deletions

View file

@ -537,3 +537,48 @@ def test_eip_filters():
service.vpc_addresses.filter(Filters=[{"Name": "domain", "Values": ["vpc"]}])
)
len(addresses).should.equal(3)
@mock_ec2
def test_eip_tags():
service = boto3.resource("ec2", region_name="us-west-1")
client = boto3.client("ec2", region_name="us-west-1")
# Allocate one address without tags
client.allocate_address(Domain="vpc")
# Allocate one address and add tags
alloc_tags = client.allocate_address(Domain="vpc")
with_tags = client.create_tags(
Resources=[alloc_tags["AllocationId"]],
Tags=[{"Key": "ManagedBy", "Value": "MyCode"}],
)
addresses_with_tags = client.describe_addresses(
Filters=[
{"Name": "domain", "Values": ["vpc"]},
{"Name": "tag:ManagedBy", "Values": ["MyCode"]},
]
)
len(addresses_with_tags["Addresses"]).should.equal(1)
addresses_with_tags = list(
service.vpc_addresses.filter(
Filters=[
{"Name": "domain", "Values": ["vpc"]},
{"Name": "tag:ManagedBy", "Values": ["MyCode"]},
]
)
)
len(addresses_with_tags).should.equal(1)
addresses_with_tags = list(
service.vpc_addresses.filter(
Filters=[
{"Name": "domain", "Values": ["vpc"]},
{"Name": "tag:ManagedBy", "Values": ["SomethingOther"]},
]
)
)
len(addresses_with_tags).should.equal(0)
addresses = list(
service.vpc_addresses.filter(Filters=[{"Name": "domain", "Values": ["vpc"]}])
)
# Expected total is 2, one with and one without tags
len(addresses).should.equal(2)