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

fix(rds): Cluster does not work with imported VPC #7666

Merged
merged 3 commits into from
Apr 30, 2020
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
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-rds/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export class DatabaseCluster extends DatabaseClusterBase {

// Cannot test whether the subnets are in different AZs, but at least we can test the amount.
if (subnetIds.length < 2) {
throw new Error(`Cluster requires at least 2 subnets, got ${subnetIds.length}`);
this.node.addError(`Cluster requires at least 2 subnets, got ${subnetIds.length}`);
}

const subnetGroup = new CfnDBSubnetGroup(this, 'Subnets', {
Expand Down
31 changes: 30 additions & 1 deletion packages/@aws-cdk/aws-rds/test/test.cluster.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, haveResource, ResourcePart } from '@aws-cdk/assert';
import { expect, haveResource, ResourcePart, SynthUtils } from '@aws-cdk/assert';
import * as ec2 from '@aws-cdk/aws-ec2';
import { ManagedPolicy, Role, ServicePrincipal } from '@aws-cdk/aws-iam';
import * as kms from '@aws-cdk/aws-kms';
Expand Down Expand Up @@ -1023,6 +1023,35 @@ export = {

test.done();
},

'does not throw (but adds a node error) if a (dummy) VPC does not have sufficient subnets'(test: Test) {
// GIVEN
const stack = testStack();
const vpc = ec2.Vpc.fromLookup(stack, 'VPC', { isDefault: true });

// WHEN
new DatabaseCluster(stack, 'Database', {
engine: DatabaseClusterEngine.AURORA,
instances: 1,
masterUser: {
username: 'admin',
},
instanceProps: {
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL),
vpc,
vpcSubnets: {
subnetName: 'DefinitelyDoesNotExist',
},
},
});

// THEN
const art = SynthUtils.synthesize(stack);
const meta = art.findMetadataByType('aws:cdk:error');
test.equal(meta[0].data, 'Cluster requires at least 2 subnets, got 0');

test.done();
},
};

function testStack() {
Expand Down