Skip to content

Commit

Permalink
Merge pull request #39 from GSA-TTS/domain-0-n-apps
Browse files Browse the repository at this point in the history
Optionally allow specifying 0:n target apps for domain service
  • Loading branch information
rahearn authored May 13, 2024
2 parents 741353a + 190fb24 commit e0f0e22
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
14 changes: 10 additions & 4 deletions domain/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
locals {
service_name = (var.name == "" ? "${data.cloudfoundry_app.app.name}-${var.domain_name}" : var.name)
endpoint = (var.host_name != null ? "${var.host_name}.${var.domain_name}" : var.domain_name)
target_apps = (var.app_name_or_id != null ? [var.app_name_or_id] : var.app_names_or_ids)
service_name = (var.name == "" ? "${data.cloudfoundry_app.app[local.target_apps[0]].name}-${var.domain_name}" : var.name)
}

data "cloudfoundry_space" "space" {
Expand All @@ -9,7 +10,8 @@ data "cloudfoundry_space" "space" {
}

data "cloudfoundry_app" "app" {
name_or_id = var.app_name_or_id
for_each = toset(local.target_apps)
name_or_id = each.key
space = data.cloudfoundry_space.space.id
}

Expand All @@ -29,8 +31,12 @@ resource "cloudfoundry_route" "origin_route" {
domain = data.cloudfoundry_domain.origin_url.id
hostname = var.host_name
space = data.cloudfoundry_space.space.id
target {
app = data.cloudfoundry_app.app.id

dynamic "target" {
for_each = data.cloudfoundry_app.app
content {
app = target.value.id
}
}
}

Expand Down
11 changes: 9 additions & 2 deletions domain/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ variable "cf_space_name" {

variable "app_name_or_id" {
type = string
description = "base application name to be accessed at this domain name"
description = "base application name or id to be accessed at this domain name. Overrides var.app_names_or_ids if used"
default = null
}

variable "app_names_or_ids" {
type = list(string)
description = "base application names or ids to be accessed at this domain name. Overridden by var.app_name_or_id if used"
default = []
}

variable "name" {
type = string
description = "name of the service instance"
description = "name of the service instance. Required if not passing in app names or ids"
default = ""
}

Expand Down

0 comments on commit e0f0e22

Please sign in to comment.