Skip to content

Commit 0745193

Browse files
authoredDec 15, 2021
fix(rds): unable to use tokens as port in DatabaseInstance (#17995)
In `DatabaseInstance` the port number can be specified using data type number. If a token value (e.g. CloudFormation Parameter) was used here, the token was not resolved correctly. The conversion of property `port` has been corrected by using method `Tokenization.stringifyNumber()`. Fixes #17948. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 54b6cc6 commit 0745193

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed
 

‎packages/@aws-cdk/aws-rds/lib/instance.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ abstract class DatabaseInstanceNew extends DatabaseInstanceBase implements IData
746746
performanceInsightsRetentionPeriod: enablePerformanceInsights
747747
? (props.performanceInsightRetention || PerformanceInsightRetention.DEFAULT)
748748
: undefined,
749-
port: props.port?.toString(),
749+
port: props.port !== undefined ? Tokenization.stringifyNumber(props.port) : undefined,
750750
preferredBackupWindow: props.preferredBackupWindow,
751751
preferredMaintenanceWindow: props.preferredMaintenanceWindow,
752752
processorFeatures: props.processorFeatures && renderProcessorFeatures(props.processorFeatures),

‎packages/@aws-cdk/aws-rds/test/instance.test.ts

+37
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,43 @@ describe('instance', () => {
16301630
},
16311631
});
16321632
});
1633+
1634+
test('instance with port provided as a number', () => {
1635+
// WHEN
1636+
new rds.DatabaseInstance(stack, 'Database', {
1637+
engine: rds.DatabaseInstanceEngine.MYSQL,
1638+
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL),
1639+
vpc,
1640+
port: 3306,
1641+
});
1642+
1643+
// THEN
1644+
expect(stack).toHaveResourceLike('AWS::RDS::DBInstance', {
1645+
Port: '3306',
1646+
});
1647+
});
1648+
1649+
test('instance with port provided as a CloudFormation parameter', () => {
1650+
// GIVEN
1651+
const port = new cdk.CfnParameter(stack, 'Port', {
1652+
type: 'Number',
1653+
}).valueAsNumber;
1654+
1655+
// WHEN
1656+
new rds.DatabaseInstance(stack, 'Database', {
1657+
engine: rds.DatabaseInstanceEngine.MYSQL,
1658+
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL),
1659+
vpc,
1660+
port,
1661+
});
1662+
1663+
// THEN
1664+
expect(stack).toHaveResourceLike('AWS::RDS::DBInstance', {
1665+
Port: {
1666+
Ref: 'Port',
1667+
},
1668+
});
1669+
});
16331670
});
16341671

16351672
test.each([

0 commit comments

Comments
 (0)
Please sign in to comment.