diff --git a/moto/resourcegroups/responses.py b/moto/resourcegroups/responses.py index d6895eeca..bda5d35df 100644 --- a/moto/resourcegroups/responses.py +++ b/moto/resourcegroups/responses.py @@ -71,6 +71,9 @@ class ResourceGroupsResponse(BaseResponse): def get_group_query(self): group_name = self._get_param("GroupName") + group_arn = self._get_param("Group") + if group_arn and not group_name: + group_name = group_arn.split(":")[-1] group = self.resourcegroups_backend.get_group(group_name=group_name) return json.dumps( { @@ -165,6 +168,9 @@ class ResourceGroupsResponse(BaseResponse): def update_group_query(self): group_name = self._get_param("GroupName") resource_query = self._get_param("ResourceQuery") + group_arn = self._get_param("Group") + if group_arn and not group_name: + group_name = group_arn.split(":")[-1] group = self.resourcegroups_backend.update_group_query( group_name=group_name, resource_query=resource_query ) diff --git a/tests/test_resourcegroups/test_resourcegroups.py b/tests/test_resourcegroups/test_resourcegroups.py index 7cf852ccb..c3dd1cd52 100644 --- a/tests/test_resourcegroups/test_resourcegroups.py +++ b/tests/test_resourcegroups/test_resourcegroups.py @@ -64,11 +64,18 @@ def test_get_group(): def test_get_group_query(): resource_groups = boto3.client("resource-groups", region_name="us-east-1") - test_create_group() + get_response = test_get_group() response = resource_groups.get_group_query(GroupName="test_resource_group") response["GroupQuery"]["ResourceQuery"]["Type"].should.contain("TAG_FILTERS_1_0") + response_get = resource_groups.get_group_query( + Group=get_response.get("Group").get("GroupArn") + ) + response_get["GroupQuery"]["ResourceQuery"]["Type"].should.contain( + "TAG_FILTERS_1_0" + ) + @mock_resourcegroups def test_get_tags(): @@ -136,7 +143,7 @@ def test_untag(): def test_update_group(): resource_groups = boto3.client("resource-groups", region_name="us-east-1") - test_get_group() + get_response = test_get_group() response = resource_groups.update_group( GroupName="test_resource_group", Description="description_2" @@ -220,7 +227,7 @@ def test_create_group_with_configuration(): def test_update_group_query(): resource_groups = boto3.client("resource-groups", region_name="us-east-1") - test_create_group() + group_response = test_get_group() response = resource_groups.update_group_query( GroupName="test_resource_group", @@ -245,3 +252,25 @@ def test_update_group_query(): response["GroupQuery"]["ResourceQuery"]["Type"].should.contain( "CLOUDFORMATION_STACK_1_0" ) + + response = resource_groups.update_group_query( + Group=group_response.get("Group").get("GroupArn"), + ResourceQuery={ + "Type": "TAG_FILTERS_1_0", + "Query": json.dumps( + { + "ResourceTypeFilters": ["AWS::AllSupported"], + "TagFilters": [ + {"Key": "resources_tag_key", "Values": ["resources_tag_value"]} + ], + } + ), + }, + ) + + response["GroupQuery"]["ResourceQuery"]["Type"].should.contain("TAG_FILTERS_1_0") + + response = resource_groups.get_group_query( + Group=group_response.get("Group").get("GroupArn") + ) + response["GroupQuery"]["ResourceQuery"]["Type"].should.contain("TAG_FILTERS_1_0")