parent
a2bd4515eb
commit
4a336b8b04
@ -3,6 +3,7 @@ import uuid
|
||||
import six
|
||||
from boto3 import Session
|
||||
|
||||
from moto.core import ACCOUNT_ID
|
||||
from moto.core import BaseBackend
|
||||
from moto.core.exceptions import RESTError
|
||||
|
||||
@ -367,6 +368,23 @@ class ResourceGroupsTaggingAPIBackend(BaseBackend):
|
||||
# RedShift Subnet group
|
||||
|
||||
# VPC
|
||||
if (
|
||||
not resource_type_filters
|
||||
or "ec2" in resource_type_filters
|
||||
or "ec2:vpc" in resource_type_filters
|
||||
):
|
||||
for vpc in self.ec2_backend.vpcs.values():
|
||||
tags = get_ec2_tags(vpc.id)
|
||||
if not tags or not tag_filter(
|
||||
tags
|
||||
): # Skip if no tags, or invalid filter
|
||||
continue
|
||||
yield {
|
||||
"ResourceARN": "arn:aws:ec2:{0}:{1}:vpc/{2}".format(
|
||||
self.region_name, ACCOUNT_ID, vpc.id
|
||||
),
|
||||
"Tags": tags,
|
||||
}
|
||||
# VPC Customer Gateway
|
||||
# VPC DHCP Option Set
|
||||
# VPC Internet Gateway
|
||||
|
@ -61,6 +61,27 @@ def test_get_resources_ec2():
|
||||
resp["ResourceTagMappingList"][0]["ResourceARN"].should.contain("instance/")
|
||||
|
||||
|
||||
@mock_ec2
|
||||
@mock_resourcegroupstaggingapi
|
||||
def test_get_resources_ec2_vpc():
|
||||
ec2 = boto3.resource("ec2", region_name="us-west-1")
|
||||
vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")
|
||||
ec2.create_tags(Resources=[vpc.id], Tags=[{"Key": "test", "Value": "test"}])
|
||||
|
||||
def assert_response(resp):
|
||||
results = resp.get("ResourceTagMappingList", [])
|
||||
results.should.have.length_of(1)
|
||||
vpc.id.should.be.within(results[0]["ResourceARN"])
|
||||
|
||||
rtapi = boto3.client("resourcegroupstaggingapi", region_name="us-west-1")
|
||||
resp = rtapi.get_resources(ResourceTypeFilters=["ec2"])
|
||||
assert_response(resp)
|
||||
resp = rtapi.get_resources(ResourceTypeFilters=["ec2:vpc"])
|
||||
assert_response(resp)
|
||||
resp = rtapi.get_resources(TagFilters=[{"Key": "test", "Values": ["test"]}])
|
||||
assert_response(resp)
|
||||
|
||||
|
||||
@mock_ec2
|
||||
@mock_resourcegroupstaggingapi
|
||||
def test_get_tag_keys_ec2():
|
||||
|
Loading…
Reference in New Issue
Block a user