Skip to content

Commit

Permalink
fix(rds): Add validation for CfnDBProxyTargetGroup props
Browse files Browse the repository at this point in the history
  • Loading branch information
civilizeddev committed Jul 5, 2020
1 parent e108ca7 commit 84d0a4a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
16 changes: 11 additions & 5 deletions packages/@aws-cdk/aws-rds/lib/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,24 @@ export class DatabaseProxy extends cdk.Resource
this.endpoint = this.resource.attrEndpoint;

let dbInstanceIdentifiers: string[] | undefined;
if (bindResult.dbClusters) {
// support for only instances of a single cluster
dbInstanceIdentifiers = bindResult.dbClusters[0].instanceIdentifiers;
} else if (bindResult.dbInstances) {
if (bindResult.dbInstances) {
// support for only single instance
dbInstanceIdentifiers = [ bindResult.dbInstances[0].instanceIdentifier ];
}

let dbClusterIdentifiers: string[] | undefined;
if (bindResult.dbClusters) {
dbClusterIdentifiers = bindResult.dbClusters.map((c) => c.clusterIdentifier);
}

if (!!dbInstanceIdentifiers && !!dbClusterIdentifiers) {
throw new Error('Cannot specify both dbInstanceIdentifiers and dbClusterIdentifiers');
}

const proxyTargetGroup = new CfnDBProxyTargetGroup(this, 'ProxyTargetGroup', {
dbProxyName: this.dbProxyName,
dbInstanceIdentifiers,
dbClusterIdentifiers: bindResult.dbClusters?.map((c) => c.clusterIdentifier),
dbClusterIdentifiers,
connectionPoolConfigurationInfo: toConnectionPoolConfigurationInfo(props),
});

Expand Down
8 changes: 0 additions & 8 deletions packages/@aws-cdk/aws-rds/test/test.proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,6 @@ export = {
Ref: 'DatabaseB269D8BB',
},
],
DBInstanceIdentifiers: [
{
Ref: 'DatabaseInstance1844F58FD',
},
{
Ref: 'DatabaseInstance2AA380DEE',
},
],
TargetGroupName: 'default',
},
}, ResourcePart.CompleteDefinition));
Expand Down

0 comments on commit 84d0a4a

Please sign in to comment.