Skip to content

Commit

Permalink
chore(rds): add clusterArn property to DatabaseCluster (#29133)
Browse files Browse the repository at this point in the history
### Issue # (if applicable)

### Reason for this change

This is to bring parity with #10741, we need the cluster arn to enable data api manually waiting for #28574.

### Description of changes

This adds a clusterArn property to IDatabaseCluster

### Description of how you validated changes

The changes have been validated through a unit test

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
BenFradet authored Feb 29, 2024
1 parent 6fe97ea commit 2f720a1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
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

0 comments on commit 2f720a1

Please sign in to comment.