Skip to content

Commit

Permalink
Enable connecting egress-proxy to multiple client spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
rahearn committed Nov 22, 2024
1 parent 8a19e8f commit 8c267b3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ Prerequities:
module "egress_proxy" {
source = "github.com/GSA-TTS/terraform-cloudgov//egress_proxy?ref=v2.0.0-beta.1"
cf_org_name = local.cf_org_name
cf_egress_space = data.cloudfoundry_space.egress_space
cf_client_space = data.cloudfoundry_space.app_space
name = "egress-proxy"
cf_org_name = local.cf_org_name
cf_egress_space = data.cloudfoundry_space.egress_space
cf_client_spaces = {(data.cloudfoundry_space.app_space.name) = data.cloudfoundy_space.app_space.id}
name = "egress-proxy"
allowlist = {
"source_app_name" = ["host.com:443", "otherhost.com:443"]
}
Expand Down
9 changes: 5 additions & 4 deletions egress_proxy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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)
route_host = substr("${var.cf_org_name}-${replace(var.cf_egress_space.name, ".", "-")}-${var.name}", -63, -1)
egress_route = "${local.route_host}.apps.internal"
}

Expand Down Expand Up @@ -74,9 +74,10 @@ locals {
}

resource "cloudfoundry_service_instance" "credentials" {
name = "${var.name}-creds"
space = var.cf_client_space.id
type = "user-provided"
for_each = var.cf_client_spaces
name = "${var.name}-credentials"
space = each.value
type = "user-provided"
credentials = jsonencode({
"uri" = local.https_proxy
"domain" = local.domain
Expand Down
8 changes: 6 additions & 2 deletions egress_proxy/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ output "app_id" {
value = cloudfoundry_app.egress_app.id
}

output "credential_service_id" {
value = cloudfoundry_service_instance.credentials.id
output "credential_service_ids" {
value = { for k, v in cloudfoundry_service_instance.credentials : k => v.id }
}

output "credential_service_name" {
value = values(cloudfoundry_service_instance.credentials)[0].name
}
20 changes: 11 additions & 9 deletions egress_proxy/tests/creation.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ variables {
id = "5178d8f5-d19a-4782-ad07-467822480c68"
name = "terraform-cloudgov-ci-tests-egress"
}
cf_client_space = {
id = "e243575e-376a-4b70-b891-23c3fa1a0680"
name = "terraform-cloudgov-ci-tests"
}
name = "terraform-egress-app"
allowlist = { "continuous_monitoring-staging" = ["raw.githubusercontent.com:443"] }
cf_client_spaces = { "client-space" = "e243575e-376a-4b70-b891-23c3fa1a0680" }
name = "terraform-egress-app"
allowlist = { "continuous_monitoring-staging" = ["raw.githubusercontent.com:443"] }
}

run "test_proxy_creation" {
Expand All @@ -37,7 +34,7 @@ run "test_proxy_creation" {
}

assert {
condition = output.domain == cloudfoundry_route.egress_route.url
condition = output.domain == local.egress_route
error_message = "Output domain must match the route url"
}

Expand Down Expand Up @@ -67,7 +64,12 @@ run "test_proxy_creation" {
}

assert {
condition = output.credential_service_id == cloudfoundry_service_instance.credentials.id
error_message = "Output credential_service_id is the user-provided-service's guid"
condition = output.credential_service_ids == { "client-space" = cloudfoundry_service_instance.credentials["client-space"].id }
error_message = "Output credential_service_ids is a map of client_space_ids to credential_instance_ids"
}

assert {
condition = output.credential_service_name == "${var.name}-credentials"
error_message = "Output credential_service_name is the single name shared by all of the credential services"
}
}
9 changes: 3 additions & 6 deletions egress_proxy/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ variable "cf_egress_space" {
description = "cloud.gov space egress"
}

variable "cf_client_space" {
type = object({
id = string
name = string
})
description = "cloud.gov space for client apps"
variable "cf_client_spaces" {
type = map(string)
description = "map of cloud.gov space names to spaces ids for client apps"
}

variable "name" {
Expand Down

0 comments on commit 8c267b3

Please sign in to comment.