Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
};