aws / aws/aws-cdk

cloudtrail: snsTobic is read incorrectly in L2

Open
#21,658 1 comment 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-cloudtrail bug effort/medium p2
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:

![Bildschirmfoto 2022-08-18 um 10 34 55](https://user-images.githubusercontent.com/56847216/185349930-aa59b8f2-8612-40c2-a761-980ece93b41c.png)

### 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:

Bildschirmfoto 2022-08-18 um 10 47 43

### 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:
![Bildschirmfoto 2022-08-18 um 10 43 26](https://user-images.githubusercontent.com/56847216/185351795-3e0e2a0a-67b5-4e20-9f9a-11cc17367a75.png)

### 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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.