Skip to content

Commit 82cf97b

Browse files
jglanderrui1610
andauthored
4441: Polished QAS enabled Mission (#309)
* 4441: Polished QAS enabled Mission - polished code to be consistent with other QAS enabled missions (like 4024, 3585, ...) * 4441: removed all e-mail validations --------- Co-authored-by: Rui Nogueira <[email protected]>
1 parent 6864466 commit 82cf97b

File tree

6 files changed

+219
-198
lines changed

6 files changed

+219
-198
lines changed

released/discovery_center/mission_4441/minimal_setup_enterprise/step1/main.tf

Lines changed: 92 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
# ------------------------------------------------------------------------------------------------------
2-
# SUBACCOUNT SETUP
2+
# Subaccount setup for DC mission 4441
33
# ------------------------------------------------------------------------------------------------------
44
# Setup subaccount domain (to ensure uniqueness in BTP global account)
55
resource "random_uuid" "uuid" {}
66

7+
locals {
8+
random_uuid = random_uuid.uuid.result
9+
subaccount_domain = "dcmission4441${local.random_uuid}"
10+
}
11+
712
# ------------------------------------------------------------------------------------------------------
813
# Creation of subaccount
914
# ------------------------------------------------------------------------------------------------------
1015
resource "btp_subaccount" "dc_mission" {
16+
count = var.subaccount_id == "" ? 1 : 0
17+
1118
name = var.subaccount_name
12-
subdomain = join("-", ["dc-mission-4441", random_uuid.uuid.result])
13-
region = lower(var.region)
19+
subdomain = local.subaccount_domain
20+
region = var.region
21+
}
22+
23+
data "btp_subaccount" "dc_mission" {
24+
id = var.subaccount_id != "" ? var.subaccount_id : btp_subaccount.dc_mission[0].id
25+
}
26+
27+
data "btp_subaccount" "subaccount" {
28+
id = data.btp_subaccount.dc_mission.id
1429
}
1530

1631
# ------------------------------------------------------------------------------------------------------
@@ -19,41 +34,46 @@ resource "btp_subaccount" "dc_mission" {
1934
resource "btp_subaccount_trust_configuration" "fully_customized" {
2035
# Only create trust configuration if custom_idp has been set
2136
count = var.custom_idp == "" ? 0 : 1
22-
subaccount_id = btp_subaccount.dc_mission.id
37+
subaccount_id = data.btp_subaccount.dc_mission.id
2338
identity_provider = var.custom_idp
2439
}
40+
2541
# ------------------------------------------------------------------------------------------------------
26-
# CLOUDFOUNDRY PREPARATION
42+
# SERVICES
2743
# ------------------------------------------------------------------------------------------------------
2844
#
29-
# Fetch all available environments for the subaccount
30-
data "btp_subaccount_environments" "all" {
31-
subaccount_id = btp_subaccount.dc_mission.id
45+
locals {
46+
service_name__cloudfoundry = "cloudfoundry"
3247
}
48+
3349
# ------------------------------------------------------------------------------------------------------
34-
# Take the landscape label from the first CF environment if no environment label is provided
35-
# (this replaces the previous null_resource)
50+
# Setup cloudfoundry (Cloud Foundry Environment)
3651
# ------------------------------------------------------------------------------------------------------
52+
#
53+
# Fetch all available environments for the subaccount
54+
data "btp_subaccount_environments" "all" {
55+
subaccount_id = data.btp_subaccount.dc_mission.id
56+
}
57+
# Take the landscape label from the first CF environment if no environment label is provided (this replaces the previous null_resource)
3758
resource "terraform_data" "cf_landscape_label" {
3859
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
3960
}
40-
# ------------------------------------------------------------------------------------------------------
41-
# Create the Cloud Foundry environment instance
42-
# ------------------------------------------------------------------------------------------------------
61+
# Entitle
4362
resource "btp_subaccount_entitlement" "cloudfoundry" {
44-
subaccount_id = btp_subaccount.dc_mission.id
45-
service_name = "cloudfoundry"
46-
plan_name = "build-code"
63+
subaccount_id = data.btp_subaccount.dc_mission.id
64+
service_name = local.service_name__cloudfoundry
65+
plan_name = var.service_plan__cloudfoundry
4766
amount = 1
4867
}
4968

69+
# Create instance
5070
resource "btp_subaccount_environment_instance" "cloudfoundry" {
5171
depends_on = [btp_subaccount_entitlement.build_code]
52-
subaccount_id = btp_subaccount.dc_mission.id
72+
subaccount_id = data.btp_subaccount.dc_mission.id
5373
name = "cf-${random_uuid.uuid.result}"
5474
environment_type = "cloudfoundry"
55-
service_name = "cloudfoundry"
56-
plan_name = "build-code"
75+
service_name = local.service_name__cloudfoundry
76+
plan_name = var.service_plan__cloudfoundry
5777
landscape_label = terraform_data.cf_landscape_label.output
5878

5979
parameters = jsonencode({
@@ -65,38 +85,43 @@ resource "btp_subaccount_environment_instance" "cloudfoundry" {
6585
# APP SUBSCRIPTIONS
6686
# ------------------------------------------------------------------------------------------------------
6787
#
88+
locals {
89+
service_name__build_code = "build-code"
90+
service_name__sapappstudio = "sapappstudio"
91+
service_name__sap_launchpad = "SAPLaunchpad"
92+
}
6893
# ------------------------------------------------------------------------------------------------------
69-
# Setup build-code
94+
# Setup build-code (SAP Build Code)
7095
# ------------------------------------------------------------------------------------------------------
7196
# Entitle
7297
resource "btp_subaccount_entitlement" "build_code" {
73-
subaccount_id = btp_subaccount.dc_mission.id
74-
service_name = "build-code"
75-
plan_name = "standard"
98+
subaccount_id = data.btp_subaccount.dc_mission.id
99+
service_name = local.service_name__build_code
100+
plan_name = var.service_plan__build_code
76101
amount = 1
77102
}
78103
# Subscribe
79104
resource "btp_subaccount_subscription" "build_code" {
80-
subaccount_id = btp_subaccount.dc_mission.id
81-
app_name = "build-code"
82-
plan_name = "standard"
105+
subaccount_id = data.btp_subaccount.dc_mission.id
106+
app_name = local.service_name__build_code
107+
plan_name = var.service_plan__build_code
83108
depends_on = [btp_subaccount_entitlement.build_code]
84109
}
85110

86111
# ------------------------------------------------------------------------------------------------------
87-
# Setup sapappstudio
112+
# Setup sapappstudio (SAP Business Application Studio)
88113
# ------------------------------------------------------------------------------------------------------
89114
# Entitle
90115
resource "btp_subaccount_entitlement" "sapappstudio" {
91-
subaccount_id = btp_subaccount.dc_mission.id
92-
service_name = "sapappstudio"
93-
plan_name = "build-code"
116+
subaccount_id = data.btp_subaccount.dc_mission.id
117+
service_name = local.service_name__sapappstudio
118+
plan_name = var.service_plan__sapappstudio
94119
}
95-
# Subscribe (depends on subscription of build-code)
120+
# Subscribe
96121
resource "btp_subaccount_subscription" "sapappstudio" {
97-
subaccount_id = btp_subaccount.dc_mission.id
98-
app_name = "sapappstudio"
99-
plan_name = "build-code"
122+
subaccount_id = data.btp_subaccount.dc_mission.id
123+
app_name = local.service_name__sapappstudio
124+
plan_name = var.service_plan__sapappstudio
100125
depends_on = [btp_subaccount_subscription.build_code, btp_subaccount_entitlement.sapappstudio]
101126
}
102127

@@ -105,33 +130,51 @@ resource "btp_subaccount_subscription" "sapappstudio" {
105130
# ------------------------------------------------------------------------------------------------------
106131
# Entitle
107132
resource "btp_subaccount_entitlement" "sap_launchpad" {
108-
subaccount_id = btp_subaccount.dc_mission.id
109-
service_name = "SAPLaunchpad"
110-
plan_name = "foundation"
133+
subaccount_id = data.btp_subaccount.dc_mission.id
134+
service_name = local.service_name__sap_launchpad
135+
plan_name = var.service_plan__sap_launchpad
111136
}
112137
# Subscribe
113138
resource "btp_subaccount_subscription" "sap_launchpad" {
114-
subaccount_id = btp_subaccount.dc_mission.id
115-
app_name = "SAPLaunchpad"
116-
plan_name = "foundation"
139+
subaccount_id = data.btp_subaccount.dc_mission.id
140+
app_name = local.service_name__sap_launchpad
141+
plan_name = var.service_plan__sap_launchpad
117142
depends_on = [btp_subaccount_entitlement.sap_launchpad]
118143
}
119144

120145
# ------------------------------------------------------------------------------------------------------
121146
# USERS AND ROLES
122147
# ------------------------------------------------------------------------------------------------------
123148
#
124-
# Get all available subaccount roles
149+
locals {
150+
subaccount_admins = var.subaccount_admins
151+
build_code_admins = var.build_code_admins
152+
build_code_developers = var.build_code_developers
153+
}
154+
155+
# Get all roles in the subaccount
125156
data "btp_subaccount_roles" "all" {
126-
subaccount_id = btp_subaccount.dc_mission.id
157+
subaccount_id = data.btp_subaccount.dc_mission.id
127158
depends_on = [btp_subaccount_subscription.build_code, btp_subaccount_subscription.sapappstudio]
128159
}
160+
161+
# ------------------------------------------------------------------------------------------------------
162+
# Assign role collection "Subaccount Administrator"
163+
# ------------------------------------------------------------------------------------------------------
164+
resource "btp_subaccount_role_collection_assignment" "subaccount_admin" {
165+
for_each = toset("${local.subaccount_admins}")
166+
subaccount_id = data.btp_subaccount.dc_mission.id
167+
role_collection_name = "Subaccount Administrator"
168+
user_name = each.value
169+
depends_on = [btp_subaccount.dc_mission]
170+
}
171+
129172
# ------------------------------------------------------------------------------------------------------
130173
# Assign role collection for Build Code Administrator
131174
# ------------------------------------------------------------------------------------------------------
132175
# Assign roles to the role collection "Build Code Administrator"
133176
resource "btp_subaccount_role_collection" "build_code_administrator" {
134-
subaccount_id = btp_subaccount.dc_mission.id
177+
subaccount_id = data.btp_subaccount.dc_mission.id
135178
name = "Build Code Administrator"
136179
description = "The role collection for an administrator on SAP Build Code"
137180

@@ -145,8 +188,8 @@ resource "btp_subaccount_role_collection" "build_code_administrator" {
145188
}
146189
# Assign users to the role collection "Build Code Administrator"
147190
resource "btp_subaccount_role_collection_assignment" "build_code_administrator" {
148-
for_each = toset("${var.build_code_admins}")
149-
subaccount_id = btp_subaccount.dc_mission.id
191+
for_each = toset("${local.build_code_admins}")
192+
subaccount_id = data.btp_subaccount.dc_mission.id
150193
role_collection_name = "Build Code Administrator"
151194
user_name = each.value
152195
depends_on = [btp_subaccount_role_collection.build_code_administrator]
@@ -157,7 +200,7 @@ resource "btp_subaccount_role_collection_assignment" "build_code_administrator"
157200
# ------------------------------------------------------------------------------------------------------
158201
# Create role collection "Build Code Developer"
159202
resource "btp_subaccount_role_collection" "build_code_developer" {
160-
subaccount_id = btp_subaccount.dc_mission.id
203+
subaccount_id = data.btp_subaccount.dc_mission.id
161204
name = "Build Code Developer"
162205
description = "The role collection for a developer on SAP Build Code"
163206

@@ -171,24 +214,13 @@ resource "btp_subaccount_role_collection" "build_code_developer" {
171214
}
172215
# Assign users to the role collection "Build Code Developer"
173216
resource "btp_subaccount_role_collection_assignment" "build_code_developer" {
174-
for_each = toset("${var.build_code_developers}")
175-
subaccount_id = btp_subaccount.dc_mission.id
217+
for_each = toset("${local.build_code_developers}")
218+
subaccount_id = data.btp_subaccount.dc_mission.id
176219
role_collection_name = "Build Code Developer"
177220
user_name = each.value
178221
depends_on = [btp_subaccount_role_collection.build_code_developer]
179222
}
180223

181-
# ------------------------------------------------------------------------------------------------------
182-
# Assign role collection "Subaccount Administrator"
183-
# ------------------------------------------------------------------------------------------------------
184-
resource "btp_subaccount_role_collection_assignment" "subaccount_admin" {
185-
for_each = toset("${var.subaccount_admins}")
186-
subaccount_id = btp_subaccount.dc_mission.id
187-
role_collection_name = "Subaccount Administrator"
188-
user_name = each.value
189-
depends_on = [btp_subaccount.dc_mission]
190-
}
191-
192224
# ------------------------------------------------------------------------------------------------------
193225
# Create tfvars file for step 2 (if variable `create_tfvars_file_for_step2` is set to true)
194226
# ------------------------------------------------------------------------------------------------------
@@ -198,7 +230,7 @@ resource "local_file" "output_vars_step1" {
198230
globalaccount = "${var.globalaccount}"
199231
cli_server_url = ${jsonencode(var.cli_server_url)}
200232
201-
subaccount_id = "${btp_subaccount.dc_mission.id}"
233+
subaccount_id = "${data.btp_subaccount.dc_mission.id}"
202234
203235
cf_api_url = "${jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["API Endpoint"]}"
204236

released/discovery_center/mission_4441/minimal_setup_enterprise/step1/outputs.tf

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/*
12
output "globalaccount" {
23
value = var.globalaccount
34
description = "The Global Account subdomain."
@@ -7,10 +8,21 @@ output "cli_server_url" {
78
value = var.cli_server_url
89
description = "The BTP CLI server URL."
910
}
11+
*/
1012

1113
output "subaccount_id" {
12-
value = btp_subaccount.dc_mission.id
13-
description = "The Global Account subdomain id."
14+
value = data.btp_subaccount.dc_mission.id
15+
description = "The ID of the subaccount."
16+
}
17+
18+
output "build_code_subscription_url" {
19+
value = btp_subaccount_subscription.build_code.subscription_url
20+
description = "SAP Build Code subscription URL."
21+
}
22+
23+
output "custom_idp" {
24+
value = var.custom_idp
25+
description = "The custom identity provider."
1426
}
1527

1628
output "cf_api_url" {
@@ -33,11 +45,6 @@ output "cf_org_name" {
3345
description = "The Cloudfoundry org name."
3446
}
3547

36-
output "custom_idp" {
37-
value = var.custom_idp
38-
description = "The custom identity provider."
39-
}
40-
4148
output "cf_org_admins" {
4249
value = var.cf_org_admins
4350
description = "List of users to set as Cloudfoundry org administrators."
@@ -52,8 +59,3 @@ output "cf_space_managers" {
5259
value = var.cf_space_managers
5360
description = "List of users to set as Cloudfoundry space managers."
5461
}
55-
56-
output "build_code_subscription_url" {
57-
value = btp_subaccount_subscription.build_code.subscription_url
58-
description = "SAP Build Code subscription URL."
59-
}
Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
# ------------------------------------------------------------------------------------------------------
22
# Provider configuration
33
# ------------------------------------------------------------------------------------------------------
4-
# Your global account subdomain
5-
globalaccount = "xxxxxxxx-xxxxxxx-xxxxxxx-xxxxxxxx-xxxxxx"
4+
custom_idp = "<<tenant-id>>.accounts.ondemand.com"
65

7-
# The CLI server URL (needs to be set to null if you are using the default CLI server)
8-
cli_server_url = null
6+
# ------------------------------------------------------------------------------------------------------
7+
# Account settings
8+
# ------------------------------------------------------------------------------------------------------
9+
globalaccount = "<your-global-account-subdomain>"
10+
region = "us10"
911

10-
# Region for your subaccount
11-
region = "us10"
12+
# ------------------------------------------------------------------------------------------------------
13+
# Use case specific configuration
14+
# ------------------------------------------------------------------------------------------------------
15+
subaccount_admins = ["[email protected]"]
16+
build_code_admins = ["[email protected]", "[email protected]"]
17+
build_code_developers = ["[email protected]", "[email protected]"]
1218

13-
# Name of your sub account
14-
subaccount_name = "SAP Discovery Center Mission 4441 (SAP Build Code)"
19+
cf_org_admins = ["[email protected]"]
20+
cf_space_managers = ["[email protected]", "[email protected]"]
21+
cf_space_developers = ["[email protected]", "[email protected]"]
1522

1623
# ------------------------------------------------------------------------------------------------------
1724
# Create tfvars file for the step 2
1825
# ------------------------------------------------------------------------------------------------------
1926
create_tfvars_file_for_step2 = true
20-
21-
# ------------------------------------------------------------------------------------------------------
22-
# USER ROLES
23-
# ------------------------------------------------------------------------------------------------------
24-
subaccount_admins = ["[email protected]"]
25-
cf_org_admins = ["[email protected]"]
26-
cf_space_managers = ["[email protected]", "[email protected]"]
27-
cf_space_developers = ["[email protected]", "[email protected]"]
28-
build_code_admins = ["[email protected]", "[email protected]"]
29-
build_code_developers = ["[email protected]", "[email protected]"]

0 commit comments

Comments
 (0)