Skip to content

Commit

Permalink
fix(rds): setting timezone on DatabaseInstance causes internal failure (
Browse files Browse the repository at this point in the history
#6534)

* fix(rds): setting timezone on DatabaseInstance causes internal failure

Per documentation[1], 'Timezone' property is only supported on Microsoft
SQL Server. Setting this property on a DatabaseInstance with a different
database engine causes deployment to fail (1) with a validation error
for a new instance of `AWS::RDS::DBInstance` and (2) internal failure
when modifying an existing instance of `AWS::RDS::DBInstance`.

[1]:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-rds-database-instance.html#cfn-rds-dbinstance-timezone

fixes #6439

* PR feedback
  • Loading branch information
nija-at authored and Elad Ben-Israel committed Mar 9, 2020
1 parent cbda86f commit c6c7e67
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/@aws-cdk/aws-rds/lib/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ export interface DatabaseInstanceSourceProps extends DatabaseInstanceNewProps {
readonly allowMajorVersionUpgrade?: boolean;

/**
* The time zone of the instance.
* The time zone of the instance. This is currently supported only by Microsoft Sql Server.
*
* @default - RDS default timezone
*/
Expand Down Expand Up @@ -678,6 +678,12 @@ abstract class DatabaseInstanceSource extends DatabaseInstanceNew implements IDa
this.singleUserRotationApplication = props.engine.singleUserRotationApplication;
this.multiUserRotationApplication = props.engine.multiUserRotationApplication;

const timezoneSupport = [ DatabaseInstanceEngine.SQL_SERVER_EE, DatabaseInstanceEngine.SQL_SERVER_EX,
DatabaseInstanceEngine.SQL_SERVER_SE, DatabaseInstanceEngine.SQL_SERVER_WEB ];
if (props.timezone && !timezoneSupport.includes(props.engine)) {
throw new Error(`timezone property can be configured only for Microsoft SQL Server, not ${props.engine.name}`);
}

this.sourceCfnProps = {
...this.newCfnProps,
allocatedStorage: props.allocatedStorage ? props.allocatedStorage.toString() : '100',
Expand Down
33 changes: 33 additions & 0 deletions packages/@aws-cdk/aws-rds/test/test.instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,4 +685,37 @@ export = {

test.done();
},

'throws when timezone is set for non-sqlserver database engine'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'vpc');
const tzSupportedEngines = [ rds.DatabaseInstanceEngine.SQL_SERVER_EE, rds.DatabaseInstanceEngine.SQL_SERVER_EX,
rds.DatabaseInstanceEngine.SQL_SERVER_SE, rds.DatabaseInstanceEngine.SQL_SERVER_WEB ];
const tzUnsupportedEngines = [ rds.DatabaseInstanceEngine.MYSQL, rds.DatabaseInstanceEngine.POSTGRES,
rds.DatabaseInstanceEngine.ORACLE_EE, rds.DatabaseInstanceEngine.MARIADB ];

// THEN
tzSupportedEngines.forEach((engine) => {
test.ok(new rds.DatabaseInstance(stack, `${engine.name}-db`, {
engine,
instanceClass: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.SMALL),
masterUsername: 'master',
timezone: 'Europe/Zurich',
vpc,
}));
});

tzUnsupportedEngines.forEach((engine) => {
test.throws(() => new rds.DatabaseInstance(stack, `${engine.name}-db`, {
engine,
instanceClass: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.SMALL),
masterUsername: 'master',
timezone: 'Europe/Zurich',
vpc,
}), /timezone property can be configured only for Microsoft SQL Server/);
});

test.done();
}
};

0 comments on commit c6c7e67

Please sign in to comment.