Skip to content

Commit

Permalink
Fix bug where egress proxy route had a leading hyphen
Browse files Browse the repository at this point in the history
  • Loading branch information
rahearn committed Dec 20, 2024
1 parent d3849d6 commit abc01da
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions egress_proxy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ locals {
denyacl = templatefile("${path.module}/acl.tftpl", { list = var.denylist })

# Yields something like: orgname-spacename-name.apps.internal, limited to the last 63 characters
route_host = substr("${var.cf_org_name}-${replace(var.cf_egress_space.name, ".", "-")}-${var.name}", -63, -1)
egress_route = "${local.route_host}.apps.internal"
default_route_host = "${var.cf_org_name}-${replace(var.cf_egress_space.name, ".", "-")}-${var.name}"
egress_route = "${replace(lower(substr(coalesce(var.route_host, local.default_route_host), -63, -1)), "/^[^a-z]*/", "")}.apps.internal"
}


Expand Down
26 changes: 26 additions & 0 deletions egress_proxy/tests/creation.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,30 @@ run "test_proxy_creation" {
condition = output.http_port == 8080
error_message = "http_port reports port 8080 for plaintext"
}

}

run "test_specific_hostname_bug" {
variables {
cf_org_name = "gsa-tts-devtools-prototyping"
cf_egress_space = {
id = "169c6e21-2513-43f7-bbff-80cc5e456882"
name = "rca-tfm-stage-egress"
}
name = "egress-proxy-staging"
}
assert {
condition = can(regex("[a-z]", substr(output.domain, 0, 1)))
error_message = "proxy domain must start with an alpha character"
}
}

run "test_custom_hostname_is_trimmed" {
variables {
route_host = "-3host-name"
}
assert {
condition = output.domain == "host-name.apps.internal"
error_message = "proxy domain is stripped of any non-alpha characters"
}
}
6 changes: 6 additions & 0 deletions egress_proxy/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ variable "name" {
description = "name of the egress proxy application"
}

variable "route_host" {
type = string
default = null
description = "Hostname to access the egress proxy on apps.internal domain (optional)"
}

variable "egress_memory" {
type = string
description = "Memory to allocate to egress proxy app, including unit"
Expand Down

0 comments on commit abc01da

Please sign in to comment.