Skip to content

Commit

Permalink
fix(rds): add the dependency on proxy targets to ensure dbInstance (#…
Browse files Browse the repository at this point in the history
…12237)

availability while creating the proxy

Fixes: #11311


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
saudkhanzada authored Jan 4, 2021
1 parent 410507a commit 8f74169
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-rds/lib/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,13 +447,15 @@ export class DatabaseProxy extends DatabaseProxyBase
throw new Error('Cannot specify both dbInstanceIdentifiers and dbClusterIdentifiers');
}

new CfnDBProxyTargetGroup(this, 'ProxyTargetGroup', {
const proxyTargetGroup = new CfnDBProxyTargetGroup(this, 'ProxyTargetGroup', {
targetGroupName: 'default',
dbProxyName: this.dbProxyName,
dbInstanceIdentifiers,
dbClusterIdentifiers,
connectionPoolConfigurationInfo: toConnectionPoolConfigurationInfo(props),
});

bindResult.dbClusters?.forEach((c) => proxyTargetGroup.node.addDependency(c));
}

/**
Expand Down
40 changes: 39 additions & 1 deletion packages/@aws-cdk/aws-rds/test/test.proxy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ABSENT, expect, haveResourceLike } from '@aws-cdk/assert';
import { ABSENT, expect, haveResourceLike, ResourcePart } from '@aws-cdk/assert';
import * as ec2 from '@aws-cdk/aws-ec2';
import { AccountPrincipal, Role } from '@aws-cdk/aws-iam';
import * as secretsmanager from '@aws-cdk/aws-secretsmanager';
Expand Down Expand Up @@ -263,4 +263,42 @@ export = {

test.done();
},

'DBProxyTargetGroup should have dependency on the proxy targets'(test: Test) {
// GIVEN
const cluster = new rds.DatabaseCluster(stack, 'cluster', {
engine: rds.DatabaseClusterEngine.AURORA,
instanceProps: {
vpc,
},
});

//WHEN
new rds.DatabaseProxy(stack, 'proxy', {
proxyTarget: rds.ProxyTarget.fromCluster(cluster),
secrets: [cluster.secret!],
vpc,
});

// THEN
expect(stack).to(haveResourceLike('AWS::RDS::DBProxyTargetGroup', {
Properties: {
DBProxyName: {
Ref: 'proxy3A1DA9C7',
},
TargetGroupName: 'default',
},
DependsOn: [
'clusterInstance183584D40',
'clusterInstance23D1AD8B2',
'cluster611F8AFF',
'clusterSecretAttachment69BFCEC4',
'clusterSecretE349B730',
'clusterSecurityGroupF441DCEA',
'clusterSubnets81E3593F',
],
}, ResourcePart.CompleteDefinition));

test.done();
},
};

0 comments on commit 8f74169

Please sign in to comment.