Repository: aws-cloudformation/cfn-lint

Issue:
Don't validate SAM transformed resources for rule I3042
### CloudFormation Lint Version

v0.71.1

### What operating system are you using?

Mac

### Describe the bug

When SAM transforms templates it can create hardcoded ARNs based on its scenario. It would make sense to not validate those ARNs against rule I3042

### Expected behavior

To not raise I3042 on resources that are created by SAM transform.

### Reproduction template

```yaml

```


Discussion:

Resolving patch:
diff --git a/src/cfnlint/rules/resources/HardCodedArnProperties.py b/src/cfnlint/rules/resources/HardCodedArnProperties.py
--- a/src/cfnlint/rules/resources/HardCodedArnProperties.py
+++ b/src/cfnlint/rules/resources/HardCodedArnProperties.py
@@ -71,9 +71,13 @@ def match_values(self, cfn):
         return results
 
     def match(self, cfn):
-        """Check CloudFormation Resources"""
         matches = []
 
+        transforms = cfn.transform_pre["Transform"]
+        transforms = transforms if isinstance(transforms, list) else [transforms]
+        if "AWS::Serverless-2016-10-31" in cfn.transform_pre["Transform"]:
+            return matches
+
         # Get a list of paths to every leaf node string containing at least one ${parameter}
         parameter_string_paths = self.match_values(cfn)
         # We want to search all of the paths to check if each one contains an 'Fn::Sub'


Test patch:
diff --git a/test/fixtures/templates/good/resources/properties/hard_coded_arn_properties_sam.yaml b/test/fixtures/templates/good/resources/properties/hard_coded_arn_properties_sam.yaml
new file mode 100644
--- /dev/null
+++ b/test/fixtures/templates/good/resources/properties/hard_coded_arn_properties_sam.yaml
@@ -0,0 +1,80 @@
+AWSTemplateFormatVersion: 2010-09-09
+Transform: AWS::Serverless-2016-10-31
+Resources:
+  S3BadBucket:
+    Type: AWS::S3::Bucket
+    Properties:
+      AccessControl: Private
+      NotificationConfiguration:
+        TopicConfigurations:
+        - Topic: !Sub arn:aws:sns:us-east-1:123456789012:TestTopic
+          Event: s3:ReducedRedundancyLostObject
+
+  SampleBadBucketPolicy: 
+    Type: AWS::S3::BucketPolicy
+    Properties: 
+      Bucket: !Ref S3BadBucket
+      PolicyDocument: 
+        Statement: 
+          - Action: 
+              - s3:GetObject
+            Effect: Allow
+            Resource: !Sub arn:aws:s3:::${S3BadBucket}
+            Principal: "*"
+
+  SampleRole:
+    Type: AWS::IAM::Role
+    Properties:
+      AssumeRolePolicyDocument:
+        Version: '2012-10-17'
+        Statement:
+          - Effect: Allow
+            Principal:
+              Service:
+              - ec2.amazonaws.com
+            Action:
+              - 'sts:AssumeRole'
+      Path: /
+
+
+  SampleBadIAMPolicy1:
+    Type: AWS::IAM::ManagedPolicy
+    Properties:
+      PolicyDocument:
+        Version: '2012-10-17'
+        Statement:
+          - Effect: Allow
+            Action:
+              - sns:Publish
+            Resource: !Sub arn:${AWS::Partition}:sns:us-east-1:${AWS::AccountId}:TestTopic
+      Roles:
+        - !Ref SampleRole
+
+  SampleBadIAMPolicy2:
+    Type: AWS::IAM::ManagedPolicy
+    Properties:
+      PolicyDocument:
+        Version: '2012-10-17'
+        Statement:
+          - Effect: Allow
+            Action:
+              - sns:Publish
+            Resource: 
+              - !Sub arn:${AWS::Partition}:sns:us-east-1:${AWS::AccountId}:TestTopic
+              - !Sub arn:${AWS::Partition}:sns:${AWS::Region}:${AWS::AccountId}:TestTopic
+      Roles:
+        - !Ref SampleRole
+
+  SampleBadIAMPolicy3:
+    Type: AWS::IAM::ManagedPolicy
+    Properties:
+      PolicyDocument:
+        Version: '2012-10-17'
+        Statement:
+          - Effect: Allow
+            Action:
+              - sns:Publish
+            Resource: 
+              - !Sub arn:${AWS::Partition}:sns:${AWS::Partition}:${AWS::AccountId}:TestTopic
+      Roles:
+        - !Ref SampleRole
diff --git a/test/unit/rules/resources/test_hardcodedarnproperties.py b/test/unit/rules/resources/test_hardcodedarnproperties.py
--- a/test/unit/rules/resources/test_hardcodedarnproperties.py
+++ b/test/unit/rules/resources/test_hardcodedarnproperties.py
@@ -16,6 +16,9 @@ def setUp(self):
         """Setup"""
         super(TestHardCodedArnProperties, self).setUp()
         self.collection.register(HardCodedArnProperties())
+        self.success_templates = [
+            "test/fixtures/templates/good/resources/properties/hard_coded_arn_properties_sam.yaml",
+        ]
 
     def test_file_positive(self):
         """Test Positive"""