Skip to content

Commit 2b21c24

Browse files
authored
Unify handling of CF landscape label across DC mission samples (#269)
1 parent fb61ccd commit 2b21c24

File tree

23 files changed

+58
-58
lines changed

23 files changed

+58
-58
lines changed

released/discovery_center/mission_3061/step1/main.tf

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,18 @@ data "btp_subaccount_environments" "all" {
7171
}
7272

7373
# Take the landscape label from the first CF environment if no environment label is provided
74-
resource "null_resource" "cache_target_environment" {
75-
triggers = {
76-
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
77-
}
78-
79-
lifecycle {
80-
ignore_changes = all
81-
}
74+
resource "terraform_data" "cf_landscape_label" {
75+
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
8276
}
8377

8478
# Create the Cloud Foundry environment instance
85-
resource "btp_subaccount_environment_instance" "cf_abap" {
79+
resource "btp_subaccount_environment_instance" "cloudfoundry" {
8680
subaccount_id = btp_subaccount.abap_subaccount.id
8781
name = local.subaccount_cf_org
8882
environment_type = "cloudfoundry"
8983
service_name = "cloudfoundry"
9084
plan_name = var.cf_plan_name
91-
landscape_label = null_resource.cache_target_environment.triggers.label
85+
landscape_label = terraform_data.cf_landscape_label.output
9286

9387
parameters = jsonencode({
9488
instance_name = local.subaccount_cf_org
@@ -108,8 +102,8 @@ resource "local_file" "output_vars_step1" {
108102
content = <<-EOT
109103
origin = "${var.origin}"
110104
111-
cf_api_url = "${jsondecode(btp_subaccount_environment_instance.cf_abap.labels)["API Endpoint"]}"
112-
cf_org_id = "${btp_subaccount_environment_instance.cf_abap.platform_id}"
105+
cf_api_url = "${jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["API Endpoint"]}"
106+
cf_org_id = "${btp_subaccount_environment_instance.cloudfoundry.platform_id}"
113107
114108
cf_org_auditors = ${jsonencode(var.cf_org_auditors)}
115109
cf_org_billing_managers = ${jsonencode(var.cf_org_billing_managers)}

released/discovery_center/mission_3061/step1/outputs.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ output "cf_org_name" {
1414
}
1515

1616
output "cf_org_id" {
17-
value = btp_subaccount_environment_instance.cf_abap.platform_id
17+
value = btp_subaccount_environment_instance.cloudfoundry.platform_id
1818
description = "The ID of the Cloud Foundry org connected to the subaccount."
1919
}
2020

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

2626
output "cf_landscape_label" {
27-
value = btp_subaccount_environment_instance.cf_abap.landscape_label
27+
value = btp_subaccount_environment_instance.cloudfoundry.landscape_label
2828
description = "Landscape label of the Cloud Foundry environment."
2929
}
3030

released/discovery_center/mission_3239/main.tf

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,9 @@ resource "btp_subaccount_trust_configuration" "fully_customized" {
4242
# Creation of Cloud Foundry environment
4343
###############################################################################################
4444

45-
46-
# ------------------------------------------------------------------------------------------------------
4745
# Take the landscape label from the first CF environment if no environment label is provided
48-
# ------------------------------------------------------------------------------------------------------
49-
resource "null_resource" "cache_target_environment" {
50-
triggers = {
51-
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
52-
}
53-
54-
lifecycle {
55-
ignore_changes = all
56-
}
46+
resource "terraform_data" "cf_landscape_label" {
47+
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
5748
}
5849

5950
resource "btp_subaccount_environment_instance" "cf" {
@@ -62,7 +53,7 @@ resource "btp_subaccount_environment_instance" "cf" {
6253
environment_type = "cloudfoundry"
6354
service_name = "cloudfoundry"
6455
plan_name = "standard"
65-
landscape_label = null_resource.cache_target_environment.triggers.label
56+
landscape_label = terraform_data.cf_landscape_label.output
6657

6758
parameters = jsonencode({
6859
instance_name = local.project_subaccount_cf_org

released/discovery_center/mission_3239/variables.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ variable "subaccount_id" {
1515
default = ""
1616
}
1717

18-
1918
variable "custom_idp" {
2019
type = string
2120
description = "Defines the custom IDP to be used for the subaccount"
@@ -40,7 +39,7 @@ variable "org" {
4039
default = "org"
4140
}
4241

43-
variable "environment_label" {
42+
variable "cf_landscape_label" {
4443
type = string
4544
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."
4645
default = ""

released/discovery_center/mission_3488/step1/main.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ data "btp_subaccount_environments" "all" {
4040
}
4141

4242
# Take the landscape label from the first CF environment if no environment label is provided
43-
resource "terraform_data" "replacement" {
43+
resource "terraform_data" "cf_landscape_label" {
4444
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
4545
}
4646

4747
# Create the Cloud Foundry environment instance
48-
resource "btp_subaccount_environment_instance" "cf_sac" {
48+
resource "btp_subaccount_environment_instance" "cloudfoundry" {
4949
subaccount_id = btp_subaccount.dc_mission.id
5050
name = local.subaccount_cf_org
5151
environment_type = "cloudfoundry"
5252
service_name = "cloudfoundry"
5353
plan_name = var.cf_plan_name
54-
landscape_label = terraform_data.replacement.output
54+
landscape_label = terraform_data.cf_landscape_label.output
5555

5656
parameters = jsonencode({
5757
instance_name = local.subaccount_cf_org
@@ -64,8 +64,8 @@ resource "local_file" "output_vars_step1" {
6464
content = <<-EOT
6565
origin = "${var.origin}"
6666
67-
cf_api_url = "${jsondecode(btp_subaccount_environment_instance.cf_sac.labels)["API Endpoint"]}"
68-
cf_org_id = "${btp_subaccount_environment_instance.cf_sac.platform_id}"
67+
cf_api_url = "${jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["API Endpoint"]}"
68+
cf_org_id = "${btp_subaccount_environment_instance.cloudfoundry.platform_id}"
6969
7070
cf_org_auditors = ${jsonencode(var.cf_org_auditors)}
7171
cf_org_billing_managers = ${jsonencode(var.cf_org_billing_managers)}

released/discovery_center/mission_3488/step1/outputs.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ output "cf_org_name" {
99
}
1010

1111
output "cf_org_id" {
12-
value = btp_subaccount_environment_instance.cf_sac.platform_id
12+
value = btp_subaccount_environment_instance.cloudfoundry.platform_id
1313
description = "The ID of the Cloud Foundry org connected to the subaccount."
1414
}
1515

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

2121
output "cf_landscape_label" {
22-
value = btp_subaccount_environment_instance.cf_sac.landscape_label
22+
value = btp_subaccount_environment_instance.cloudfoundry.landscape_label
2323
description = "Landscape label of the Cloud Foundry environment."
2424
}
2525

released/discovery_center/mission_3501/step1/main.tf

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,11 @@ resource "btp_subaccount_role_collection_assignment" "subaccount-service-admins"
5151
data "btp_subaccount_environments" "all" {
5252
subaccount_id = data.btp_subaccount.project.id
5353
}
54-
55-
locals {
56-
cf_landscape_labels = [
57-
for env in data.btp_subaccount_environments.all.values : env.landscape_label
58-
if env.environment_type == "cloudfoundry"
59-
]
54+
# Take the landscape label from the first CF environment if no environment label is provided
55+
resource "terraform_data" "cf_landscape_label" {
56+
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
6057
}
6158

62-
6359
######################################################################
6460
# Creation of Cloud Foundry environment
6561
######################################################################
@@ -69,7 +65,7 @@ resource "btp_subaccount_environment_instance" "cloudfoundry" {
6965
environment_type = "cloudfoundry"
7066
service_name = "cloudfoundry"
7167
plan_name = "standard"
72-
landscape_label = local.cf_landscape_labels[0]
68+
landscape_label = terraform_data.cf_landscape_label.output
7369
parameters = jsonencode({
7470
instance_name = local.project_subaccount_cf_org
7571
})
File renamed without changes.

released/discovery_center/mission_3501/step1/variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ variable "cf_org_name" {
2828
default = "cloud-foundry"
2929
}
3030

31+
# cf landscape label
32+
variable "cf_landscape_label" {
33+
type = string
34+
description = "The Cloud Foundry landscape (format example eu10-004)."
35+
default = ""
36+
}
37+
3138
# Region
3239
variable "region" {
3340
type = string
File renamed without changes.

0 commit comments

Comments
 (0)