Enhancement: implement EC2 instance filtering by subnet-id (#3694)

Co-authored-by: Tony Greising-Murschel <tony@platform.sh>
This commit is contained in:
tony-dot-sh 2021-02-15 09:38:40 -07:00 committed by GitHub
parent def46b5130
commit 9feabf5479
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -379,6 +379,7 @@ filter_dict_attribute_mapping = {
"network-interface.private-dns-name": "private_dns",
"private-dns-name": "private_dns",
"owner-id": "owner_id",
"subnet-id": "subnet_id",
}

View File

@ -606,6 +606,29 @@ def test_get_instances_filtering_by_instance_group_id():
reservations[0]["Instances"].should.have.length_of(1)
@mock_ec2
def test_get_instances_filtering_by_subnet_id():
client = boto3.client("ec2", region_name="us-east-1")
vpc_cidr = ipaddress.ip_network("192.168.42.0/24")
subnet_cidr = ipaddress.ip_network("192.168.42.0/25")
resp = client.create_vpc(CidrBlock=str(vpc_cidr),)
vpc_id = resp["Vpc"]["VpcId"]
resp = client.create_subnet(CidrBlock=str(subnet_cidr), VpcId=vpc_id)
subnet_id = resp["Subnet"]["SubnetId"]
client.run_instances(
ImageId=EXAMPLE_AMI_ID, MaxCount=1, MinCount=1, SubnetId=subnet_id,
)
reservations = client.describe_instances(
Filters=[{"Name": "subnet-id", "Values": [subnet_id]}]
)["Reservations"]
reservations.should.have.length_of(1)
@mock_ec2_deprecated
def test_get_instances_filtering_by_tag():
conn = boto.connect_ec2()