Skip to content

Commit

Permalink
Make loadBalancer a readonly property (#117)
Browse files Browse the repository at this point in the history
Signed-off-by: Sayali Gaikawad <gaiksaya@amazon.com>
  • Loading branch information
gaiksaya authored Apr 12, 2024
1 parent 9ce1869 commit c7de4b4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions lib/infra/infra-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ export interface InfraProps extends StackProps {
}

export class InfraStack extends Stack {
public readonly nlb: NetworkLoadBalancer;

private instanceRole: Role;

private distVersion: string;
Expand Down Expand Up @@ -396,7 +398,7 @@ export class InfraStack extends Stack {

const certificateArn = `${props?.certificateArn ?? scope.node.tryGetContext('certificateArn')}`;

const nlb = new NetworkLoadBalancer(this, 'clusterNlb', {
this.nlb = new NetworkLoadBalancer(this, 'clusterNlb', {
vpc: props.vpc,
internetFacing: (!this.isInternal),
crossZoneEnabled: true,
Expand Down Expand Up @@ -427,27 +429,27 @@ export class InfraStack extends Stack {
}

if (!this.securityDisabled && !this.minDistribution && this.opensearchPortMapping === 443 && certificateArn !== 'undefined') {
opensearchListener = nlb.addListener('opensearch', {
opensearchListener = this.nlb.addListener('opensearch', {
port: this.opensearchPortMapping,
protocol: Protocol.TLS,
certificates: [ListenerCertificate.fromArn(certificateArn)],
});
} else {
opensearchListener = nlb.addListener('opensearch', {
opensearchListener = this.nlb.addListener('opensearch', {
port: this.opensearchPortMapping,
protocol: Protocol.TCP,
});
}

if (this.dashboardsUrl !== 'undefined') {
if (!this.securityDisabled && !this.minDistribution && this.opensearchDashboardsPortMapping === 443 && certificateArn !== 'undefined') {
dashboardsListener = nlb.addListener('dashboards', {
dashboardsListener = this.nlb.addListener('dashboards', {
port: this.opensearchDashboardsPortMapping,
protocol: Protocol.TLS,
certificates: [ListenerCertificate.fromArn(certificateArn)],
});
} else {
dashboardsListener = nlb.addListener('dashboards', {
dashboardsListener = this.nlb.addListener('dashboards', {
port: this.opensearchDashboardsPortMapping,
protocol: Protocol.TCP,
});
Expand Down Expand Up @@ -678,7 +680,7 @@ export class InfraStack extends Stack {
}
}
new CfnOutput(this, 'loadbalancer-url', {
value: nlb.loadBalancerDnsName,
value: this.nlb.loadBalancerDnsName,
});

if (this.enableMonitoring) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opensearch-project/opensearch-cluster-cdk",
"version": "1.2.2",
"version": "1.2.3",
"bin": {
"cdk_v2": "bin/app.js"
},
Expand Down

0 comments on commit c7de4b4

Please sign in to comment.