diff --git a/packages/aws-cdk-lib/aws-opensearchservice/lib/domain.ts b/packages/aws-cdk-lib/aws-opensearchservice/lib/domain.ts index f3603307afbb5..fe00ce2a39f6e 100644 --- a/packages/aws-cdk-lib/aws-opensearchservice/lib/domain.ts +++ b/packages/aws-cdk-lib/aws-opensearchservice/lib/domain.ts @@ -1588,6 +1588,17 @@ 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) { @@ -1595,7 +1606,7 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable { } 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)) { @@ -1603,7 +1614,7 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable { } 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 diff --git a/packages/aws-cdk-lib/aws-opensearchservice/test/domain.test.ts b/packages/aws-cdk-lib/aws-opensearchservice/test/domain.test.ts index df0866c32a410..78b6be1583eee 100644 --- a/packages/aws-cdk-lib/aws-opensearchservice/test/domain.test.ts +++ b/packages/aws-cdk-lib/aws-opensearchservice/test/domain.test.ts @@ -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: { @@ -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', () => { @@ -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./); }); @@ -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', () => {