Skip to content

Commit

Permalink
feat(rds): add clusterArn property to IServerlessCluster
Browse files Browse the repository at this point in the history
closes aws#10736
  • Loading branch information
asterikx committed Oct 6, 2020
1 parent 0297f31 commit 2736838
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 4 deletions.
19 changes: 18 additions & 1 deletion packages/@aws-cdk/aws-rds/lib/serverless-cluster.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as ec2 from '@aws-cdk/aws-ec2';
import * as kms from '@aws-cdk/aws-kms';
import * as secretsmanager from '@aws-cdk/aws-secretsmanager';
import { Resource, Duration, Token, Annotations, RemovalPolicy, IResource } from '@aws-cdk/core';
import { Resource, Duration, Token, Annotations, RemovalPolicy, IResource, Stack } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { IClusterEngine } from './cluster-engine';
import { DatabaseSecret } from './database-secret';
Expand All @@ -23,6 +23,11 @@ export interface IServerlessCluster extends IResource, ec2.IConnectable, secrets
*/
readonly clusterIdentifier: string;

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

/**
* The endpoint to use for read/write operations
* @attribute EndpointAddress,EndpointPort
Expand Down Expand Up @@ -282,6 +287,18 @@ abstract class ServerlessClusterBase extends Resource implements IServerlessClus
*/
public abstract readonly connections: ec2.Connections;

/**
* The cluster arn.
*/
public get clusterArn(): string {
return Stack.of(this).formatArn({
service: 'rds',
resource: 'cluster',
sep: ':',
resourceName: this.clusterIdentifier,
});
}

/**
* Renders the secret attachment target specifications.
*/
Expand Down
37 changes: 36 additions & 1 deletion packages/@aws-cdk/aws-rds/test/test.serverless-cluster.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ABSENT, expect, haveResource, haveResourceLike, ResourcePart, SynthUtils } from '@aws-cdk/assert';
import { ABSENT, expect, haveOutput, haveResource, haveResourceLike, ResourcePart, SynthUtils } from '@aws-cdk/assert';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as kms from '@aws-cdk/aws-kms';
import * as cdk from '@aws-cdk/core';
Expand Down Expand Up @@ -617,6 +617,41 @@ export = {

test.done();
},

'check that clusterArn property works'(test: Test) {
// GIVEN
const stack = testStack();
const vpc = ec2.Vpc.fromLookup(stack, 'VPC', { isDefault: true });
const cluster = new ServerlessCluster(stack, 'Database', {
engine: DatabaseClusterEngine.AURORA_MYSQL,
vpc,
});
const exportName = 'DbCluterArn';

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

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

test.done();
},
};

function testStack() {
Expand Down
20 changes: 18 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4456,6 +4456,22 @@ caseless@~0.12.0:
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=

cdk8s-plus@^0.29.0:
version "0.29.0"
resolved "https://registry.yarnpkg.com/cdk8s-plus/-/cdk8s-plus-0.29.0.tgz#c30dc2aca0338f473b2572e92268946adc014ad9"
integrity sha512-++8E+uk7cdLiqZgpb/95goNd8pSHBtjWEqe/Fe7JCrUOCfKEBma60PvTHZaSMGRx52bkd1vevyQYiCmcAz4Aww==
dependencies:
minimatch "^3.0.4"

cdk8s@^0.30.0:
version "0.30.0"
resolved "https://registry.yarnpkg.com/cdk8s/-/cdk8s-0.30.0.tgz#71cfbc36c09a03c2410b4530486d38b4e0025c51"
integrity sha512-ZPNq02HXekAbgdTwNVXYpAqPT9tq2S279oRf0ffbiphjmVtL+wrog2es+DAygFZzG8zkoOkJG5dOZtkE9FaSbQ==
dependencies:
follow-redirects "^1.11.0"
json-stable-stringify "^1.0.1"
yaml "^1.7.2"

chalk@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
Expand Down Expand Up @@ -6773,7 +6789,7 @@ follow-redirects@1.5.10:
dependencies:
debug "=3.1.0"

follow-redirects@^1.0.0:
follow-redirects@^1.0.0, follow-redirects@^1.11.0:
version "1.13.0"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.0.tgz#b42e8d93a2a7eea5ed88633676d6597bc8e384db"
integrity sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA==
Expand Down Expand Up @@ -14372,7 +14388,7 @@ yallist@^4.0.0:
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==

yaml@*, yaml@1.10.0, yaml@^1.10.0, yaml@^1.5.0:
yaml@*, yaml@1.10.0, yaml@^1.10.0, yaml@^1.5.0, yaml@^1.7.2:
version "1.10.0"
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.0.tgz#3b593add944876077d4d683fee01081bd9fff31e"
integrity sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg==
Expand Down

0 comments on commit 2736838

Please sign in to comment.