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): read replica instance cannot join domain #19202

Merged
merged 4 commits into from
Mar 1, 2022
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
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',
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder... since this is a CFN validation, do we need a new small integration test for this, to confirm it deploys?

Copy link
Contributor Author

@jogold jogold Mar 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally yes but it's complicated because it means we need to create a domain using L1 resources from @aws-cdk/aws-directoryservice... and I don't have experience with those resources.

(domain is currently a string but could have been a IDirectory if we had L2 resources for this)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

});

test.each([
Expand Down