infra: PPv2 attributes, NLB sources output, trust alarms
Ingress module (edge PPv2 spec §8.1): per-port preserve_client_ip and proxy_protocol_v2 maps, defaulting to today's S0 so a re-pin plans no target group change; a validation refuses S3 (both off) on any port. A new proxy_trust_alarm input creates the proxy-trust and port-allocation alarms, and a target group precondition refuses PPv2 while it is unset. Output proxy_protocol_sources lists the NLB node private addresses, sorted, from one network interface lookup per zone. group.tf (§8.2): existing target groups pass in S0, S1 and S2; S3 is refused.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 files changed,
+388
−3
infra/modules/region-host/group.tf+2 −2infra/modules/region-host/ingress/alarms.tf+50 −0infra/modules/region-host/ingress/main.tf+24 −1infra/modules/region-host/ingress/outputs.tf+4 −0infra/modules/region-host/ingress/tests/group_ingress.tftest.hcl+206 −0infra/modules/region-host/ingress/variables.tf+52 −0infra/modules/region-host/tests/group.tftest.hcl+50 −0
Intent
diff --git a/infra/modules/region-host/group.tf b/infra/modules/region-host/group.tf| index 71684a9a0..eee8879d5 100644 |
| --- a/infra/modules/region-host/group.tf |
| +++ b/infra/modules/region-host/group.tf |
| @@ -182,9 +182,9 @@ resource "aws_security_group" "group" { |
| } |
| precondition { |
| condition = var.group_ingress == null ? true : alltrue([for port, tg in { "80" = data.aws_lb_target_group.group_http[0], "443" = data.aws_lb_target_group.group_https[0] } : |
| - tg.vpc_id == var.vpc_id && tg.port == tonumber(port) && tg.protocol == "TCP" && tg.target_type == "instance" && tg.preserve_client_ip == "true" && tg.load_balancer_arns == toset([var.group_ingress.nlb_arn]) |
| + tg.vpc_id == var.vpc_id && tg.port == tonumber(port) && tg.protocol == "TCP" && tg.target_type == "instance" && (tg.preserve_client_ip == "true" || tg.proxy_protocol_v2) && tg.load_balancer_arns == toset([var.group_ingress.nlb_arn]) |
| ]) |
| - error_message = "existing target groups must preserve client IPs and serve TCP 80 and 443 in the group VPC through the selected NLB" |
| + error_message = "existing target groups must preserve client IPs or send PROXY protocol v2, and serve TCP 80 and 443 in the group VPC through the selected NLB" |
| } |
| } |
| } |
diff --git a/infra/modules/region-host/ingress/alarms.tf b/infra/modules/region-host/ingress/alarms.tf| index 38e6429c2..c33103dc2 100644 |
| --- a/infra/modules/region-host/ingress/alarms.tf |
| +++ b/infra/modules/region-host/ingress/alarms.tf |
| @@ -87,3 +87,53 @@ resource "aws_cloudwatch_metric_alarm" "admitted" { |
| Region = var.regional_metrics.region |
| } |
| } |
| + |
| +locals { |
| + proxy_trust_actions = var.proxy_trust_alarm == null ? [] : [var.proxy_trust_alarm.topic_arn] |
| +} |
| + |
| +# Edge PPv2 spec §4.5 and §8.1: any trust violation on an armed box means a |
| +# target group may have PROXY protocol v2 off with preservation off (S3). |
| +# Unarmed boxes publish nothing, so missing data is not breaching. |
| +resource "aws_cloudwatch_metric_alarm" "proxy_trust" { |
| + count = var.proxy_trust_alarm == null ? 0 : 1 |
| + alarm_name = "${var.name}-proxy-trust" |
| + alarm_description = "A box refused a request with no client address, or trusted a forged PROXY header, in the last minute. A target group may have PROXY protocol v2 off with client IP preservation off. Run the S3 incident procedure now." |
| + namespace = "Carlos/Host" |
| + metric_name = "IngressProxyTrustViolations" |
| + statistic = "Maximum" |
| + period = 60 |
| + evaluation_periods = 1 |
| + datapoints_to_alarm = 1 |
| + threshold = 0 |
| + comparison_operator = "GreaterThanThreshold" |
| + treat_missing_data = "notBreaching" |
| + alarm_actions = local.proxy_trust_actions |
| + ok_actions = local.proxy_trust_actions |
| + dimensions = { |
| + Deployment = var.proxy_trust_alarm.deployment |
| + Region = var.proxy_trust_alarm.region |
| + } |
| +} |
| + |
| +# With client IP preservation off the NLB allocates its own source ports; |
| +# running out drops new connections. |
| +resource "aws_cloudwatch_metric_alarm" "port_allocation" { |
| + count = var.proxy_trust_alarm == null ? 0 : 1 |
| + alarm_name = "${var.name}-port-allocation" |
| + alarm_description = "The load balancer could not allocate a source port for a new connection in the last five minutes, so that connection failed. Check connection volume to each target." |
| + namespace = "AWS/NetworkELB" |
| + metric_name = "PortAllocationErrorCount" |
| + statistic = "Sum" |
| + period = 300 |
| + evaluation_periods = 1 |
| + datapoints_to_alarm = 1 |
| + threshold = 0 |
| + comparison_operator = "GreaterThanThreshold" |
| + treat_missing_data = "notBreaching" |
| + alarm_actions = local.proxy_trust_actions |
| + ok_actions = local.proxy_trust_actions |
| + dimensions = { |
| + LoadBalancer = aws_lb.nlb.arn_suffix |
| + } |
| +} |
diff --git a/infra/modules/region-host/ingress/main.tf b/infra/modules/region-host/ingress/main.tf| index a31951c27..5594010a0 100644 |
| --- a/infra/modules/region-host/ingress/main.tf |
| +++ b/infra/modules/region-host/ingress/main.tf |
| @@ -101,7 +101,8 @@ resource "aws_lb_target_group" "target" { |
| protocol = "TCP" |
| target_type = "instance" |
| vpc_id = var.vpc_id |
| - preserve_client_ip = true |
| + preserve_client_ip = var.preserve_client_ip[each.key] |
| + proxy_protocol_v2 = var.proxy_protocol_v2[each.key] |
| deregistration_delay = 30 |
| health_check { |
| enabled = true |
| @@ -123,6 +124,14 @@ resource "aws_lb_target_group" "target" { |
| enable_unhealthy_connection_termination = false |
| unhealthy_draining_interval = 180 |
| } |
| + # Edge PPv2 spec §8.1: the trust alarm watches for PPv2 turned off behind |
| + # an armed edge, so no target group gets PPv2 without it. |
| + lifecycle { |
| + precondition { |
| + condition = !var.proxy_protocol_v2[each.key] || var.proxy_trust_alarm != null |
| + error_message = "set proxy_trust_alarm before a target group sends PROXY protocol v2" |
| + } |
| + } |
| } |
| resource "aws_lb_listener" "tcp" { |
| @@ -135,3 +144,17 @@ resource "aws_lb_listener" "tcp" { |
| target_group_arn = each.value.arn |
| } |
| } |
| + |
| +# The NLB's node addresses, one interface per enabled zone. The edge trusts a |
| +# PROXY protocol header only from these peers (CARLOS_INGRESS_PROXY_SOURCES). |
| +data "aws_network_interface" "node" { |
| + for_each = var.zones |
| + filter { |
| + name = "description" |
| + values = ["ELB ${aws_lb.nlb.arn_suffix}"] |
| + } |
| + filter { |
| + name = "subnet-id" |
| + values = [each.value.subnet_id] |
| + } |
| +} |
diff --git a/infra/modules/region-host/ingress/outputs.tf b/infra/modules/region-host/ingress/outputs.tf| index 75a78a521..d10436a0b 100644 |
| --- a/infra/modules/region-host/ingress/outputs.tf |
| +++ b/infra/modules/region-host/ingress/outputs.tf |
| @@ -17,3 +17,7 @@ output "nlb_arn_suffix" { |
| output "target_group_arn_suffixes" { |
| value = { for port, group in aws_lb_target_group.target : port => group.arn_suffix } |
| } |
| +output "proxy_protocol_sources" { |
| + description = "Private IPv4 addresses of the load balancer nodes, one per availability zone, sorted. These are the values for CARLOS_INGRESS_PROXY_SOURCES." |
| + value = sort([for node in data.aws_network_interface.node : node.private_ip]) |
| +} |
diff --git a/infra/modules/region-host/ingress/tests/group_ingress.tftest.hcl b/infra/modules/region-host/ingress/tests/group_ingress.tftest.hcl| index 2bb599401..1ca5b6565 100644 |
| --- a/infra/modules/region-host/ingress/tests/group_ingress.tftest.hcl |
| +++ b/infra/modules/region-host/ingress/tests/group_ingress.tftest.hcl |
| @@ -298,3 +298,209 @@ run "group_alarm_missing_producer_identity" { |
| variables { regional_metrics = { deployment = "", region = "ie" } } |
| expect_failures = [var.regional_metrics] |
| } |
| + |
| +# Edge PROXY protocol v2 (edge PPv2 spec §8.1). Each target group's client |
| +# IP preservation and PPv2 come from per-port maps. The defaults are today's |
| +# S0, so a root re-pinned to this version plans no target group change. |
| +run "defaults_keep_today" { |
| + command = plan |
| + assert { |
| + condition = alltrue([for key, tg in aws_lb_target_group.target : |
| + tg.preserve_client_ip == "true" && tg.proxy_protocol_v2 == false |
| + ]) && toset(keys(aws_lb_target_group.target)) == toset(["80", "443"]) |
| + error_message = "by default both target groups must preserve client IPs with PROXY protocol v2 off" |
| + } |
| + assert { |
| + condition = length(aws_cloudwatch_metric_alarm.proxy_trust) == 0 && length(aws_cloudwatch_metric_alarm.port_allocation) == 0 |
| + error_message = "the trust and port allocation alarms must be opt-in" |
| + } |
| +} |
| + |
| +# S1 on port 80 only: one target group flips at a time, and PPv2 needs the |
| +# trust alarm input. |
| +run "ppv2_on_80_with_alarm" { |
| + command = plan |
| + variables { |
| + proxy_protocol_v2 = { "80" = true, "443" = false } |
| + proxy_trust_alarm = { deployment = "shop-deployment", region = "ie", topic_arn = "arn:aws:sns:eu-west-1:123456789012:shop-alerts" } |
| + } |
| + assert { |
| + condition = ( |
| + aws_lb_target_group.target["80"].preserve_client_ip == "true" && aws_lb_target_group.target["80"].proxy_protocol_v2 == true && |
| + aws_lb_target_group.target["443"].preserve_client_ip == "true" && aws_lb_target_group.target["443"].proxy_protocol_v2 == false |
| + ) |
| + error_message = "PROXY protocol v2 must change only the target group it names" |
| + } |
| +} |
| + |
| +# S2 on port 80: preservation off with PPv2 on is allowed. |
| +run "ppv2_only_on_80_with_alarm" { |
| + command = plan |
| + variables { |
| + preserve_client_ip = { "80" = false, "443" = true } |
| + proxy_protocol_v2 = { "80" = true, "443" = false } |
| + proxy_trust_alarm = { deployment = "shop-deployment", region = "ie", topic_arn = "arn:aws:sns:eu-west-1:123456789012:shop-alerts" } |
| + } |
| + assert { |
| + condition = ( |
| + aws_lb_target_group.target["80"].preserve_client_ip == "false" && aws_lb_target_group.target["80"].proxy_protocol_v2 == true && |
| + aws_lb_target_group.target["443"].preserve_client_ip == "true" && aws_lb_target_group.target["443"].proxy_protocol_v2 == false |
| + ) |
| + error_message = "preservation off with PROXY protocol v2 on must plan for the named target group" |
| + } |
| +} |
| + |
| +run "ppv2_without_alarm_refused" { |
| + command = plan |
| + variables { |
| + proxy_protocol_v2 = { "80" = true, "443" = false } |
| + } |
| + expect_failures = [aws_lb_target_group.target] |
| +} |
| + |
| +# S3 (preservation off, PPv2 off) lets any client choose its address. It is |
| +# never a declared state. |
| +run "s3_refused" { |
| + command = plan |
| + variables { |
| + preserve_client_ip = { "80" = false, "443" = true } |
| + proxy_protocol_v2 = { "80" = false, "443" = false } |
| + } |
| + expect_failures = [var.proxy_protocol_v2] |
| +} |
| + |
| +run "s3_refused_on_443" { |
| + command = plan |
| + variables { |
| + preserve_client_ip = { "80" = true, "443" = false } |
| + proxy_protocol_v2 = { "80" = true, "443" = false } |
| + proxy_trust_alarm = { deployment = "shop-deployment", region = "ie", topic_arn = "arn:aws:sns:eu-west-1:123456789012:shop-alerts" } |
| + } |
| + expect_failures = [var.proxy_protocol_v2] |
| +} |
| + |
| +run "preserve_port_keys_refused" { |
| + command = plan |
| + variables { |
| + preserve_client_ip = { "80" = true, "443" = true, "8080" = true } |
| + } |
| + expect_failures = [var.preserve_client_ip] |
| +} |
| + |
| +run "proxy_port_keys_refused" { |
| + command = plan |
| + variables { |
| + proxy_protocol_v2 = { "80" = false } |
| + } |
| + expect_failures = [var.proxy_protocol_v2] |
| +} |
| + |
| +run "port_value_null_refused" { |
| + command = plan |
| + variables { |
| + preserve_client_ip = { "80" = null, "443" = true } |
| + } |
| + expect_failures = [var.preserve_client_ip] |
| +} |
| + |
| +run "proxy_trust_alarm_wrong_region_refused" { |
| + command = plan |
| + variables { |
| + proxy_trust_alarm = { deployment = "shop-deployment", region = "ie", topic_arn = "arn:aws:sns:us-east-1:123456789012:shop-alerts" } |
| + } |
| + expect_failures = [var.proxy_trust_alarm] |
| +} |
| + |
| +run "proxy_trust_alarm_missing_identity_refused" { |
| + command = plan |
| + variables { |
| + proxy_trust_alarm = { deployment = "", region = "ie", topic_arn = "arn:aws:sns:eu-west-1:123456789012:shop-alerts" } |
| + } |
| + expect_failures = [var.proxy_trust_alarm] |
| +} |
| + |
| +run "alarms_shape" { |
| + command = plan |
| + variables { |
| + proxy_trust_alarm = { deployment = "shop-deployment", region = "ie", topic_arn = "arn:aws:sns:eu-west-1:123456789012:shop-trust" } |
| + alarm_topic_arn = "arn:aws:sns:eu-west-1:123456789012:shop-alerts" |
| + } |
| + assert { |
| + condition = ( |
| + length(aws_cloudwatch_metric_alarm.proxy_trust) == 1 && |
| + aws_cloudwatch_metric_alarm.proxy_trust[0].alarm_name == "shop-probe-proxy-trust" && |
| + aws_cloudwatch_metric_alarm.proxy_trust[0].namespace == "Carlos/Host" && |
| + aws_cloudwatch_metric_alarm.proxy_trust[0].metric_name == "IngressProxyTrustViolations" && |
| + aws_cloudwatch_metric_alarm.proxy_trust[0].statistic == "Maximum" && |
| + aws_cloudwatch_metric_alarm.proxy_trust[0].period == 60 && |
| + aws_cloudwatch_metric_alarm.proxy_trust[0].evaluation_periods == 1 && |
| + aws_cloudwatch_metric_alarm.proxy_trust[0].datapoints_to_alarm == 1 && |
| + aws_cloudwatch_metric_alarm.proxy_trust[0].threshold == 0 && |
| + aws_cloudwatch_metric_alarm.proxy_trust[0].comparison_operator == "GreaterThanThreshold" && |
| + aws_cloudwatch_metric_alarm.proxy_trust[0].treat_missing_data == "notBreaching" && |
| + aws_cloudwatch_metric_alarm.proxy_trust[0].dimensions == tomap({ Deployment = "shop-deployment", Region = "ie" }) && |
| + length(aws_cloudwatch_metric_alarm.proxy_trust[0].metric_query) == 0 && |
| + aws_cloudwatch_metric_alarm.proxy_trust[0].alarm_actions == toset(["arn:aws:sns:eu-west-1:123456789012:shop-trust"]) && |
| + aws_cloudwatch_metric_alarm.proxy_trust[0].ok_actions == toset(["arn:aws:sns:eu-west-1:123456789012:shop-trust"]) |
| + ) |
| + error_message = "the trust alarm must fire on any trust violation in one minute and notify its own topic" |
| + } |
| + assert { |
| + condition = ( |
| + length(aws_cloudwatch_metric_alarm.port_allocation) == 1 && |
| + aws_cloudwatch_metric_alarm.port_allocation[0].alarm_name == "shop-probe-port-allocation" && |
| + aws_cloudwatch_metric_alarm.port_allocation[0].namespace == "AWS/NetworkELB" && |
| + aws_cloudwatch_metric_alarm.port_allocation[0].metric_name == "PortAllocationErrorCount" && |
| + aws_cloudwatch_metric_alarm.port_allocation[0].statistic == "Sum" && |
| + aws_cloudwatch_metric_alarm.port_allocation[0].period == 300 && |
| + aws_cloudwatch_metric_alarm.port_allocation[0].evaluation_periods == 1 && |
| + aws_cloudwatch_metric_alarm.port_allocation[0].datapoints_to_alarm == 1 && |
| + aws_cloudwatch_metric_alarm.port_allocation[0].threshold == 0 && |
| + aws_cloudwatch_metric_alarm.port_allocation[0].comparison_operator == "GreaterThanThreshold" && |
| + aws_cloudwatch_metric_alarm.port_allocation[0].treat_missing_data == "notBreaching" && |
| + aws_cloudwatch_metric_alarm.port_allocation[0].dimensions == tomap({ LoadBalancer = aws_lb.nlb.arn_suffix }) && |
| + length(aws_cloudwatch_metric_alarm.port_allocation[0].metric_query) == 0 && |
| + aws_cloudwatch_metric_alarm.port_allocation[0].alarm_actions == toset(["arn:aws:sns:eu-west-1:123456789012:shop-trust"]) && |
| + aws_cloudwatch_metric_alarm.port_allocation[0].ok_actions == toset(["arn:aws:sns:eu-west-1:123456789012:shop-trust"]) |
| + ) |
| + error_message = "the port allocation alarm must fire on any NLB port allocation error in five minutes and notify the trust topic" |
| + } |
| + assert { |
| + condition = length(aws_cloudwatch_metric_alarm.clock) == 0 && length(aws_cloudwatch_metric_alarm.admitted) == 0 |
| + error_message = "the trust alarm input must not switch on the clock and admission alarms" |
| + } |
| +} |
| + |
| +# The edge trusts a PROXY header only from the NLB's own node addresses: one |
| +# interface per enabled zone, found by the NLB's ELB description. The lookup |
| +# reads the NLB's ARN, so a plan that creates the NLB defers it; this run |
| +# applies against the mock provider. It supplies both allocations so the test |
| +# creates no protected address, and it runs last so no other run sees its |
| +# state. OpenTofu 1.12 refuses keyed override_data, so the run pins one |
| +# address for every zone. |
| +run "sources_output" { |
| + command = apply |
| + variables { |
| + zones = { |
| + eu-west-1a = { subnet_id = "subnet-0123456789abcdef0", allocation_id = "eipalloc-0123456789abcdef0" } |
| + eu-west-1b = { subnet_id = "subnet-0123456789abcdef1", allocation_id = "eipalloc-0123456789abcdef1" } |
| + } |
| + } |
| + override_data { |
| + target = data.aws_network_interface.node |
| + values = { private_ip = "10.0.1.10" } |
| + } |
| + assert { |
| + condition = output.proxy_protocol_sources == tolist(["10.0.1.10", "10.0.1.10"]) |
| + error_message = "proxy_protocol_sources must list each zone's NLB node address" |
| + } |
| + assert { |
| + condition = toset(keys(data.aws_network_interface.node)) == toset(keys(var.zones)) && alltrue([for az, eni in data.aws_network_interface.node : |
| + { for filter in eni.filter : filter.name => toset(filter.values) } == { |
| + description = toset(["ELB ${aws_lb.nlb.arn_suffix}"]) |
| + subnet-id = toset([var.zones[az].subnet_id]) |
| + } |
| + ]) |
| + error_message = "node lookups must filter by the NLB's ELB description and the zone's subnet" |
| + } |
| +} |
diff --git a/infra/modules/region-host/ingress/variables.tf b/infra/modules/region-host/ingress/variables.tf| index 5269c48e2..14ba0eab7 100644 |
| --- a/infra/modules/region-host/ingress/variables.tf |
| +++ b/infra/modules/region-host/ingress/variables.tf |
| @@ -77,3 +77,55 @@ variable "regional_metrics" { |
| error_message = "regional_metrics must name the deployment bucket and region code used by the boxes" |
| } |
| } |
| + |
| +# Edge PROXY protocol v2 (edge PPv2 spec §8.1). A root moves one target group |
| +# at a time: S0 preserves client IPs, S1 adds PPv2, S2 drops preservation. |
| +# The defaults are S0, today's state, so re-pinning plans no change. |
| +variable "preserve_client_ip" { |
| + type = map(bool) |
| + nullable = false |
| + default = { "80" = true, "443" = true } |
| + description = "Client IP preservation for each target group, keyed by port (\"80\" and \"443\")." |
| + validation { |
| + condition = toset(keys(var.preserve_client_ip)) == toset(["80", "443"]) && alltrue([for on in values(var.preserve_client_ip) : on != null]) |
| + error_message = "preserve_client_ip must set true or false for exactly the keys 80 and 443" |
| + } |
| +} |
| + |
| +variable "proxy_protocol_v2" { |
| + type = map(bool) |
| + nullable = false |
| + default = { "80" = false, "443" = false } |
| + description = "PROXY protocol v2 for each target group, keyed by port (\"80\" and \"443\"). Turning it on needs proxy_trust_alarm." |
| + validation { |
| + condition = toset(keys(var.proxy_protocol_v2)) == toset(["80", "443"]) && alltrue([for on in values(var.proxy_protocol_v2) : on != null]) |
| + error_message = "proxy_protocol_v2 must set true or false for exactly the keys 80 and 443" |
| + } |
| + # S3, preservation off with PPv2 off, delivers the NLB's own address as the |
| + # peer with no header, so any client could supply its own and choose its |
| + # address. It is never a declared state. |
| + validation { |
| + condition = alltrue([for port in ["80", "443"] : |
| + try(var.preserve_client_ip[port] || var.proxy_protocol_v2[port], true) |
| + ]) |
| + error_message = "each target group must preserve client IPs or send PROXY protocol v2; turning both off lets clients choose their address" |
| + } |
| +} |
| + |
| +variable "proxy_trust_alarm" { |
| + type = object({ |
| + deployment = string |
| + region = string |
| + topic_arn = string |
| + }) |
| + default = null |
| + description = "Enable the PROXY trust and port allocation alarms. Deployment is CARLOS_DEPLOYMENT_BUCKET; region is the region_code in region-config.json; topic_arn is a confirmed SNS topic in this module's AWS region. Required before any target group sends PROXY protocol v2." |
| + validation { |
| + condition = var.proxy_trust_alarm == null ? true : ( |
| + try(length(trimspace(var.proxy_trust_alarm.deployment)) > 0, false) && |
| + can(regex("^[a-z][a-z0-9-]{0,31}$", var.proxy_trust_alarm.region)) && |
| + can(regex("^arn:[a-z0-9-]+:sns:${data.aws_region.current.region}:[0-9]{12}:[A-Za-z0-9_-]+$", var.proxy_trust_alarm.topic_arn)) |
| + ) |
| + error_message = "proxy_trust_alarm must name the deployment bucket and region code used by the boxes, and an SNS topic in this module's AWS region" |
| + } |
| +} |
diff --git a/infra/modules/region-host/tests/group.tftest.hcl b/infra/modules/region-host/tests/group.tftest.hcl| index 80562c839..53b17e893 100644 |
| --- a/infra/modules/region-host/tests/group.tftest.hcl |
| +++ b/infra/modules/region-host/tests/group.tftest.hcl |
| @@ -469,3 +469,53 @@ run "group_home_placement" { |
| error_message = "group home placement must remain empty beside its canonical region" |
| } |
| } |
| + |
| +# Edge PROXY protocol v2 (edge PPv2 spec §8.2): an existing target group may |
| +# preserve client IPs (S0), add PROXY protocol v2 (S1) or replace |
| +# preservation with it (S2). Preservation off with PPv2 off (S3) lets any |
| +# client choose its address and is refused. |
| +run "existing_tg_s0_accepted" { |
| + command = plan |
| + override_data { |
| + target = data.aws_lb_target_group.group_http |
| + values = { vpc_id = "vpc-0123456789abcdef0", port = 80, protocol = "TCP", target_type = "instance", load_balancer_arns = ["arn:aws:elasticloadbalancing:eu-west-1:123456789012:loadbalancer/net/test/1234"], preserve_client_ip = "true", proxy_protocol_v2 = false } |
| + } |
| + assert { |
| + condition = length(aws_security_group.group) == 1 |
| + error_message = "a target group preserving client IPs must be accepted" |
| + } |
| +} |
| +run "existing_tg_s1_accepted" { |
| + command = plan |
| + override_data { |
| + target = data.aws_lb_target_group.group_http |
| + values = { vpc_id = "vpc-0123456789abcdef0", port = 80, protocol = "TCP", target_type = "instance", load_balancer_arns = ["arn:aws:elasticloadbalancing:eu-west-1:123456789012:loadbalancer/net/test/1234"], preserve_client_ip = "true", proxy_protocol_v2 = true } |
| + } |
| + assert { |
| + condition = length(aws_security_group.group) == 1 |
| + error_message = "a target group preserving client IPs and sending PROXY protocol v2 must be accepted" |
| + } |
| +} |
| +run "existing_tg_s2_accepted" { |
| + command = plan |
| + override_data { |
| + target = data.aws_lb_target_group.group_http |
| + values = { vpc_id = "vpc-0123456789abcdef0", port = 80, protocol = "TCP", target_type = "instance", load_balancer_arns = ["arn:aws:elasticloadbalancing:eu-west-1:123456789012:loadbalancer/net/test/1234"], preserve_client_ip = "false", proxy_protocol_v2 = true } |
| + } |
| + override_data { |
| + target = data.aws_lb_target_group.group_https |
| + values = { vpc_id = "vpc-0123456789abcdef0", port = 443, protocol = "TCP", target_type = "instance", load_balancer_arns = ["arn:aws:elasticloadbalancing:eu-west-1:123456789012:loadbalancer/net/test/1234"], preserve_client_ip = "false", proxy_protocol_v2 = true } |
| + } |
| + assert { |
| + condition = length(aws_security_group.group) == 1 |
| + error_message = "target groups sending PROXY protocol v2 without preservation must be accepted" |
| + } |
| +} |
| +run "existing_tg_s3_refused" { |
| + command = plan |
| + override_data { |
| + target = data.aws_lb_target_group.group_https |
| + values = { vpc_id = "vpc-0123456789abcdef0", port = 443, protocol = "TCP", target_type = "instance", load_balancer_arns = ["arn:aws:elasticloadbalancing:eu-west-1:123456789012:loadbalancer/net/test/1234"], preserve_client_ip = "false", proxy_protocol_v2 = false } |
| + } |
| + expect_failures = [aws_security_group.group] |
| +} |