cloudtrail: snsTobic is read incorrectly in L2
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
If a snsTopic Arn is specified, only the snsTopicName is drawn in L2. This is not a problem if this topic is in the same account. If this topic is in another account, it cannot find it and throws an error. The whole thing works via CloudFormation.
```
export class CloudTrailStack extends cdk.Stack {
constructor(scope: Construct, id: string, props: CloudTrailStackProps) {
super(scope, id, props);
new cloudtrail.Trail(this, 'TestCloudTrail', {
trailName: 'TestCloudTrail',
isMultiRegionTrail: true,
includeGlobalServiceEvents: true,
enableFileValidation: true,
snsTopic: Topic.fromTopicArn(this, 'TopicArn', 'arn:aws:sns:eu-central-1:031087229678:CloudTrailDelivery'),
bucket: Bucket.fromBucketName(this, 'BucketName', 'dbscloudtrailcentral'),
});
}
}
```
See attached image from cdk.out after synthesizing:

### Expected Behavior
I expect this to be pulled in L2 with "snsTopicArn" rather than "snsTopicName". Gladly with a test it is in the same account, then take the name otherwise the Arn.
### Current Behavior
The following error is currently missing:

### Reproduction Steps
```
import { aws_cloudtrail as cloudtrail } from 'aws-cdk-lib';
import * as cdk from 'aws-cdk-lib';
import { Bucket } from 'aws-cdk-lib/aws-s3';
import { Topic } from 'aws-cdk-lib/aws-sns';
import { Construct } from 'constructs';
export interface CloudTrailStackProps extends cdk.StackProps {
}
export class CloudTrailStack extends cdk.Stack {
constructor(scope: Construct, id: string, props: CloudTrailStackProps) {
super(scope, id, props);
new cloudtrail.Trail(this, 'TestCloudTrail', {
trailName: 'TestCloudTrail',
isMultiRegionTrail: true,
includeGlobalServiceEvents: true,
enableFileValidation: true,
snsTopic: Topic.fromTopicArn(this, 'TopicArn', 'arn:aws:sns:eu-central-1:031087229678:CloudTrailDelivery'),
bucket: Bucket.fromBucketName(this, 'BucketName', 'dbscloudtrailcentral'),
});
}
}
```
### Possible Solution
I'm currently doing the following:
```
const snsTopic = Topic.fromTopicArn(this, 'TopicArn', 'arn:aws:sns:eu-central-1:031087229678:CloudTrailDelivery');
const trail = new cloudtrail.Trail(this, 'TestCloudTrail', {
trailName: 'TestCloudTrail',
isMultiRegionTrail: true,
includeGlobalServiceEvents: true,
enableFileValidation: true,
snsTopic: snsTopic,
bucket: Bucket.fromBucketName(this, 'BucketName', 'dbscloudtrailcentral'),
});
const cfntrail = trail.node.defaultChild as cloudtrail.CfnTrail;
cfntrail.addPropertyOverride('SnsTopicName', snsTopic.topicArn);
```
See attached image from cdk.out after synthesizing:

### Additional Information/Context
_No response_
### CDK CLI Version
2.37.1
### Framework Version
_No response_
### Node.js Version
18.6.0
### OS
12.5
### Language
Typescript
### Language Version
_No response_
### Other information
_No response_
Contributor guide
Research direction
Start with the cloudtrail.Trail L2 and the Topic.fromTopicArn usage in the reproduction, then synthesize the CloudTrailStack and inspect cdk.out. Compare the generated SnsTopicName value with the imported topic ARN; done means a cross-account topic is represented with its ARN while same-account behavior remains valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100