Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(opensearch): improve error message generation logic #32651

Merged
merged 3 commits into from
Dec 24, 2024
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
15 changes: 13 additions & 2 deletions packages/aws-cdk-lib/aws-opensearchservice/lib/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1588,22 +1588,33 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable {
...unSupportEbsInstanceType,
];

const unSupportEncryptionAtRestInstanceType=[
ec2.InstanceClass.M3,
ec2.InstanceClass.R3,
ec2.InstanceClass.T2,
];

const unSupportUltraWarmInstanceType=[
ec2.InstanceClass.T2,
ec2.InstanceClass.T3,
];

// Validate against instance type restrictions, per
// https://docs.aws.amazon.com/opensearch-service/latest/developerguide/supported-instance-types.html
if (isSomeInstanceType(...unSupportEbsInstanceType) && ebsEnabled) {
throw new Error(`${formatInstanceTypesList(unSupportEbsInstanceType, 'and')} instance types do not support EBS storage volumes.`);
}

if (isSomeInstanceType('m3', 'r3', 't2') && encryptionAtRestEnabled) {
throw new Error('M3, R3, and T2 instance types do not support encryption of data at rest.');
throw new Error(`${formatInstanceTypesList(unSupportEncryptionAtRestInstanceType, 'and')} instance types do not support encryption of data at rest.`);
}

if (isInstanceType('t2.micro') && !(isElasticsearchVersion && versionNum <= 2.3)) {
throw new Error('The t2.micro.search instance type supports only Elasticsearch versions 1.5 and 2.3.');
}

if (isSomeInstanceType('t2', 't3') && warmEnabled) {
throw new Error('T2 and T3 instance types do not support UltraWarm storage.');
throw new Error(`${formatInstanceTypesList(unSupportUltraWarmInstanceType, 'and')} instance types do not support UltraWarm storage.`);
}

// Only R3, I3, R6GD, I4G, I4I, IM4GN and R7GD support instance storage, per
Expand Down
54 changes: 18 additions & 36 deletions packages/aws-cdk-lib/aws-opensearchservice/test/domain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1971,7 +1971,7 @@ each(testedOpenSearchVersions).describe('custom error responses', (engineVersion
'i4g.large.search',
'i4i.xlarge.search',
'r7gd.xlarge.search',
])('error when %4 instance types are specified with EBS enabled', (dataNodeInstanceType) => {
])('error when %s instance type is specified with EBS enabled', (dataNodeInstanceType) => {
expect(() => new Domain(stack, 'Domain2', {
version: engineVersion,
capacity: {
Expand All @@ -1984,35 +1984,21 @@ each(testedOpenSearchVersions).describe('custom error responses', (engineVersion
})).toThrow(/I3, R6GD, I4G, I4I, IM4GN and R7GD instance types do not support EBS storage volumes./);
});

test('error when m3, r3, or t2 instance types are specified with encryption at rest enabled', () => {
const error = /M3, R3, and T2 instance types do not support encryption of data at rest/;
test.each([
'm3.2xlarge.search',
'r3.2xlarge.search',
't2.2xlarge.search',
])
('error when %s instance type is specified with encryption at rest enabled', (masterNodeInstanceType) => {
expect(() => new Domain(stack, 'Domain1', {
version: engineVersion,
capacity: {
masterNodeInstanceType: 'm3.2xlarge.search',
},
encryptionAtRest: {
enabled: true,
},
})).toThrow(error);
expect(() => new Domain(stack, 'Domain2', {
version: engineVersion,
capacity: {
dataNodeInstanceType: 'r3.2xlarge.search',
},
encryptionAtRest: {
enabled: true,
},
})).toThrow(error);
expect(() => new Domain(stack, 'Domain3', {
version: engineVersion,
capacity: {
masterNodeInstanceType: 't2.2xlarge.search',
masterNodeInstanceType,
},
encryptionAtRest: {
enabled: true,
},
})).toThrow(error);
})).toThrow(/M3, R3 and T2 instance types do not support encryption of data at rest/);
});

test('error when t2.micro is specified with Elasticsearch version > 2.3', () => {
Expand All @@ -2027,14 +2013,14 @@ each(testedOpenSearchVersions).describe('custom error responses', (engineVersion
test.each([
'm5.large.search',
'r5.large.search',
])('error when any instance type other than R3, I3, R6GD, I4I, I4G, IM4GN or R7GD are specified without EBS enabled', () => {
])('error when any instance type other than R3, I3, R6GD, I4I, I4G, IM4GN or R7GD are specified without EBS enabled', (masterNodeInstanceType) => {
expect(() => new Domain(stack, 'Domain1', {
version: engineVersion,
ebs: {
enabled: false,
},
capacity: {
masterNodeInstanceType: 'm5.large.search',
masterNodeInstanceType,
},
})).toThrow(/EBS volumes are required when using instance types other than R3, I3, R6GD, I4G, I4I, IM4GN or R7GD./);
});
Expand Down Expand Up @@ -2160,22 +2146,18 @@ each(testedOpenSearchVersions).describe('custom error responses', (engineVersion
});
});

test('error when t2 or t3 instance types are specified with UltramWarm enabled', () => {
const error = /T2 and T3 instance types do not support UltraWarm storage/;
test.each([
't2.2xlarge.search',
't3.2xlarge.search',
])
('error when %s instance types is specified with UltramWarm enabled', (masterNodeInstanceType) => {
expect(() => new Domain(stack, 'Domain1', {
version: engineVersion,
capacity: {
masterNodeInstanceType: 't2.2xlarge.search',
masterNodeInstanceType,
warmNodes: 1,
},
})).toThrow(error);
expect(() => new Domain(stack, 'Domain2', {
version: engineVersion,
capacity: {
masterNodeInstanceType: 't3.2xlarge.search',
warmNodes: 1,
},
})).toThrow(error);
})).toThrow(/T2 and T3 instance types do not support UltraWarm storage/);
});

test('error when UltraWarm instance is used and no dedicated master instance specified', () => {
Expand Down
Loading