The module code moved from https://github.com/worldcoin/infrastructure/tree/main/modules/clusters/orb/nlb
module "nlb" { source = "github.com/worldcoin/terraform-aws-nlb?ref=v0.1.0" cluster_name = var.name application = "traefik/traefik" internal = false acm_arn = var.acm_arn acm_extra_arns = var.acm_extra_arns vpc_id = var.vpc_config.vpc_id public_subnets = var.vpc_config.public_subnets }
When create_default_tls_listener = false, acm_arn can be omitted:
module "nlb" { source = "github.com/worldcoin/terraform-aws-nlb?ref=v1.5.0" cluster_name = var.name application = "gateway-api/gateway" internal = false create_default_tls_listener = false vpc_id = var.vpc_config.vpc_id public_subnets = var.vpc_config.public_subnets }
By default the module creates a security group. security_group_ids adds existing
groups to the NLB's initial attachments. To use only existing groups:
create_security_group = false security_group_ids = [aws_security_group.frontend.id]
At least one existing group is required when creation is disabled. In this mode,
sg_nlb_id and sg_egress_rules are null; ingress_sg_rules and
egress_sg_rules apply only to module-created groups.
The module ignores NLB security-group attachment changes after creation. Before disabling SG creation for an existing NLB, confirm its controller or operator has already moved attachments and other references to the existing groups. The declarative address move preserves managed SG identities for callers keeping the default.
Omitting egress_sg_rules or passing null allows all ports and protocols to
this VPC's associated IPv4 CIDRs. New in-VPC targets and health-check ports work
without caller SG updates. The module reads the VPC identified by vpc_id.
This replaces the previous unrestricted IPv4 default. Check target destinations
before upgrading: IPv6 and cross-VPC destinations require an explicit rule set.
Explicit rules replace the default; [] removes all outbound rules. Do not manage
this SG's egress with separate rule resources; the module owns the complete set.
For restricted egress, allow both target traffic and health checks. For example, when both use TCP port 8080:
egress_sg_rules = [{ description = "Allow target traffic and health checks" protocol = "tcp" from_port = 8080 to_port = 8080 security_groups = [aws_security_group.targets.id] }]
Changing existing rules takes effect at apply; review target and health-check reachability before opting in. This input does not change ingress rules.
Use target_groups and listeners for workloads managed outside the AWS Load Balancer Controller, such as ECS. Their map keys are stable Terraform identities. Disable the legacy listeners, set tags to avoid controller tags, and scope NLB egress to the task security group.
module "ecs_nlb" { source = "[email protected]:worldcoin/terraform-aws-nlb.git?ref=vX.Y.Z" name = "example-ecs" cluster_name = "unused-for-ecs" application = "example/ecs" internal = true vpc_id = module.vpc.vpc_id private_subnets = module.vpc.private_subnets create_default_listeners = false tags = { service = "example" } target_groups = { api = { port = 8080 deregistration_delay = 60 health_check = { protocol = "HTTP" path = "/health" matcher = "200" } } } listeners = { http = { port = 80 target_group_key = "api" } } }
| Name | Version |
|---|---|
| terraform | >= 1.2 |
| aws | >= 5.22.0 |
| Name | Version |
|---|---|
| aws | >= 5.22.0 |
No modules.
| Name | Type |
|---|---|
| aws_lb.nlb | resource |
| aws_lb_listener.extra | resource |
| aws_lb_listener.plain | resource |
| aws_lb_listener.this | resource |
| aws_lb_listener.tls | resource |
| aws_lb_listener_certificate.extra | resource |
| aws_lb_target_group.extra | resource |
| aws_lb_target_group.plain | resource |
| aws_lb_target_group.this | resource |
| aws_lb_target_group.tls | resource |
| aws_security_group.nlb | resource |
| aws_region.current | data source |
| aws_vpc.current | data source |
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| acm_arn | ARN for ACM certificate used for TLS. Required when the default TLS listener is enabled. | string |
null |
no |
| acm_extra_arns | ARNs of ACM certificates used for TLS, attached as additional certificates to the main NLB | list(string) |
[] |
no |
| application | (namespace/app) - Name of application which will be connected to this NLB | string |
n/a | yes |
| cluster_name | Name of the cluster will be used as suffix to all resources | string |
n/a | yes |
| cluster_tag | Value for the elbv2.k8s.aws/cluster tag. Defaults to cluster_name. Use when the tag must differ from the name used to construct the LB name (e.g. Gateway API where the LB name prefix is trimmed but the tag must match the LBC --cluster-name). | string |
"" |
no |
| create_default_listeners | If true, default listeners will be created | bool |
true |
no |
| create_default_plain_listener | If true, default listener (80) will be created (ANDed with create_default_listeners) | bool |
true |
no |
| create_default_tls_listener | If true, tls listener (443) will be created (ANDed with create_default_listeners) | bool |
true |
no |
| create_security_group | Create a security group for the NLB. Existing attachments are managed externally. | bool |
true |
no |
| dns_record_client_routing_policy | DNS client routing policy controlling which AZ's NLB node IP Route 53 returns when a client resolves the NLB hostname. any_availability_zone (default) returns IPs from any AZ. partial_availability_zone_affinity returns the local-AZ IP for ~85% of clients. availability_zone_affinity returns the local-AZ IP for 100% of clients. Combine with enable_cross_zone_load_balancing = false for end-to-end AZ affinity (client → NLB node → target all in same AZ), eliminating cross-AZ data-transfer cost. Caller must ensure each AZ has ≥1 healthy target; otherwise local-AZ clients will see failures rather than fail over. |
string |
"any_availability_zone" |
no |
| egress_sg_rules | Replacement outbound rules for the NLB security group. Omitted or null uses all ports/protocols within the VPC's associated IPv4 CIDRs. Set [] to remove all outbound rules; use explicit rules for IPv6 or cross-VPC destinations. | set(object({ |
null |
no |
| enable_cross_zone_load_balancing | If true, cross-zone load balancing is enabled (NLB routes to targets in any AZ regardless of which AZ the LB node received the traffic on). Disabling can reduce cross-AZ data-transfer charges, but the NLB node in a given AZ will drop traffic when no healthy targets exist in that AZ. Defaults to true to preserve prior behavior. | bool |
true |
no |
| enable_deletion_protection | If true, deletion of the load balancer will be disabled via the AWS API | bool |
true |
no |
| enforce_security_group_inbound_rules_on_private_link_traffic | Whether the NLB security group inbound rules are enforced on traffic arriving through AWS PrivateLink (for example API Gateway VPC Links). Valid values are "on" and "off"; null keeps the AWS default ("on"). | string |
null |
no |
| extra_listeners | List with configuration for additional listeners | list(object({ |
[] |
no |
| health_check_port | Port used for health check for listener | number |
-1 |
no |
| ingress_sg_rules | The security group rules to allow ingress from. | set(object({ |
[ |
no |
| internal | Set NLB to be internal (available only within VPC) | bool |
n/a | yes |
| listeners | Additional named listeners. Each listener forwards to a target_groups key; keys are stable Terraform identities. | map(object({ |
{} |
no |
| name | Name of the NLB, overrides default naming | string |
"" |
no |
| name_suffix | Part of the name used to differentiate NLBs for multiple traefik instances | string |
"" |
no |
| private_subnets | List of private subnets to use | list(string) |
[] |
no |
| public_subnets | List of public subnets to use | list(string) |
[] |
no |
| security_group_ids | Existing security groups to include when creating the NLB. Required when create_security_group is false. | list(string) |
[] |
no |
| tag_prefix | Tag key prefix for LBC resource/stack tags (e.g. service.k8s.aws for Service LB, gateway.k8s.aws.nlb for Gateway API) | string |
"service.k8s.aws" |
no |
| tag_stack | Override the computed stack tag value (default: var.application) | string |
"" |
no |
| tags | Tags for the NLB and its listeners/target groups (default, extra, and Gateway API). If non-empty, these fully replace the module's default tags (elbv2.k8s.aws/cluster, <tag_prefix>/resource, <tag_prefix>/stack) instead of merging with them - use this for an NLB that must not be tracked/managed by an EKS AWS Load Balancer Controller. |
map(string) |
{} |
no |
| target_groups | Additional named target groups for non-controller integrations such as ECS. Keys are stable Terraform identities. | map(object({ |
{} |
no |
| tls_listener_version | Minimum TLS version served by TLS listener | string |
"1.3" |
no |
| vpc_id | VPC ID where the NLB will be deployed | string |
n/a | yes |
| Name | Description |
|---|---|
| arn | The ARN of the NLB. |
| dns_name | The DNS name of the NLB. |
| listener_arns | ARNs of listeners created from listeners, keyed by listener name. |
| ready | Hack! Because modules with providers (cluster-apps) cannot use depends_on output value needs to be used to make sure those are provisioned in correct order. |
| sg_egress_rules | Outbound rules for the module-created security group, or null when creation is disabled. |
| sg_nlb_id | The module-created security group ID, or null when creation is disabled. |
| ssl_policy | SSL Policy attached to loadbalancer |
| target_group_arns | ARNs of target groups created from target_groups, keyed by target group name. |
| zone_id | The zone ID of the NLB. |