Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate provider from cloudfoundry-community to cloudfoundry #57

Merged
merged 19 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
rahearn marked this conversation as resolved.
Show resolved Hide resolved
}
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" {
rahearn marked this conversation as resolved.
Show resolved Hide resolved
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