Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
fix(rds): allowing a no name rds
Browse files Browse the repository at this point in the history
  • Loading branch information
bassrock committed Nov 28, 2023
1 parent 9ff96dc commit 0b95434
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 4 deletions.
21 changes: 21 additions & 0 deletions src/base/ApplicationRDSCluster.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,25 @@ describe('ApplicationRDSCluster', () => {
});
expect(synthed).toMatchSnapshot();
});

it('renders a RDS cluster without a name', () => {
const synthed = Testing.synthScope((stack) => {
new ApplicationRDSCluster(stack, 'testRDSCluster', {
prefix: 'bowling-',
vpcId: 'rug',
subnetIds: ['0', '1'],
useName: false,
rdsConfig: {
masterUsername: 'walter',
masterPassword: 'bowling',
databaseName: 'walter',
engine: 'aurora-mysql',
},
tags: {
whodis: 'walter',
},
});
});
expect(synthed).toMatchSnapshot();
});
});
18 changes: 14 additions & 4 deletions src/base/ApplicationRDSCluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ export interface ApplicationRDSClusterProps extends TerraformMetaArguments {
prefix: string;
vpcId: string;
subnetIds: string[];
useName?: boolean; // When importing resources we need to tell terraform to not try and change the name of the resource.
rdsConfig: ApplicationRDSClusterConfig;
tags?: { [key: string]: string };
}

const defaults = {
useName: true

Check failure on line 40 in src/base/ApplicationRDSCluster.ts

View workflow job for this annotation

GitHub Actions / Lint Code Base

Insert `,`
};

