Skip to content

Commit

Permalink
fix(rds): read replica instance cannot join domain (#19202)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
jogold committed Mar 1, 2022
1 parent 2d6a266 commit cef8fec
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/@aws-cdk/aws-rds/lib/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1171,12 +1171,18 @@ export class DatabaseInstanceReadReplica extends DatabaseInstanceNew implements
throw new Error(`Cannot set 'backupRetention', as engine '${engineDescription(props.sourceDatabaseInstance.engine)}' does not support automatic backups for read replicas`);
}

// 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.
const shouldPassEngine = props.domain != null;

const instance = new CfnDBInstance(this, 'Resource', {
...this.newCfnProps,
// this must be ARN, not ID, because of https://github.com/terraform-providers/terraform-provider-aws/issues/528#issuecomment-391169012
sourceDbInstanceIdentifier: props.sourceDatabaseInstance.instanceArn,
kmsKeyId: props.storageEncryptionKey?.keyArn,
storageEncrypted: props.storageEncryptionKey ? true : props.storageEncrypted,
engine: shouldPassEngine ? props.sourceDatabaseInstance.engine?.engineType : undefined,
});

this.instanceType = props.instanceType;
Expand Down
25 changes: 25 additions & 0 deletions packages/@aws-cdk/aws-rds/test/instance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,31 @@ describe('instance', () => {
},
});
});

test('engine is specified for read replica using domain', () => {
// GIVEN
const instanceType = ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.SMALL);
const engine = rds.DatabaseInstanceEngine.postgres({ version: rds.PostgresEngineVersion.VER_13 });
const source = new rds.DatabaseInstance(stack, 'Source', {
engine,
instanceType,
vpc,
});

// WHEN
new rds.DatabaseInstanceReadReplica(stack, 'Replica', {
sourceDatabaseInstance: source,
instanceType,
vpc,
domain: 'my-domain',
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::RDS::DBInstance', {
SourceDBInstanceIdentifier: Match.anyValue(),
Engine: 'postgres',
});
});
});

test.each([
Expand Down

0 comments on commit cef8fec

Please sign in to comment.