Skip to content

Commit cef8fec

Browse files
authored
fix(rds): read replica instance cannot join domain (#19202)
The read replica instance always uses the same engine as the source instance but some CF validations require the engine to be explicitely passed when some properties are specified. Pass the `engine` property to the CF resource if `domain` is specified. Closes #18786 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 2d6a266 commit cef8fec

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

packages/@aws-cdk/aws-rds/lib/instance.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1171,12 +1171,18 @@ export class DatabaseInstanceReadReplica extends DatabaseInstanceNew implements
11711171
throw new Error(`Cannot set 'backupRetention', as engine '${engineDescription(props.sourceDatabaseInstance.engine)}' does not support automatic backups for read replicas`);
11721172
}
11731173

1174+
// The read replica instance always uses the same engine as the source instance
1175+
// but some CF validations require the engine to be explicitely passed when some
1176+
// properties are specified.
1177+
const shouldPassEngine = props.domain != null;
1178+
11741179
const instance = new CfnDBInstance(this, 'Resource', {
11751180
...this.newCfnProps,
11761181
// this must be ARN, not ID, because of https://github.com/terraform-providers/terraform-provider-aws/issues/528#issuecomment-391169012
11771182
sourceDbInstanceIdentifier: props.sourceDatabaseInstance.instanceArn,
11781183
kmsKeyId: props.storageEncryptionKey?.keyArn,
11791184
storageEncrypted: props.storageEncryptionKey ? true : props.storageEncrypted,
1185+
engine: shouldPassEngine ? props.sourceDatabaseInstance.engine?.engineType : undefined,
11801186
});
11811187

11821188
this.instanceType = props.instanceType;

packages/@aws-cdk/aws-rds/test/instance.test.ts

+25
Original file line numberDiff line numberDiff line change
@@ -1617,6 +1617,31 @@ describe('instance', () => {
16171617
},
16181618
});
16191619
});
1620+
1621+
test('engine is specified for read replica using domain', () => {
1622+
// GIVEN
1623+
const instanceType = ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.SMALL);
1624+
const engine = rds.DatabaseInstanceEngine.postgres({ version: rds.PostgresEngineVersion.VER_13 });
1625+
const source = new rds.DatabaseInstance(stack, 'Source', {
1626+
engine,
1627+
instanceType,
1628+
vpc,
1629+
});
1630+
1631+
// WHEN
1632+
new rds.DatabaseInstanceReadReplica(stack, 'Replica', {
1633+
sourceDatabaseInstance: source,
1634+
instanceType,
1635+
vpc,
1636+
domain: 'my-domain',
1637+
});
1638+
1639+
// THEN
1640+
Template.fromStack(stack).hasResourceProperties('AWS::RDS::DBInstance', {
1641+
SourceDBInstanceIdentifier: Match.anyValue(),
1642+
Engine: 'postgres',
1643+
});
1644+
});
16201645
});
16211646

16221647
test.each([

0 commit comments

Comments
 (0)