/**
* Generates an RDS cluster
*
Expand All @@ -50,10 +55,13 @@ export class ApplicationRDSCluster extends Construct {
constructor(
scope: Construct,
name: string,
config: ApplicationRDSClusterProps,
config: ApplicationRDSClusterProps

Check failure on line 58 in src/base/ApplicationRDSCluster.ts

View workflow job for this annotation

GitHub Actions / Lint Code Base

Insert `,`
) {
super(scope, name);

// Apply defaults
config = {...defaults, ...config}

Check failure on line 63 in src/base/ApplicationRDSCluster.ts

View workflow job for this annotation

GitHub Actions / Lint Code Base

Replace `...defaults,·...config}` with `·...defaults,·...config·};`

const appVpc = new DataAwsVpc(this, `vpc`, {
filter: [
{
Expand Down Expand Up @@ -104,15 +112,17 @@ export class ApplicationRDSCluster extends Construct {
});

const subnetGroup = new DbSubnetGroup(this, 'rds_subnet_group', {
namePrefix: config.prefix.toLowerCase(),
namePrefix: config.useName ? config.prefix.toLowerCase() : undefined,
subnetIds: config.subnetIds,
provider: config.provider,
tags: config.tags,
});

this.rds = new RdsCluster(this, 'rds_cluster', {
...config.rdsConfig,
clusterIdentifierPrefix: config.prefix.toLowerCase(),
clusterIdentifierPrefix: config.useName
? config.prefix.toLowerCase()
: undefined,
tags: config.tags,
copyTagsToSnapshot: true, //Why would we ever want this to false??
masterPassword:
Expand All @@ -135,7 +145,7 @@ export class ApplicationRDSCluster extends Construct {
config.prefix,
config.tags,
config.rdsConfig.engine,
config.provider,
config.provider

Check failure on line 148 in src/base/ApplicationRDSCluster.ts

View workflow job for this annotation

GitHub Actions / Lint Code Base

Insert `,`
);

this.secretARN = secretARN;
Expand Down
118 changes: 118 additions & 0 deletions src/base/__snapshots__/ApplicationRDSCluster.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,121 @@ exports[`ApplicationRDSCluster renders a RDS cluster with a database URL 1`] = `
}
}"
`;

exports[`ApplicationRDSCluster renders a RDS cluster without a name 1`] = `
"{
"data": {
"aws_vpc": {
"testRDSCluster_vpc_F47EEEFE": {
"filter": [
{
"name": "vpc-id",
"values": [
"rug"
]
}
]
}
}
},
"resource": {
"aws_db_subnet_group": {
"testRDSCluster_rds_subnet_group_88022457": {
"subnet_ids": [
"0",
"1"
],
"tags": {
"whodis": "walter"
}
}
},
"aws_rds_cluster": {
"testRDSCluster_rds_cluster_B5FD08B5": {
"copy_tags_to_snapshot": true,
"database_name": "walter",
"db_subnet_group_name": "\${aws_db_subnet_group.testRDSCluster_rds_subnet_group_88022457.name}",
"engine": "aurora-mysql",
"lifecycle": {
"ignore_changes": [
"master_username",
"master_password"
]
},
"master_password": "bowling",
"master_username": "walter",
"tags": {
"whodis": "walter"
},
"vpc_security_group_ids": [
"\${aws_security_group.testRDSCluster_rds_security_group_4A9D257E.id}"
]
}
},
"aws_secretsmanager_secret": {
"testRDSCluster_rds_secret_A2014138": {
"depends_on": [
"aws_rds_cluster.testRDSCluster_rds_cluster_B5FD08B5"
],
"description": "Secret For \${aws_rds_cluster.testRDSCluster_rds_cluster_B5FD08B5.cluster_identifier}",
"name": "bowling-/\${aws_rds_cluster.testRDSCluster_rds_cluster_B5FD08B5.cluster_identifier}",
"tags": {
"whodis": "walter"
}
}
},
"aws_secretsmanager_secret_version": {
"testRDSCluster_rds_secret_version_55C44893": {
"depends_on": [
"aws_secretsmanager_secret.testRDSCluster_rds_secret_A2014138"
],
"secret_id": "\${aws_secretsmanager_secret.testRDSCluster_rds_secret_A2014138.id}",
"secret_string": "{\\"engine\\":\\"aurora-mysql\\",\\"host\\":\\"\${aws_rds_cluster.testRDSCluster_rds_cluster_B5FD08B5.endpoint}\\",\\"username\\":\\"\${aws_rds_cluster.testRDSCluster_rds_cluster_B5FD08B5.master_username}\\",\\"password\\":\\"\${aws_rds_cluster.testRDSCluster_rds_cluster_B5FD08B5.master_password}\\",\\"dbname\\":\\"\${aws_rds_cluster.testRDSCluster_rds_cluster_B5FD08B5.database_name}\\",\\"port\\":3306,\\"database_url\\":\\"mysql://\${aws_rds_cluster.testRDSCluster_rds_cluster_B5FD08B5.master_username}:\${aws_rds_cluster.testRDSCluster_rds_cluster_B5FD08B5.master_password}@\${aws_rds_cluster.testRDSCluster_rds_cluster_B5FD08B5.endpoint}:3306/\${aws_rds_cluster.testRDSCluster_rds_cluster_B5FD08B5.database_name}\\"}"
}
},
"aws_security_group": {
"testRDSCluster_rds_security_group_4A9D257E": {
"description": "Managed by Terraform",
"egress": [
{
"cidr_blocks": [
"0.0.0.0/0"
],
"description": "required",
"from_port": 0,
"ipv6_cidr_blocks": [
],
"prefix_list_ids": [
],
"protocol": "-1",
"security_groups": [
],
"self": null,
"to_port": 0
}
],
"ingress": [
{
"cidr_blocks": [
"\${data.aws_vpc.testRDSCluster_vpc_F47EEEFE.cidr_block}"
],
"description": null,
"from_port": 3306,
"ipv6_cidr_blocks": null,
"prefix_list_ids": null,
"protocol": "tcp",
"security_groups": null,
"self": null,
"to_port": 3306
}
],
"name_prefix": "bowling-",
"tags": {
"whodis": "walter"
},
"vpc_id": "\${data.aws_vpc.testRDSCluster_vpc_F47EEEFE.id}"
}
}
}
}"
`;

0 comments on commit 0b95434

Please sign in to comment.