1
+
2
+
3
+ # ##############################################################################################
4
+ # This is the Terraform script for the SAP Insidetrack event. In this script you will create
5
+ # the infrastructure for the development of an SAP extension project
6
+ # The script will do the following
7
+ # - create a new subaccount (if the subaccount id is not set)
8
+ # - add users as subaccount administrators and viewers
9
+ # - create entitlements for the following services:
10
+ # * SAP Business Application Studio
11
+ # * SAP Continous & Integration Application
12
+ # * SAP Build Workzone - standard edition
13
+ # - create subscriptions
14
+ # - add user to service role collections
15
+ # ##############################################################################################
16
+
17
+ # ##############################################################################################
18
+ # Creation of subaccount - if subaccount_id = ""
19
+ # ##############################################################################################
20
+ # Setup subaccount domain (to ensure uniqueness in BTP global account)
21
+ resource "random_uuid" "uuid" {}
22
+
23
+ resource "btp_subaccount" "create_subaccount" {
24
+ count = var. subaccount_id == " " ? 1 : 0
25
+ name = var. subaccount_name
26
+ subdomain = join (" -" , [var . subaccount_name , random_uuid . uuid . result ])
27
+ region = lower (var. region )
28
+ }
29
+
30
+ # For the next resources we need the subaccount ID – either use the new one or one from the subaccount_id variable
31
+ data "btp_subaccount" "project" {
32
+ id = var. subaccount_id != " " ? var. subaccount_id : btp_subaccount. create_subaccount [0 ]. id
33
+ }
34
+
35
+ # #############################################################################################
36
+ # Assign users to the subaccount role collections
37
+ # #############################################################################################
38
+ # Assignment of admins to the sub account as sub account administrators
39
+ resource "btp_subaccount_role_collection_assignment" "subaccount_admins" {
40
+ for_each = toset (" ${ var . subaccount_admins } " )
41
+ subaccount_id = data. btp_subaccount . project . id
42
+ role_collection_name = " Subaccount Administrator"
43
+ user_name = each. value
44
+ }
45
+
46
+ # Assignment of developers to the sub account as sub account viewer
47
+ resource "btp_subaccount_role_collection_assignment" "subaccount_viewer" {
48
+ for_each = toset (" ${ var . developers } " )
49
+ subaccount_id = data. btp_subaccount . project . id
50
+ role_collection_name = " Subaccount Viewer"
51
+ user_name = each. value
52
+ }
53
+ # Assignment of the subaccount service administrators
54
+ resource "btp_subaccount_role_collection_assignment" "subaccount_service_admin" {
55
+ for_each = toset (" ${ var . service_admins } " )
56
+ subaccount_id = data. btp_subaccount . project . id
57
+ role_collection_name = " Subaccount Service Administrator"
58
+ user_name = each. value
59
+ }
60
+
61
+ # #############################################################################################
62
+ # Creating entitlements
63
+ # #############################################################################################
64
+ # Entitle subaccount for usage of app destination SAP Build Workzone, standard edition
65
+ resource "btp_subaccount_entitlement" "build_workzone" {
66
+ subaccount_id = data. btp_subaccount . project . id
67
+ service_name = " SAPLaunchpad"
68
+ plan_name = var. build_workzone_service_plan
69
+ amount = 1
70
+ }
71
+
72
+ # Entitle subaccount for usage of app destination SAP Business Application Studio
73
+ resource "btp_subaccount_entitlement" "bas" {
74
+ subaccount_id = data. btp_subaccount . project . id
75
+ service_name = " sapappstudio"
76
+ plan_name = var. bas_service_plan
77
+ }
78
+ # Entitle subaccount for usage of app destination Continous Integration & Delivery
79
+ resource "btp_subaccount_entitlement" "cicd" {
80
+ subaccount_id = data. btp_subaccount . project . id
81
+ service_name = " cicd-app"
82
+ plan_name = var. cicd_service_plan
83
+ }
84
+
85
+ # #############################################################################################
86
+ # Creating subscriptions
87
+ # #############################################################################################
88
+ # Create app subscription to SAP Build Workzone, standard edition (depends on entitlement)
89
+ resource "btp_subaccount_subscription" "build_workzone" {
90
+ subaccount_id = data. btp_subaccount . project . id
91
+ app_name = " SAPLaunchpad"
92
+ plan_name = var. build_workzone_service_plan
93
+ depends_on = [btp_subaccount_entitlement . build_workzone ]
94
+ }
95
+
96
+ # Create app subscription to SAP Business Application Studio (depends on entitlement)
97
+ resource "btp_subaccount_subscription" "bas" {
98
+ subaccount_id = data. btp_subaccount . project . id
99
+ app_name = " sapappstudio"
100
+ plan_name = var. bas_service_plan
101
+ depends_on = [btp_subaccount_entitlement . bas ]
102
+ }
103
+ # Create app subscription to SAP Business Application Studio (depends on entitlement)
104
+ resource "btp_subaccount_subscription" "cicd" {
105
+ subaccount_id = data. btp_subaccount . project . id
106
+ app_name = " cicd-app"
107
+ plan_name = var. cicd_service_plan
108
+ depends_on = [btp_subaccount_entitlement . cicd ]
109
+ }
110
+
111
+ # ##############################################################################################
112
+ # Assign User to role collections
113
+ # ##############################################################################################
114
+
115
+
116
+ # Assign users to Role Collection: Launchpad_Admin
117
+ resource "btp_subaccount_role_collection_assignment" "launchpad_admin" {
118
+ for_each = toset (" ${ var . service_admins } " )
119
+ subaccount_id = data. btp_subaccount . project . id
120
+ role_collection_name = " Launchpad_Admin"
121
+ user_name = each. value
122
+ depends_on = [btp_subaccount_subscription . build_workzone ]
123
+ }
124
+
125
+ # Assign users to Role Collection: Business_Application_Studio_Administrator
126
+ resource "btp_subaccount_role_collection_assignment" "bas_admin" {
127
+ for_each = toset (" ${ var . service_admins } " )
128
+ subaccount_id = data. btp_subaccount . project . id
129
+ role_collection_name = " Business_Application_Studio_Administrator"
130
+ user_name = each. value
131
+ depends_on = [btp_subaccount_subscription . bas ]
132
+ }
133
+
134
+ # Assign users to Role Collection: Business_Application_Studio_Developer
135
+ resource "btp_subaccount_role_collection_assignment" "bas_dev" {
136
+ for_each = toset (" ${ var . developers } " )
137
+ subaccount_id = data. btp_subaccount . project . id
138
+ role_collection_name = " Business_Application_Studio_Developer"
139
+ user_name = each. value
140
+ depends_on = [btp_subaccount_subscription . bas ]
141
+ }
142
+
143
+ # Assign users to Role Collection: CICD Service Administrator
144
+ resource "btp_subaccount_role_collection_assignment" "cicd_admin" {
145
+ for_each = toset (" ${ var . service_admins } " )
146
+ subaccount_id = data. btp_subaccount . project . id
147
+ role_collection_name = " CICD Service Administrator"
148
+ user_name = each. value
149
+ depends_on = [btp_subaccount_subscription . cicd ]
150
+ }
151
+
152
+ # Assign users to Role Collection: CICD Service Developer
153
+ resource "btp_subaccount_role_collection_assignment" "cicd_dev" {
154
+ for_each = toset (" ${ var . developers } " )
155
+ subaccount_id = data. btp_subaccount . project . id
156
+ role_collection_name = " CICD Service Developer"
157
+ user_name = each. value
158
+ depends_on = [btp_subaccount_subscription . cicd ]
159
+ }
0 commit comments