diff --git a/README.md b/README.md index 03e4615d3df..00a786cbee3 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ In order to deploy both the stacks the user needs to provide a set of required a |------------------------|:------------|:--------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | distVersion | Required | string | The OpenSearch distribution version (released/un-released) the user wants to deploy | | securityDisabled | Required | boolean | Enable or disable security plugin | -| adminPassword | Optional | string | This value is required when security plugin is enabled | +| adminPassword | Optional | string | This value is required when security plugin is enabled and the cluster version is >= 2.12 | | minDistribution | Required | boolean | Is it the minimal OpenSearch distribution with no security and plugins | | distributionUrl | Required | string | OpenSearch tar distribution url | | cpuArch | Required | string | CPU platform for EC2, could be either `x64` or `arm64` | diff --git a/lib/os-cluster-entrypoint.ts b/lib/os-cluster-entrypoint.ts index 074587f8849..fd3cf6bb4ef 100644 --- a/lib/os-cluster-entrypoint.ts +++ b/lib/os-cluster-entrypoint.ts @@ -88,7 +88,11 @@ export class OsClusterEntrypoint { // adminPassword is required if security is enabled and demo config is to be run const adminPassword: String = security ? `${scope.node.tryGetContext('adminPassword')}` : ""; - if (security && (adminPassword === null || adminPassword === "")) { + console.log("bhosdino"); + console.log(Number.parseFloat(distVersion)); + console.log(Number.parseFloat(distVersion) >= 2.12); + + if (!security && Number.parseFloat(distVersion) >= 2.12 && (adminPassword === null || adminPassword === "")) { throw new Error('adminPassword parameter is required to be set when security is enabled'); } diff --git a/test/os-cluster.test.ts b/test/os-cluster.test.ts index 4bdb7cd5d2f..c63b717b403 100644 --- a/test/os-cluster.test.ts +++ b/test/os-cluster.test.ts @@ -530,7 +530,7 @@ test('Throw error on incorrect JSON', () => { } }); -test('Throw error when security is enabled and adminPassword is not defined', () => { +test('Throw error when security is enabled and adminPassword is not defined and dist version is greater than or equal to 2.12', () => { const app = new App({ context: { securityDisabled: false, @@ -539,16 +539,16 @@ test('Throw error when security is enabled and adminPassword is not defined', () cpuArch: 'x64', singleNodeCluster: false, dashboardsUrl: 'www.example.com', - distVersion: '1.0.0', + distVersion: '3.0.0', serverAccessType: 'ipv4', restrictServerAccessTo: 'all', - additionalConfig: '{ "name": "John Doe", "age": 30, "email": "johndoe@example.com" }', - additionalOsdConfig: '{ "something.enabled": "true", "something_else.enabled": "false" }', - // eslint-disable-next-line max-len - customConfigFiles: '{"test/data/config.yml": opensearch/config/opensearch-security/config.yml"}', + managerNodeCount: 0, + dataNodeCount: 3, + dataNodeStorage: 200, + customRoleArn: 'arn:aws:iam::12345678:role/customRoleName', }, }); - // WHEN + try { const testStack = new OsClusterEntrypoint(app, { env: { account: 'test-account', region: 'us-east-1' }, @@ -562,3 +562,33 @@ test('Throw error when security is enabled and adminPassword is not defined', () expect(error.message).toEqual('adminPassword parameter is required to be set when security is enabled'); } }); + +test('Should not throw error when security is enabled and adminPassword is not defined and dist version is less than 2.12', () => { + const app = new App({ + context: { + securityDisabled: false, + minDistribution: false, + distributionUrl: 'www.example.com', + cpuArch: 'x64', + singleNodeCluster: false, + dashboardsUrl: 'www.example.com', + distVersion: '1.0.0', + serverAccessType: 'ipv4', + restrictServerAccessTo: 'all', + managerNodeCount: 0, + dataNodeCount: 3, + dataNodeStorage: 200, + customRoleArn: 'arn:aws:iam::12345678:role/customRoleName', + }, + }); + + // WHEN + const testStack = new OsClusterEntrypoint(app, { + env: { account: 'test-account', region: 'us-east-1' }, + }); + + // THEN + expect(testStack.stacks).toHaveLength(2); + +}); +