Skip to content

Commit

Permalink
fix(rds): pass the ARN of master instead of its ID in DatabaseInstanc…
Browse files Browse the repository at this point in the history
…eReadReplica (#5702)

This works around the
"DbSubnetGroupName should not be specified for read replicas that are
created in the same region as the master" RDS validation.

See hashicorp/terraform-provider-aws#528 (comment)
for details.

Fixes #5530

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
skinny85 and mergify[bot] committed Jan 8, 2020
1 parent bf2d635 commit d323c0c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-rds/lib/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,8 @@ export class DatabaseInstanceReadReplica extends DatabaseInstanceNew implements

const instance = new CfnDBInstance(this, 'Resource', {
...this.newCfnProps,
sourceDbInstanceIdentifier: props.sourceDatabaseInstance.instanceIdentifier,
// 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.kmsKey && props.kmsKey.keyArn,
storageEncrypted: props.kmsKey ? true : props.storageEncrypted,
});
Expand Down
18 changes: 15 additions & 3 deletions packages/@aws-cdk/aws-rds/test/test.instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ export = {
test.done();
},

'create a read replica'(test: Test) {
'create a read replica in the same region - with the subnet group name'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'VPC');
Expand All @@ -323,8 +323,20 @@ export = {
// THEN
expect(stack).to(haveResource('AWS::RDS::DBInstance', {
SourceDBInstanceIdentifier: {
Ref: 'InstanceC1063A87'
}
"Fn::Join": ["", [
"arn:",
{ Ref: "AWS::Partition" },
":rds:",
{ Ref: "AWS::Region" },
":",
{ Ref: "AWS::AccountId" },
":db:",
{ Ref: "InstanceC1063A87" },
]],
},
DBSubnetGroupName: {
Ref: 'ReadReplicaSubnetGroup680C605C',
},
}));

test.done();
Expand Down

0 comments on commit d323c0c

Please sign in to comment.