From d323c0c13aaf475f59615a41969bb60cbb678be8 Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Tue, 7 Jan 2020 19:50:48 -0800 Subject: [PATCH] fix(rds): pass the ARN of master instead of its ID in DatabaseInstanceReadReplica (#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 https://github.com/terraform-providers/terraform-provider-aws/issues/528#issuecomment-391169012 for details. Fixes #5530 Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- packages/@aws-cdk/aws-rds/lib/instance.ts | 3 ++- .../@aws-cdk/aws-rds/test/test.instance.ts | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/@aws-cdk/aws-rds/lib/instance.ts b/packages/@aws-cdk/aws-rds/lib/instance.ts index 32e8f6e0ba4e4..d26c14b8f8e22 100644 --- a/packages/@aws-cdk/aws-rds/lib/instance.ts +++ b/packages/@aws-cdk/aws-rds/lib/instance.ts @@ -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, }); diff --git a/packages/@aws-cdk/aws-rds/test/test.instance.ts b/packages/@aws-cdk/aws-rds/test/test.instance.ts index 30b519d4432f7..35876e9afa3e0 100644 --- a/packages/@aws-cdk/aws-rds/test/test.instance.ts +++ b/packages/@aws-cdk/aws-rds/test/test.instance.ts @@ -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'); @@ -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();