Fix CloudFormation AWS::Logs::LogGroup tagging (#7039)

This commit is contained in:
Jordan Sanders 2023-11-17 15:43:04 -06:00 committed by GitHub
parent fccdfb69e2
commit deeddfb72b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 1 deletions

View File

@ -410,7 +410,9 @@ class LogGroup(CloudFormationModel):
**kwargs: Any, **kwargs: Any,
) -> "LogGroup": ) -> "LogGroup":
properties = cloudformation_json["Properties"] properties = cloudformation_json["Properties"]
tags = properties.get("Tags", {}) tags = properties.get("Tags", [])
tags = dict([tag.values() for tag in tags])
return logs_backends[account_id][region_name].create_log_group( return logs_backends[account_id][region_name].create_log_group(
resource_name, tags, **properties resource_name, tags, **properties
) )

View File

@ -0,0 +1,31 @@
import json
import boto3
from moto import mock_cloudformation, mock_logs
@mock_logs
@mock_cloudformation
def test_tagging():
logs_client = boto3.client("logs", region_name="us-east-1")
cf_client = boto3.client("cloudformation", region_name="us-east-1")
template = {
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"testGroup": {
"Type": "AWS::Logs::LogGroup",
"Properties": {"Tags": [{"Key": "foo", "Value": "bar"}]},
}
},
}
template_json = json.dumps(template)
cf_client.create_stack(
StackName="test_stack",
TemplateBody=template_json,
)
arn = logs_client.describe_log_groups()["logGroups"][0]["arn"]
tags = logs_client.list_tags_for_resource(resourceArn=arn)["tags"]
assert tags == {"foo": "bar"}