Skip to content

Unify handling of CF landscape label across DC mission samples #269

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

Merged
merged 3 commits into from
Jul 22, 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
18 changes: 6 additions & 12 deletions released/discovery_center/mission_3061/step1/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,18 @@ data "btp_subaccount_environments" "all" {
}

# Take the landscape label from the first CF environment if no environment label is provided
resource "null_resource" "cache_target_environment" {
triggers = {
label = length(var.cf_landscape_label) > 0 ? var.cf_landscape_label : [for env in data.btp_subaccount_environments.all.values : env if env.service_name == "cloudfoundry" && env.environment_type == "cloudfoundry"][0].landscape_label
}

lifecycle {
ignore_changes = all
}
resource "terraform_data" "cf_landscape_label" {
input = length(var.cf_landscape_label) > 0 ? var.cf_landscape_label : [for env in data.btp_subaccount_environments.all.values : env if env.service_name == "cloudfoundry" && env.environment_type == "cloudfoundry"][0].landscape_label
}

# Create the Cloud Foundry environment instance
resource "btp_subaccount_environment_instance" "cf_abap" {
resource "btp_subaccount_environment_instance" "cloudfoundry" {
subaccount_id = btp_subaccount.abap_subaccount.id
name = local.subaccount_cf_org
environment_type = "cloudfoundry"
service_name = "cloudfoundry"
plan_name = var.cf_plan_name
landscape_label = null_resource.cache_target_environment.triggers.label
landscape_label = terraform_data.cf_landscape_label.output

parameters = jsonencode({
instance_name = local.subaccount_cf_org
Expand All @@ -108,8 +102,8 @@ resource "local_file" "output_vars_step1" {
content = <<-EOT
origin = "${var.origin}"

cf_api_url = "${jsondecode(btp_subaccount_environment_instance.cf_abap.labels)["API Endpoint"]}"
cf_org_id = "${btp_subaccount_environment_instance.cf_abap.platform_id}"
cf_api_url = "${jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["API Endpoint"]}"
cf_org_id = "${btp_subaccount_environment_instance.cloudfoundry.platform_id}"

cf_org_auditors = ${jsonencode(var.cf_org_auditors)}
cf_org_billing_managers = ${jsonencode(var.cf_org_billing_managers)}
Expand Down
6 changes: 3 additions & 3 deletions released/discovery_center/mission_3061/step1/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ output "cf_org_name" {
}

output "cf_org_id" {
value = btp_subaccount_environment_instance.cf_abap.platform_id
value = btp_subaccount_environment_instance.cloudfoundry.platform_id
description = "The ID of the Cloud Foundry org connected to the subaccount."
}

output "cf_api_url" {
value = lookup(jsondecode(btp_subaccount_environment_instance.cf_abap.labels), "API Endpoint", "not found")
value = lookup(jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels), "API Endpoint", "not found")
description = "API endpoint of the Cloud Foundry environment."
}

output "cf_landscape_label" {
value = btp_subaccount_environment_instance.cf_abap.landscape_label
value = btp_subaccount_environment_instance.cloudfoundry.landscape_label
description = "Landscape label of the Cloud Foundry environment."
}

Expand Down
15 changes: 3 additions & 12 deletions released/discovery_center/mission_3239/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,9 @@ resource "btp_subaccount_trust_configuration" "fully_customized" {
# Creation of Cloud Foundry environment
###############################################################################################


# ------------------------------------------------------------------------------------------------------
# Take the landscape label from the first CF environment if no environment label is provided
# ------------------------------------------------------------------------------------------------------
resource "null_resource" "cache_target_environment" {
triggers = {
label = length(var.environment_label) > 0 ? var.environment_label : [for env in data.btp_subaccount_environments.all.values : env if env.service_name == "cloudfoundry" && env.environment_type == "cloudfoundry"][0].landscape_label
}

lifecycle {
ignore_changes = all
}
resource "terraform_data" "cf_landscape_label" {
input = length(var.cf_landscape_label) > 0 ? var.cf_landscape_label : [for env in data.btp_subaccount_environments.all.values : env if env.service_name == "cloudfoundry" && env.environment_type == "cloudfoundry"][0].landscape_label
}

resource "btp_subaccount_environment_instance" "cf" {
Expand All @@ -62,7 +53,7 @@ resource "btp_subaccount_environment_instance" "cf" {
environment_type = "cloudfoundry"
service_name = "cloudfoundry"
plan_name = "standard"
landscape_label = null_resource.cache_target_environment.triggers.label
landscape_label = terraform_data.cf_landscape_label.output

parameters = jsonencode({
instance_name = local.project_subaccount_cf_org
Expand Down
3 changes: 1 addition & 2 deletions released/discovery_center/mission_3239/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ variable "subaccount_id" {
default = ""
}


variable "custom_idp" {
type = string
description = "Defines the custom IDP to be used for the subaccount"
Expand All @@ -40,7 +39,7 @@ variable "org" {
default = "org"
}

variable "environment_label" {
variable "cf_landscape_label" {
type = string
description = "In case there are multiple environments available for a subaccount, you can use this label to choose with which one you want to go. If nothing is given, we take by default the first available."
default = ""
Expand Down
10 changes: 5 additions & 5 deletions released/discovery_center/mission_3488/step1/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ data "btp_subaccount_environments" "all" {
}

# Take the landscape label from the first CF environment if no environment label is provided
resource "terraform_data" "replacement" {
resource "terraform_data" "cf_landscape_label" {
input = length(var.cf_landscape_label) > 0 ? var.cf_landscape_label : [for env in data.btp_subaccount_environments.all.values : env if env.service_name == "cloudfoundry" && env.environment_type == "cloudfoundry"][0].landscape_label
}

# Create the Cloud Foundry environment instance
resource "btp_subaccount_environment_instance" "cf_sac" {
resource "btp_subaccount_environment_instance" "cloudfoundry" {
subaccount_id = btp_subaccount.dc_mission.id
name = local.subaccount_cf_org
environment_type = "cloudfoundry"
service_name = "cloudfoundry"
plan_name = var.cf_plan_name
landscape_label = terraform_data.replacement.output
landscape_label = terraform_data.cf_landscape_label.output

parameters = jsonencode({
instance_name = local.subaccount_cf_org
Expand All @@ -64,8 +64,8 @@ resource "local_file" "output_vars_step1" {
content = <<-EOT
origin = "${var.origin}"

cf_api_url = "${jsondecode(btp_subaccount_environment_instance.cf_sac.labels)["API Endpoint"]}"
cf_org_id = "${btp_subaccount_environment_instance.cf_sac.platform_id}"
cf_api_url = "${jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["API Endpoint"]}"
cf_org_id = "${btp_subaccount_environment_instance.cloudfoundry.platform_id}"

cf_org_auditors = ${jsonencode(var.cf_org_auditors)}
cf_org_billing_managers = ${jsonencode(var.cf_org_billing_managers)}
Expand Down
6 changes: 3 additions & 3 deletions released/discovery_center/mission_3488/step1/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ output "cf_org_name" {
}

output "cf_org_id" {
value = btp_subaccount_environment_instance.cf_sac.platform_id
value = btp_subaccount_environment_instance.cloudfoundry.platform_id
description = "The ID of the Cloud Foundry org connected to the subaccount."
}

output "cf_api_url" {
value = lookup(jsondecode(btp_subaccount_environment_instance.cf_sac.labels), "API Endpoint", "not found")
value = lookup(jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels), "API Endpoint", "not found")
description = "API endpoint of the Cloud Foundry environment."
}

output "cf_landscape_label" {
value = btp_subaccount_environment_instance.cf_sac.landscape_label
value = btp_subaccount_environment_instance.cloudfoundry.landscape_label
description = "Landscape label of the Cloud Foundry environment."
}

Expand Down
12 changes: 4 additions & 8 deletions released/discovery_center/mission_3501/step1/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,11 @@ resource "btp_subaccount_role_collection_assignment" "subaccount-service-admins"
data "btp_subaccount_environments" "all" {
subaccount_id = data.btp_subaccount.project.id
}

locals {
cf_landscape_labels = [
for env in data.btp_subaccount_environments.all.values : env.landscape_label
if env.environment_type == "cloudfoundry"
]
# Take the landscape label from the first CF environment if no environment label is provided
resource "terraform_data" "cf_landscape_label" {
input = length(var.cf_landscape_label) > 0 ? var.cf_landscape_label : [for env in data.btp_subaccount_environments.all.values : env if env.service_name == "cloudfoundry" && env.environment_type == "cloudfoundry"][0].landscape_label
}


######################################################################
# Creation of Cloud Foundry environment
######################################################################
Expand All @@ -69,7 +65,7 @@ resource "btp_subaccount_environment_instance" "cloudfoundry" {
environment_type = "cloudfoundry"
service_name = "cloudfoundry"
plan_name = "standard"
landscape_label = local.cf_landscape_labels[0]
landscape_label = terraform_data.cf_landscape_label.output
parameters = jsonencode({
instance_name = local.project_subaccount_cf_org
})
Expand Down
7 changes: 7 additions & 0 deletions released/discovery_center/mission_3501/step1/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ variable "cf_org_name" {
default = "cloud-foundry"
}

# cf landscape label
variable "cf_landscape_label" {
type = string
description = "The Cloud Foundry landscape (format example eu10-004)."
default = ""
}

# Region
variable "region" {
type = string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ output "cf_org_id" {
description = "The Cloudfoundry org id."
}

output "cf_landscape_label" {
value = btp_subaccount_environment_instance.cloudfoundry.landscape_label
description = "Landscape label of the Cloud Foundry environment."
}

output "event_mesh_url" {
value = btp_subaccount_subscription.event_mesh_application.subscription_url
description = "Event Mesh URL"
Expand Down
5 changes: 5 additions & 0 deletions released/discovery_center/mission_3774/step1/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ output "cf_org_name" {
description = "The Cloudfoundry org name."
}

output "cf_landscape_label" {
value = btp_subaccount_environment_instance.cloudfoundry.landscape_label
description = "Landscape label of the Cloud Foundry environment."
}

output "cf_org_admins" {
value = var.cf_org_admins
description = "The Cloudfoundry org admins."
Expand Down
11 changes: 4 additions & 7 deletions released/discovery_center/mission_4172/step1/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,11 @@ data "btp_subaccount_environments" "all" {
subaccount_id = data.btp_subaccount.project.id
}

locals {
cf_landscape_labels = [
for env in data.btp_subaccount_environments.all.values : env.landscape_label
if env.environment_type == "cloudfoundry"
]
# Take the landscape label from the first CF environment if no environment label is provided
resource "terraform_data" "cf_landscape_label" {
input = length(var.cf_landscape_label) > 0 ? var.cf_landscape_label : [for env in data.btp_subaccount_environments.all.values : env if env.service_name == "cloudfoundry" && env.environment_type == "cloudfoundry"][0].landscape_label
}


######################################################################
# Creation of Cloud Foundry environment
######################################################################
Expand All @@ -69,7 +66,7 @@ resource "btp_subaccount_environment_instance" "cloudfoundry" {
environment_type = "cloudfoundry"
service_name = "cloudfoundry"
plan_name = "standard"
landscape_label = local.cf_landscape_labels[0]
landscape_label = terraform_data.cf_landscape_label.output
parameters = jsonencode({
instance_name = local.project_subaccount_cf_org
})
Expand Down
7 changes: 7 additions & 0 deletions released/discovery_center/mission_4172/step1/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ variable "cf_org_name" {
default = "cloud-foundry"
}

# cf landscape label
variable "cf_landscape_label" {
type = string
description = "The Cloud Foundry landscape (format example eu10-004)."
default = ""
}

# Region
variable "region" {
type = string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ output "cf_api_url" {
}

output "cf_landscape_label" {
value = terraform_data.cf_landscape_label.output
value = btp_subaccount_environment_instance.cloudfoundry.landscape_label
description = "The Cloudfoundry landscape label."
}

Expand Down
4 changes: 2 additions & 2 deletions released/discovery_center/mission_4371/step1/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ data "btp_subaccount_environments" "all" {
# Take the landscape label from the first CF environment if no environment label is provided
# (this replaces the previous null_resource)
# ------------------------------------------------------------------------------------------------------
resource "terraform_data" "replacement" {
resource "terraform_data" "cf_landscape_label" {
input = length(var.cf_landscape_label) > 0 ? var.cf_landscape_label : [for env in data.btp_subaccount_environments.all.values : env if env.service_name == "cloudfoundry" && env.environment_type == "cloudfoundry"][0].landscape_label
}
# ------------------------------------------------------------------------------------------------------
Expand All @@ -186,7 +186,7 @@ resource "btp_subaccount_environment_instance" "cloudfoundry" {
environment_type = "cloudfoundry"
service_name = "cloudfoundry"
plan_name = "standard"
landscape_label = terraform_data.replacement.output
landscape_label = terraform_data.cf_landscape_label.output
parameters = jsonencode({
instance_name = local.subaccount_cf_org
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ output "cf_api_url" {
}

output "cf_landscape_label" {
value = terraform_data.replacement.output
value = btp_subaccount_environment_instance.cloudfoundry.landscape_label
description = "The Cloudfoundry landscape label."
}

Expand Down
3 changes: 1 addition & 2 deletions released/discovery_center/mission_4441/step1/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ output "cf_api_url" {
description = "The Cloudfoundry API URL."
}


output "cf_landscape_label" {
value = terraform_data.cf_landscape_label.output
value = btp_subaccount_environment_instance.cloudfoundry.landscape_label
description = "The Cloudfoundry landscape label."
}

Expand Down