Skip to content

Commit b380b00

Browse files
authored
chore: Update for SIT (#333)
* chore: Update for sap inside track * chore: fixes * chore: fixes * chore: fixes
1 parent fc25444 commit b380b00

File tree

4 files changed

+293
-0
lines changed

4 files changed

+293
-0
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
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+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
terraform {
2+
required_providers {
3+
btp = {
4+
source = "sap/btp"
5+
version = "~> 1.5.0"
6+
}
7+
}
8+
}
9+
10+
# Please checkout documentation on how best to authenticate against SAP BTP
11+
# via the Terraform provider for SAP BTP
12+
provider "btp" {
13+
globalaccount = var.globalaccount
14+
username = var.btp_username
15+
password = var.btp_password
16+
idp = var.idp
17+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
########################################################################
2+
# Account settings
3+
########################################################################
4+
globalaccount = "inside-track-2023"
5+
region = "us10"
6+
subaccount_name = "learningjourney"
7+
idp = "<name of the custom identity provider>"
8+
9+
10+
# Set the subaccount_id ro run the script in an existing subaccount,
11+
# keep it empty to create a new one, for that you need the global account administration role
12+
# subaccount_id = ""
13+
14+
#####################################################################################
15+
# Subaccount administrators - don't add your own user here, your ID is added automatically
16+
#####################################################################################
17+
subaccount_admins = ["[email protected]", "[email protected]"]
18+
19+
20+
#####################################################################################
21+
# Service administrators and developers - add your ID here
22+
#####################################################################################
23+
service_admins = ["[email protected]", "[email protected]"]
24+
developers = ["[email protected]"]
25+
26+
#####################################################################################
27+
# Service plans - for testing the services you can set "free" as value, the free service plan
28+
# is only supported for SAP BTP accounts with the CPEA, BTPEA or Pay-as-you-go commercial model
29+
#####################################################################################
30+
build_workzone_service_plan = "free"
31+
bas_service_plan = "free"
32+
cicd_service_plan = "default"
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
variable "globalaccount" {
2+
type = string
3+
description = "The globalaccount subdomain where the sub account shall be created."
4+
}
5+
variable "idp" {
6+
type = string
7+
description = "The custom identity provider for the subaccount."
8+
default = "aviss4yru.accounts.ondemand.com"
9+
}
10+
11+
variable "subaccount_name" {
12+
type = string
13+
description = "The subaccount name."
14+
default = "My SAP subaccount"
15+
}
16+
17+
variable "subaccount_id" {
18+
type = string
19+
description = "The subaccount ID."
20+
default = ""
21+
}
22+
variable "region" {
23+
type = string
24+
description = "The region where the subaccount shall be created in."
25+
default = "us10"
26+
}
27+
28+
variable "build_workzone_service_plan" {
29+
type = string
30+
description = "The plan for the SAP Build Workzone subscription"
31+
default = "free"
32+
validation {
33+
condition = contains(["free", "standard"], var.build_workzone_service_plan)
34+
error_message = "Invalid value for build_workzone_service_plan. Only 'free' and 'standard' are allowed."
35+
}
36+
}
37+
38+
variable "bas_service_plan" {
39+
type = string
40+
description = "The plan for SAP Business Application Studio subscription"
41+
default = "free"
42+
validation {
43+
condition = contains(["free", "standard-edition"], var.bas_service_plan)
44+
error_message = "Invalid value for SAP Business Application Studion. Only 'free' and 'standard-edition' are allowed."
45+
}
46+
}
47+
48+
variable "cicd_service_plan" {
49+
type = string
50+
description = "The plan for Continous Integraion & Delivery subscription"
51+
default = "free"
52+
validation {
53+
condition = contains(["free", "default"], var.cicd_service_plan)
54+
error_message = "Invalid value for Continous Integraion & Delivery. Only 'free' and 'default' are allowed."
55+
}
56+
}
57+
58+
variable "subaccount_admins" {
59+
type = list(string)
60+
description = "Defines the colleagues who are added to each subaccount as emergency administrators."
61+
}
62+
variable "service_admins" {
63+
type = list(string)
64+
description = "Defines the users who are added to each subaccount as service administrators."
65+
}
66+
variable "developers" {
67+
type = list(string)
68+
description = "Defines the colleagues who are added to services as developers."
69+
}
70+
71+
variable "btp_username" {
72+
type = string
73+
description = "SAP BTP user name"
74+
## set default value to "" when using environment values for user and password
75+
# default = ""
76+
}
77+
78+
79+
variable "btp_password" {
80+
type = string
81+
description = "Password for SAP BTP user"
82+
sensitive = true
83+
## set default value to "" when using environment values for user and password
84+
# default = ""
85+
}

0 commit comments

Comments
 (0)