1
1
# ------------------------------------------------------------------------------------------------------
2
- # SUBACCOUNT SETUP
2
+ # Subaccount setup for DC mission 4441
3
3
# ------------------------------------------------------------------------------------------------------
4
4
# Setup subaccount domain (to ensure uniqueness in BTP global account)
5
5
resource "random_uuid" "uuid" {}
6
6
7
+ locals {
8
+ random_uuid = random_uuid. uuid . result
9
+ subaccount_domain = " dcmission4441${ local . random_uuid } "
10
+ }
11
+
7
12
# ------------------------------------------------------------------------------------------------------
8
13
# Creation of subaccount
9
14
# ------------------------------------------------------------------------------------------------------
10
15
resource "btp_subaccount" "dc_mission" {
16
+ count = var. subaccount_id == " " ? 1 : 0
17
+
11
18
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
14
29
}
15
30
16
31
# ------------------------------------------------------------------------------------------------------
@@ -19,41 +34,46 @@ resource "btp_subaccount" "dc_mission" {
19
34
resource "btp_subaccount_trust_configuration" "fully_customized" {
20
35
# Only create trust configuration if custom_idp has been set
21
36
count = var. custom_idp == " " ? 0 : 1
22
- subaccount_id = btp_subaccount. dc_mission . id
37
+ subaccount_id = data . btp_subaccount . dc_mission . id
23
38
identity_provider = var. custom_idp
24
39
}
40
+
25
41
# ------------------------------------------------------------------------------------------------------
26
- # CLOUDFOUNDRY PREPARATION
42
+ # SERVICES
27
43
# ------------------------------------------------------------------------------------------------------
28
44
#
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"
32
47
}
48
+
33
49
# ------------------------------------------------------------------------------------------------------
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)
36
51
# ------------------------------------------------------------------------------------------------------
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)
37
58
resource "terraform_data" "cf_landscape_label" {
38
59
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
39
60
}
40
- # ------------------------------------------------------------------------------------------------------
41
- # Create the Cloud Foundry environment instance
42
- # ------------------------------------------------------------------------------------------------------
61
+ # Entitle
43
62
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
47
66
amount = 1
48
67
}
49
68
69
+ # Create instance
50
70
resource "btp_subaccount_environment_instance" "cloudfoundry" {
51
71
depends_on = [btp_subaccount_entitlement . build_code ]
52
- subaccount_id = btp_subaccount. dc_mission . id
72
+ subaccount_id = data . btp_subaccount . dc_mission . id
53
73
name = " cf-${ random_uuid . uuid . result } "
54
74
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
57
77
landscape_label = terraform_data. cf_landscape_label . output
58
78
59
79
parameters = jsonencode ({
@@ -65,38 +85,43 @@ resource "btp_subaccount_environment_instance" "cloudfoundry" {
65
85
# APP SUBSCRIPTIONS
66
86
# ------------------------------------------------------------------------------------------------------
67
87
#
88
+ locals {
89
+ service_name__build_code = " build-code"
90
+ service_name__sapappstudio = " sapappstudio"
91
+ service_name__sap_launchpad = " SAPLaunchpad"
92
+ }
68
93
# ------------------------------------------------------------------------------------------------------
69
- # Setup build-code
94
+ # Setup build-code (SAP Build Code)
70
95
# ------------------------------------------------------------------------------------------------------
71
96
# Entitle
72
97
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
76
101
amount = 1
77
102
}
78
103
# Subscribe
79
104
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
83
108
depends_on = [btp_subaccount_entitlement . build_code ]
84
109
}
85
110
86
111
# ------------------------------------------------------------------------------------------------------
87
- # Setup sapappstudio
112
+ # Setup sapappstudio (SAP Business Application Studio)
88
113
# ------------------------------------------------------------------------------------------------------
89
114
# Entitle
90
115
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
94
119
}
95
- # Subscribe (depends on subscription of build-code)
120
+ # Subscribe
96
121
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
100
125
depends_on = [btp_subaccount_subscription . build_code , btp_subaccount_entitlement . sapappstudio ]
101
126
}
102
127
@@ -105,33 +130,51 @@ resource "btp_subaccount_subscription" "sapappstudio" {
105
130
# ------------------------------------------------------------------------------------------------------
106
131
# Entitle
107
132
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
111
136
}
112
137
# Subscribe
113
138
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
117
142
depends_on = [btp_subaccount_entitlement . sap_launchpad ]
118
143
}
119
144
120
145
# ------------------------------------------------------------------------------------------------------
121
146
# USERS AND ROLES
122
147
# ------------------------------------------------------------------------------------------------------
123
148
#
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
125
156
data "btp_subaccount_roles" "all" {
126
- subaccount_id = btp_subaccount. dc_mission . id
157
+ subaccount_id = data . btp_subaccount . dc_mission . id
127
158
depends_on = [btp_subaccount_subscription . build_code , btp_subaccount_subscription . sapappstudio ]
128
159
}
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
+
129
172
# ------------------------------------------------------------------------------------------------------
130
173
# Assign role collection for Build Code Administrator
131
174
# ------------------------------------------------------------------------------------------------------
132
175
# Assign roles to the role collection "Build Code Administrator"
133
176
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
135
178
name = " Build Code Administrator"
136
179
description = " The role collection for an administrator on SAP Build Code"
137
180
@@ -145,8 +188,8 @@ resource "btp_subaccount_role_collection" "build_code_administrator" {
145
188
}
146
189
# Assign users to the role collection "Build Code Administrator"
147
190
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
150
193
role_collection_name = " Build Code Administrator"
151
194
user_name = each. value
152
195
depends_on = [btp_subaccount_role_collection . build_code_administrator ]
@@ -157,7 +200,7 @@ resource "btp_subaccount_role_collection_assignment" "build_code_administrator"
157
200
# ------------------------------------------------------------------------------------------------------
158
201
# Create role collection "Build Code Developer"
159
202
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
161
204
name = " Build Code Developer"
162
205
description = " The role collection for a developer on SAP Build Code"
163
206
@@ -171,24 +214,13 @@ resource "btp_subaccount_role_collection" "build_code_developer" {
171
214
}
172
215
# Assign users to the role collection "Build Code Developer"
173
216
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
176
219
role_collection_name = " Build Code Developer"
177
220
user_name = each. value
178
221
depends_on = [btp_subaccount_role_collection . build_code_developer ]
179
222
}
180
223
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
-
192
224
# ------------------------------------------------------------------------------------------------------
193
225
# Create tfvars file for step 2 (if variable `create_tfvars_file_for_step2` is set to true)
194
226
# ------------------------------------------------------------------------------------------------------
@@ -198,7 +230,7 @@ resource "local_file" "output_vars_step1" {
198
230
globalaccount = "${ var . globalaccount } "
199
231
cli_server_url = ${ jsonencode (var. cli_server_url )}
200
232
201
- subaccount_id = "${ btp_subaccount . dc_mission . id } "
233
+ subaccount_id = "${ data . btp_subaccount . dc_mission . id } "
202
234
203
235
cf_api_url = "${ jsondecode (btp_subaccount_environment_instance. cloudfoundry . labels )[" API Endpoint" ]} "
204
236
0 commit comments