diff --git a/lib/infra/infra-stack.ts b/lib/infra/infra-stack.ts index b844fe513a7..3f7b4aa67bd 100644 --- a/lib/infra/infra-stack.ts +++ b/lib/infra/infra-stack.ts @@ -507,7 +507,7 @@ export class InfraStack extends Stack { Tags.of(singleNodeInstance).add('role', 'client'); // Disable target security for now, can be provided as an option in the future - InfraStack.addTargets( + InfraStack.addTargetsToListener( opensearchListener, this.elbType, 'single-node-target', @@ -516,7 +516,7 @@ export class InfraStack extends Stack { false); if (this.dashboardsUrl !== 'undefined') { - InfraStack.addTargets( + InfraStack.addTargetsToListener( dashboardsListener!, this.elbType, 'single-node-osd-target', @@ -688,7 +688,7 @@ export class InfraStack extends Stack { } // Disable target security for now, can be provided as an option in the future - InfraStack.addTargets( + InfraStack.addTargetsToListener( opensearchListener, this.elbType, 'opensearchTarget', @@ -697,7 +697,7 @@ export class InfraStack extends Stack { false); if (this.dashboardsUrl !== 'undefined') { - InfraStack.addTargets( + InfraStack.addTargetsToListener( dashboardsListener!, this.elbType, 'dashboardsTarget', @@ -1090,7 +1090,7 @@ export class InfraStack extends Stack { * Adds targets to the given listener. * Works for both Application Load Balancers and Network Load Balancers. */ - private static addTargets(listener: BaseListener, elbType: LoadBalancerType, id: string, port: number, target: AutoScalingGroup | InstanceTarget, + private static addTargetsToListener(listener: BaseListener, elbType: LoadBalancerType, id: string, port: number, target: AutoScalingGroup | InstanceTarget, securityEnabled: boolean) { switch(elbType) { case LoadBalancerType.ALB: { diff --git a/test/infra-stack-props.test.ts b/test/infra-stack-props.test.ts index f8be7563e37..acbd1edcd3b 100644 --- a/test/infra-stack-props.test.ts +++ b/test/infra-stack-props.test.ts @@ -317,3 +317,42 @@ test('Throw error on invalid CPU Arch', () => { expect(error.message).toEqual('distributionUrl parameter is required. Please provide the OpenSearch distribution artifact url to download'); } }); + +test('Throw error on invalid load balancer type', () => { + const app = new App({ + context: { + distVersion: '1.0.0', + securityDisabled: false, + minDistribution: false, + cpuArch: 'x64', + singleNodeCluster: false, + dashboardsUrl: 'www.example.com', + serverAccessType: 'ipv4', + restrictServerAccessTo: 'all', + additionalConfig: '{ "name": "John Doe", "age": 30, "email": "johndoe@example.com" }', + additionalOsdConfig: '{ "something.enabled": "true", "something_else.enabled": "false" }', + loadBalancerType: 'invalid-type', + }, + }); + + try { + // WHEN + const networkStack = new NetworkStack(app, 'opensearch-network-stack', { + env: { account: 'test-account', region: 'us-east-1' }, + }); + + // @ts-ignore + const infraStack = new InfraStack(app, 'opensearch-infra-stack', { + vpc: networkStack.vpc, + securityGroup: networkStack.osSecurityGroup, + env: { account: 'test-account', region: 'us-east-1' }, + }); + + // eslint-disable-next-line no-undef + fail('Expected an error to be thrown'); + } catch (error) { + expect(error).toBeInstanceOf(Error); + // @ts-ignore + expect(error.message).toEqual('Unsupported load balancer type.'); + } +});