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

Optionally allow specifying 0:n target apps for domain service #39

Merged
merged 4 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading