Skip to content

Commit

Permalink
Optionally allow specifying 0:n target apps for domain service
Browse files Browse the repository at this point in the history
  • Loading branch information
rahearn committed May 8, 2024
1 parent 741353a commit 541d295
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 9 additions & 3 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)

Check failure on line 2 in domain/main.tf

View workflow job for this annotation

GitHub Actions / Validate terraform configuration (domain)

Missing resource instance key
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)
}

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 = {

Check failure on line 37 in domain/main.tf

View workflow job for this annotation

GitHub Actions / Validate terraform configuration (domain)

Unsupported argument
app = target.id
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion domain/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ 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. Conflicts with var.app_names_or_ids"
default = null
}

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

variable "name" {
Expand Down

0 comments on commit 541d295

Please sign in to comment.