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): readers not always be created after the writer #30277

Merged
merged 7 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 0 deletions packages/aws-cdk-lib/aws-rds/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,8 @@ abstract class DatabaseClusterNew extends DatabaseClusterBase {
subnetGroup: this.subnetGroup,
});
readers.push(clusterInstance);
// this makes sure the readers would always be created after the writer
clusterInstance.node.addDependency(writer);

if (clusterInstance.tier < 2) {
this.validateReaderInstance(writer, clusterInstance);
Expand Down
36 changes: 36 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 @@ -554,6 +554,42 @@ describe('cluster new api', () => {
PromotionTier: 0,
});
});

test('readers always to be created after the writer', () => {
// GIVEN
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');

// WHEN
new DatabaseCluster(stack, 'Database', {
engine: DatabaseClusterEngine.AURORA,
vpc,
vpcSubnets: vpc.selectSubnets({ subnetType: ec2.SubnetType.PUBLIC }),
writer: ClusterInstance.serverlessV2('writer'),
readers: [
ClusterInstance.serverlessV2('reader1', { instanceIdentifier: 'reader1' }),
ClusterInstance.serverlessV2('reader2', { instanceIdentifier: 'reader2' }),
],
});

// THEN
const template = Template.fromStack(stack);
Array.isArray(template);
// reader1 should depend on the writer
template.hasResource('AWS::RDS::DBInstance', {
Properties: {
DBInstanceIdentifier: 'reader1',
},
DependsOn: Match.arrayWith(['Databasewriter2462CC03']),
});
// reader2 should depend on the writer
template.hasResource('AWS::RDS::DBInstance', {
Properties: {
DBInstanceIdentifier: 'reader2',
},
DependsOn: Match.arrayWith(['Databasewriter2462CC03']),
});
});
});

describe('instanceIdentifiers', () => {
Expand Down
Loading