From adb64bd97a90c2711d973686a84530f466e04485 Mon Sep 17 00:00:00 2001 From: Jordan Sanders Date: Tue, 28 Mar 2023 07:17:56 -0500 Subject: [PATCH] CloudFormation, Logs: Resolve LogGroup physical id and attributes (#6125) * CloudFormation, Logs: Add physical_resource_id to LogGroup https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-logs-loggroup.html#aws-resource-logs-loggroup-return-values This brings CloudFormation's Ref behavior more in line with actual AWS behavior. Previously, it returned an instance of a LogGroup model. I didn't add a test case for this but I'm happy to do so if requested. * Resolve LogGroup Fn::GetAtt https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-logs-loggroup.html#aws-resource-logs-loggroup-return-values * Add type annotations * Add return type annotation * Updating CloudFormation coverage --- CLOUDFORMATION_COVERAGE.md | 3 +-- moto/logs/models.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CLOUDFORMATION_COVERAGE.md b/CLOUDFORMATION_COVERAGE.md index 60619ff07..44f33f1c8 100644 --- a/CLOUDFORMATION_COVERAGE.md +++ b/CLOUDFORMATION_COVERAGE.md @@ -272,8 +272,7 @@ - [x] create implemented - [ ] update implemented - [ ] delete implemented - - [ ] Fn::GetAtt implemented - - [ ] Arn + - [x] Fn::GetAtt implemented - AWS::RDS::DBParameterGroup: - [x] create implemented - [ ] update implemented diff --git a/moto/logs/models.py b/moto/logs/models.py index f3fe935ee..633cb2704 100644 --- a/moto/logs/models.py +++ b/moto/logs/models.py @@ -306,6 +306,23 @@ class LogGroup(CloudFormationModel): resource_name, tags, **properties ) + @classmethod + def has_cfn_attr(cls, attr: str) -> bool: + return attr in [ + "Arn", + ] + + def get_cfn_attribute(self, attribute_name: str) -> str: + from moto.cloudformation.exceptions import UnformattedGetAttTemplateException + + if attribute_name == "Arn": + return self.arn + raise UnformattedGetAttTemplateException() + + @property + def physical_resource_id(self) -> str: + return self.name + def create_log_stream(self, log_stream_name: str) -> None: if log_stream_name in self.streams: raise ResourceAlreadyExistsException()