Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(rds): add clusterArn property to DatabaseCluster #29133

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/aws-cdk-lib/aws-rds/lib/cluster-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export interface IDatabaseCluster extends IResource, ec2.IConnectable, secretsma
*/
readonly engine?: IClusterEngine;

/**
* The ARN of the database cluster
*/
readonly clusterArn: string;

/**
* Add a new db proxy to this cluster.
*/
Expand Down
12 changes: 12 additions & 0 deletions packages/aws-cdk-lib/aws-rds/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,18 @@ export abstract class DatabaseClusterBase extends Resource implements IDatabaseC
*/
public abstract readonly connections: ec2.Connections;

/**
* The ARN of the cluster
*/
public get clusterArn(): string {
return Stack.of(this).formatArn({
service: 'rds',
resource: 'cluster',
arnFormat: ArnFormat.COLON_RESOURCE_NAME,
resourceName: this.clusterIdentifier,
});
}

/**
* Add a new db proxy to this cluster.
*/
Expand Down
32 changes: 32 additions & 0 deletions packages/aws-cdk-lib/aws-rds/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4052,6 +4052,38 @@ describe('cluster', () => {
],
});
});

test('clusterArn property', () => {
// GIVEN
const stack = testStack();
const vpc = ec2.Vpc.fromLookup(stack, 'VPC', { isDefault: true });
const cluster = new DatabaseCluster(stack, 'Database', {
engine: DatabaseClusterEngine.auroraPostgres({ version: AuroraPostgresEngineVersion.VER_14_3 }),
instanceProps: { vpc },
});
const exportName = 'DbCluterArn';

// WHEN
new cdk.CfnOutput(stack, exportName, {
exportName,
value: cluster.clusterArn,
});

// THEN
expect(
stack.resolve(cluster.clusterArn),
).toEqual({
'Fn::Join': [
'',
[
'arn:',
{ Ref: 'AWS::Partition' },
':rds:us-test-1:12345:cluster:',
{ Ref: 'DatabaseB269D8BB' },
],
],
});
});
});

test.each([
Expand Down