Skip to content

Commit

Permalink
Simplify routing for clamav module
Browse files Browse the repository at this point in the history
  • Loading branch information
rahearn committed Nov 22, 2024
1 parent 8c267b3 commit a11cbd1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 45 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module "clamav" {
source = "github.com/GSA-TTS/terraform-cloudgov//clamav?ref=v2.0.0-beta.1"
cf_org_name = local.cf_org_name
cf_space = data.cloudfoundry_space.app_space
cf_space_name = local.cf_space_name
app_name = "app_name"
name = "my_clamav_name"
clamav_image = "ghcr.io/gsa-tts/clamav-rest/clamav:TAG_NAME"
Expand Down
16 changes: 5 additions & 11 deletions clamav/main.tf
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
data "cloudfoundry_domain" "internal" {
name = "apps.internal"
locals {
endpoint = "${var.name}.apps.internal"
}

data "cloudfoundry_app" "app" {
name = var.app_name
org_name = var.cf_org_name
space_name = var.cf_space.name
}

resource "cloudfoundry_route" "clamav_route" {
space = var.cf_space.id
domain = data.cloudfoundry_domain.internal.id
host = var.name
space_name = var.cf_space_name
}

resource "cloudfoundry_app" "clamav_api" {
name = var.name
space_name = var.cf_space.name
space_name = var.cf_space_name
org_name = var.cf_org_name

memory = var.clamav_memory
Expand All @@ -27,7 +21,7 @@ resource "cloudfoundry_app" "clamav_api" {
docker_image = var.clamav_image
routes = [
{
route = cloudfoundry_route.clamav_route.url
route = local.endpoint
}
]
environment = {
Expand Down
6 changes: 1 addition & 5 deletions clamav/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ output "app_id" {
value = cloudfoundry_app.clamav_api.id
}

output "route_id" {
value = cloudfoundry_route.clamav_route.id
}

output "endpoint" {
value = cloudfoundry_route.clamav_route.url
value = local.endpoint
}
25 changes: 3 additions & 22 deletions clamav/tests/creation.tftest.hcl
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
mock_provider "cloudfoundry" {
mock_data "cloudfoundry_domain" {
defaults = {
id = "7dbc73bb-28d3-481f-afcc-a81545825bd0"
}
}
mock_resource "cloudfoundry_route" {
defaults = {
url = "terraform-cloudgov-clamav-test.apps.internal"
}
}
}
mock_provider "cloudfoundry" {}
mock_provider "cloudfoundry-community" {}

variables {
cf_org_name = "gsa-tts-devtools-prototyping"
cf_space = {
id = "e243575e-376a-4b70-b891-23c3fa1a0680"
name = "terraform-cloudgov-ci-tests"
}
cf_org_name = "gsa-tts-devtools-prototyping"
cf_space_name = "terraform-cloudgov-ci-tests"
app_name = "terraform_cloudgov_app"
name = "terraform-cloudgov-clamav-test"
clamav_image = "ghcr.io/gsa-tts/clamav-rest/clamav:TAG"
Expand All @@ -30,11 +16,6 @@ run "test_app_creation" {
error_message = "App ID output must match the clamav app ID"
}

assert {
condition = cloudfoundry_route.clamav_route.id == output.route_id
error_message = "Route ID output must match the ID of the route to the clamav app"
}

assert {
condition = "${var.name}.apps.internal" == output.endpoint
error_message = "Endpoint output must match the clamav route endpoint"
Expand Down
9 changes: 3 additions & 6 deletions clamav/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ variable "cf_org_name" {
description = "cloud.gov organization name"
}

variable "cf_space" {
type = object({
id = string
name = string
})
description = "cloud.gov space resource"
variable "cf_space_name" {
type = string
description = "cloud.gov space name"
}

variable "app_name" {
Expand Down

0 comments on commit a11cbd1

Please sign in to comment.