Skip to content

Commit ce84efb

Browse files
enable_cross_zone_load_balancing and preserve_client_ip
1 parent 4c51452 commit ce84efb

File tree

5 files changed

+49
-38
lines changed

5 files changed

+49
-38
lines changed

main.tf

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,13 @@ module "nlb" {
138138

139139
for_each = { for idx, instance in local.instances : instance.name => instance if lookup(instance, "create_nlb", true) }
140140

141-
name_prefix = each.value.name
142-
namespace = each.value.namespace
143-
internal = each.value.internal_nlb
144-
subnet_ids = each.value.internal_nlb ? local.network_private_subnet_ids : local.network_public_subnet_ids
145-
vpc_id = local.network_id
146-
mz_resource_id = module.operator[0].materialize_instance_resource_ids[each.value.name]
141+
name_prefix = each.value.name
142+
namespace = each.value.namespace
143+
internal = each.value.internal_nlb
144+
subnet_ids = each.value.internal_nlb ? local.network_private_subnet_ids : local.network_public_subnet_ids
145+
enable_cross_zone_load_balancing = each.value.enable_cross_zone_load_balancing
146+
vpc_id = local.network_id
147+
mz_resource_id = module.operator[0].materialize_instance_resource_ids[each.value.name]
147148

148149
depends_on = [
149150
module.aws_lbc,
@@ -189,13 +190,14 @@ locals {
189190

190191
instances = [
191192
for instance in var.materialize_instances : {
192-
name = instance.name
193-
namespace = instance.namespace
194-
database_name = instance.database_name
195-
create_database = instance.create_database
196-
environmentd_version = instance.environmentd_version
197-
create_nlb = instance.create_nlb
198-
internal_nlb = instance.internal_nlb
193+
name = instance.name
194+
namespace = instance.namespace
195+
database_name = instance.database_name
196+
create_database = instance.create_database
197+
environmentd_version = instance.environmentd_version
198+
create_nlb = instance.create_nlb
199+
internal_nlb = instance.internal_nlb
200+
enable_cross_zone_load_balancing = instance.enable_cross_zone_load_balancing
199201

200202
metadata_backend_url = format(
201203
"postgres://%s:%s@%s/%s?sslmode=require",

modules/nlb/main.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
resource "aws_lb" "nlb" {
2-
name = var.name_prefix
3-
internal = var.internal
4-
load_balancer_type = "network"
5-
subnets = var.subnet_ids
2+
name = var.name_prefix
3+
internal = var.internal
4+
load_balancer_type = "network"
5+
subnets = var.subnet_ids
6+
enable_cross_zone_load_balancing = var.enable_cross_zone_load_balancing
67
}
78

89
module "target_pgwire" {

modules/nlb/target/main.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
resource "aws_lb_target_group" "target_group" {
2-
name = var.name
3-
port = var.port
4-
protocol = "TCP"
5-
target_type = "ip"
6-
vpc_id = var.vpc_id
2+
name = var.name
3+
port = var.port
4+
preserve_client_ip = true
5+
protocol = "TCP"
6+
target_type = "ip"
7+
vpc_id = var.vpc_id
78

89
health_check {
910
enabled = true

modules/nlb/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ variable "mz_resource_id" {
2828
description = "The resourceId from the Materialize CR"
2929
type = string
3030
}
31+
32+
variable "enable_cross_zone_load_balancing" {
33+
description = "Whether to enable cross zone load balancing on the NLB."
34+
type = bool
35+
default = true
36+
}

variables.tf

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -319,22 +319,23 @@ variable "helm_values" {
319319
variable "materialize_instances" {
320320
description = "Configuration for Materialize instances"
321321
type = list(object({
322-
name = string
323-
namespace = optional(string)
324-
database_name = string
325-
environmentd_version = optional(string, "v0.130.4")
326-
cpu_request = optional(string, "1")
327-
memory_request = optional(string, "1Gi")
328-
memory_limit = optional(string, "1Gi")
329-
create_database = optional(bool, true)
330-
create_nlb = optional(bool, true)
331-
internal_nlb = optional(bool, true)
332-
in_place_rollout = optional(bool, false)
333-
request_rollout = optional(string)
334-
force_rollout = optional(string)
335-
balancer_memory_request = optional(string, "256Mi")
336-
balancer_memory_limit = optional(string, "256Mi")
337-
balancer_cpu_request = optional(string, "100m")
322+
name = string
323+
namespace = optional(string)
324+
database_name = string
325+
environmentd_version = optional(string, "v0.130.4")
326+
cpu_request = optional(string, "1")
327+
memory_request = optional(string, "1Gi")
328+
memory_limit = optional(string, "1Gi")
329+
create_database = optional(bool, true)
330+
create_nlb = optional(bool, true)
331+
internal_nlb = optional(bool, true)
332+
enable_cross_zone_load_balancing = optional(bool, true)
333+
in_place_rollout = optional(bool, false)
334+
request_rollout = optional(string)
335+
force_rollout = optional(string)
336+
balancer_memory_request = optional(string, "256Mi")
337+
balancer_memory_limit = optional(string, "256Mi")
338+
balancer_cpu_request = optional(string, "100m")
338339
}))
339340
default = []
340341

0 commit comments

Comments
 (0)