Skip to content

Commit

Permalink
handled default values
Browse files Browse the repository at this point in the history
  • Loading branch information
lpizzinidev committed Jul 22, 2023
1 parent 3b24e02 commit c667e52
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@
"LogPublishingOptions": {},
"NodeToNodeEncryptionOptions": {
"Enabled": true
},
"OffPeakWindowOptions": {
"Enabled": true,
"OffPeakWindow": {
"WindowStartTime": {
"Hours": 0,
"Minutes": 0
}
}
}
},
"UpdateReplacePolicy": "Delete",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@
"LogPublishingOptions": {},
"NodeToNodeEncryptionOptions": {
"Enabled": true
},
"OffPeakWindowOptions": {
"Enabled": true,
"OffPeakWindow": {
"WindowStartTime": {
"Hours": 0,
"Minutes": 0
}
}
}
},
"UpdateReplacePolicy": "Delete",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@
"LogPublishingOptions": {},
"NodeToNodeEncryptionOptions": {
"Enabled": false
},
"OffPeakWindowOptions": {
"Enabled": true,
"OffPeakWindow": {
"WindowStartTime": {
"Hours": 0,
"Minutes": 0
}
}
}
},
"UpdateReplacePolicy": "Delete",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@
"LogPublishingOptions": {},
"NodeToNodeEncryptionOptions": {
"Enabled": false
},
"OffPeakWindowOptions": {
"Enabled": true,
"OffPeakWindow": {
"WindowStartTime": {
"Hours": 0,
"Minutes": 0
}
}
}
},
"UpdateReplacePolicy": "Delete",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
"LogPublishingOptions": {},
"NodeToNodeEncryptionOptions": {
"Enabled": false
},
"OffPeakWindowOptions": {
"Enabled": true,
"OffPeakWindow": {
"WindowStartTime": {
"Hours": 0,
"Minutes": 0
}
}
}
},
"UpdateReplacePolicy": "Delete",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
"LogPublishingOptions": {},
"NodeToNodeEncryptionOptions": {
"Enabled": false
},
"OffPeakWindowOptions": {
"Enabled": true,
"OffPeakWindow": {
"WindowStartTime": {
"Hours": 0,
"Minutes": 0
}
}
}
},
"UpdateReplacePolicy": "Delete",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
"LogPublishingOptions": {},
"NodeToNodeEncryptionOptions": {
"Enabled": false
},
"OffPeakWindowOptions": {
"Enabled": true,
"OffPeakWindow": {
"WindowStartTime": {
"Hours": 0,
"Minutes": 0
}
}
}
},
"UpdateReplacePolicy": "Delete",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@
"LogPublishingOptions": {},
"NodeToNodeEncryptionOptions": {
"Enabled": true
},
"OffPeakWindowOptions": {
"Enabled": true,
"OffPeakWindow": {
"WindowStartTime": {
"Hours": 0,
"Minutes": 0
}
}
}
},
"UpdateReplacePolicy": "Delete",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,15 @@
"Ref": "VpcPrivateSubnet2Subnet3788AAA1"
}
]
},
"OffPeakWindowOptions": {
"Enabled": true,
"OffPeakWindow": {
"WindowStartTime": {
"Hours": 0,
"Minutes": 0
}
}
}
},
"DependsOn": [
Expand Down
41 changes: 34 additions & 7 deletions packages/aws-cdk-lib/aws-opensearchservice/lib/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,14 @@ export interface WindowStartTime {
/**
* The start hour of the window in Coordinated Universal Time (UTC), using 24-hour time.
* For example, 17 refers to 5:00 P.M. UTC.
*
* @default - 0
*/
readonly hours: number;
/**
* The start minute of the window, in UTC.
*
* @default - 0
*/
readonly minutes: number;
}
Expand All @@ -345,21 +349,28 @@ export interface OffPeakWindow {
* A custom start time for the off-peak window, in Coordinated Universal Time (UTC).
* The window length will always be 10 hours, so you can't specify an end time.
* For example, if you specify 11:00 P.M. UTC as a start time, the end time will automatically be set to 9:00 A.M.
*
* @default - 00:00 UTC
*/
readonly windowStartTime?: WindowStartTime;
}

/**
* Off-peak window settings for the domain.
* You can't disable the off-peak window for a domain after it's enabled.
*/
export interface OffPeakWindowOptions {
/**
* Specifies whether off-peak window settings are enabled for the domain.
*
* @default - true
*/
readonly enabled?: boolean;

/**
* Off-peak window settings for the domain.
*
* @default - default window start time is 00:00 UTC
*/
readonly offPeakWindow?: OffPeakWindow;
}
Expand All @@ -370,6 +381,8 @@ export interface OffPeakWindowOptions {
export interface SoftwareUpdateOptions {
/**
* Specifies whether automatic service software updates are enabled for the domain.
*
* @default - automatic software updates are disabled
*/
readonly autoSoftwareUpdateEnabled?: boolean;
}
Expand Down Expand Up @@ -561,11 +574,15 @@ export interface DomainProps {
/**
* Options for a domain's off-peak window, during which OpenSearch Service can perform mandatory
* configuration changes on the domain.
*
* @default - off-peak window is enabled by default with 00:00 UTC start time.
*/
readonly offPeakWindowOptions?: OffPeakWindowOptions;

/**
* Options for configuring service software updates for a domain.
*
* @default - no software updates configured for the domain
*/
readonly softwareUpdateOptions?: SoftwareUpdateOptions;
}
Expand Down Expand Up @@ -1615,7 +1632,22 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable {
}
}

this.validateWindowStartTime(props.offPeakWindowOptions?.offPeakWindow?.windowStartTime);
let offPeakWindowOptions: OffPeakWindowOptions = {
enabled: props.offPeakWindowOptions?.enabled ?? true,
};
if (offPeakWindowOptions.enabled) {
offPeakWindowOptions = {
...offPeakWindowOptions,
offPeakWindow: {
windowStartTime: {
hours: props.offPeakWindowOptions?.offPeakWindow?.windowStartTime?.hours ?? 0,
minutes: props.offPeakWindowOptions?.offPeakWindow?.windowStartTime?.minutes ?? 0,
},
},
};
}

this.validateWindowStartTime(offPeakWindowOptions?.offPeakWindow?.windowStartTime);

// Create the domain
this.domain = new CfnDomain(this, 'Resource', {
Expand Down Expand Up @@ -1691,12 +1723,7 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable {
}
: undefined,
advancedOptions: props.advancedOptions,
offPeakWindowOptions: props.offPeakWindowOptions ? {
enabled: props.offPeakWindowOptions.enabled,
offPeakWindow: props.offPeakWindowOptions.offPeakWindow && props.offPeakWindowOptions.offPeakWindow.windowStartTime ? {
windowStartTime: props.offPeakWindowOptions.offPeakWindow.windowStartTime,
} : undefined,
} : undefined,
offPeakWindowOptions: offPeakWindowOptions,
softwareUpdateOptions: props.softwareUpdateOptions,
});
this.domain.applyRemovalPolicy(props.removalPolicy);
Expand Down
35 changes: 34 additions & 1 deletion packages/aws-cdk-lib/aws-opensearchservice/test/domain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1981,7 +1981,7 @@ each(testedOpenSearchVersions).describe('cognito dashboards auth', (engineVersio
});

each(testedOpenSearchVersions).describe('offPeakWindowOptions and softwareUpdateOptions properties', (engineVersion) => {
test('with offPeakWindowOptions', () => {
test('with offPeakWindowOptions enabled', () => {
new Domain(stack, 'Domain', {
version: engineVersion,
offPeakWindowOptions: {
Expand All @@ -2008,6 +2008,39 @@ each(testedOpenSearchVersions).describe('offPeakWindowOptions and softwareUpdate
});
});

test('with offPeakWindowOptions disabled', () => {
new Domain(stack, 'Domain', {
version: engineVersion,
offPeakWindowOptions: {
enabled: false,
},
});

Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', {
OffPeakWindowOptions: {
Enabled: false,
},
});
});

test('offPeakWindowOptions default value', () => {
new Domain(stack, 'Domain', {
version: engineVersion,
});

Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', {
OffPeakWindowOptions: {
Enabled: true,
OffPeakWindow: {
WindowStartTime: {
Hours: 0,
Minutes: 0,
},
},
},
});
});

test('with softwareUpdateOptions', () => {
new Domain(stack, 'Domain', {
version: engineVersion,
Expand Down

0 comments on commit c667e52

Please sign in to comment.