Skip to content

Commit c89f480

Browse files
authored
Exercise for Learning Journey BTP200 (#262)
1 parent 8ccab27 commit c89f480

File tree

6 files changed

+352
-4
lines changed

6 files changed

+352
-4
lines changed

released/discovery_center/mission_3239/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ To deploy the resources you must:
2727
1. Create a file `secret.auto.tfvars` and maintain the credentials for the BTP provider
2828

2929
```hcl
30-
user_email = "<Email address of your BTP user>"
31-
password = "<Password of your BTP user>"
30+
btp_username = "<Email address of your BTP user>"
31+
btp_password = "<Password of your BTP user>"
3232
```
3333
as an alternative you can set this credentials also as environment variables
3434

3535
```bash
36-
export user_email ='<Email address of your BTP user>'
37-
export password ='<Password of your BTP user>'
36+
export btp_username ='<Email address of your BTP user>'
37+
export btp_password ='<Password of your BTP user>'
3838
```
3939

4040
3. Change the variables in the `sample.tfvars` file to meet your requirements
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Learning Journey BTP200
2+
## Overview
3+
4+
This folder contains the files for the Terraform exercise of the SAP Learing Journey BTP200
5+
6+
## Content of setup
7+
8+
The setup comprises the following resources:
9+
10+
- Creation of an SAP BTP subaccount or using an existing subaccount
11+
- Entitlements of services
12+
* SAP Business Application Studio
13+
* SAP Build Work Zone, standard edition
14+
* Continous Integration & Delivery - optional
15+
16+
- Subscriptions of the services
17+
- Role collection assignments to users
18+
19+
## Deploying the resources
20+
21+
Make sure that you are familiar with SAP BTP and know both the [Get Started with btp-terraform-samples](https://github.com/SAP-samples/btp-terraform-samples/blob/main/GET_STARTED.md) and the [Get Started with the Terraform Provider for BTP](https://developers.sap.com/tutorials/btp-terraform-get-started.html)
22+
23+
To deploy the resources you must:
24+
25+
1. Create a file `secret.auto.tfvars` and maintain the credentials for the BTP provider
26+
27+
```hcl
28+
btp_username = "<Email address of your BTP user>"
29+
btp_password = "<Password of your BTP user>"
30+
```
31+
As an alternative you can set this credentials also as environment variables. Then you have to set the default values to "" for these variables in variables.tf.git
32+
33+
```bash
34+
export btp_username ='<Email address of your BTP user>'
35+
export btp_password ='<Password of your BTP user>'
36+
```
37+
38+
3. Change the variables in the `terraform.tfvars` file to meet your requirements
39+
> The minimal set of parameters you should specify (beside btp_user and btp_password) is globalaccount (i.e. its subdomain - you find it in the SAP BTP cockpit in the Account Explorer). If you don't have the global account administrator privileg, you need to have access to a subaccount with the subaccount administrator privileg. In that case you need to set the subaccount_id (You can find it in the SAP BTP cockpit on the subaccount overview page).
40+
41+
42+
43+
4. Initialize your workspace:
44+
45+
```bash
46+
terraform init
47+
```
48+
49+
5. You can check what Terraform plans to apply based on your configuration:
50+
51+
```bash
52+
terraform plan
53+
```
54+
55+
6. Apply your configuration to provision the resources:
56+
57+
```bash
58+
terraform apply
59+
```
60+
7. Remove the changes you have done with this script
61+
62+
```bash
63+
terraform destroy
64+
```
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
2+
3+
###############################################################################################
4+
# This is the Terraform script for the BTP_200 Learning Journey. 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+
}
70+
71+
# Entitle subaccount for usage of app destination SAP Business Application Studio
72+
resource "btp_subaccount_entitlement" "bas" {
73+
subaccount_id = data.btp_subaccount.project.id
74+
service_name = "sapappstudio"
75+
plan_name = var.bas_service_plan
76+
}
77+
# Entitle subaccount for usage of app destination Continous Integration & Delivery
78+
resource "btp_subaccount_entitlement" "cicd" {
79+
subaccount_id = data.btp_subaccount.project.id
80+
service_name = "cicd-app"
81+
plan_name = var.cicd_service_plan
82+
}
83+
84+
##############################################################################################
85+
# Creating subscriptions
86+
##############################################################################################
87+
# Create app subscription to SAP Build Workzone, standard edition (depends on entitlement)
88+
resource "btp_subaccount_subscription" "build_workzone" {
89+
subaccount_id = data.btp_subaccount.project.id
90+
app_name = "SAPLaunchpad"
91+
plan_name = var.build_workzone_service_plan
92+
depends_on = [btp_subaccount_entitlement.build_workzone]
93+
}
94+
95+
# Create app subscription to SAP Business Application Studio (depends on entitlement)
96+
resource "btp_subaccount_subscription" "bas" {
97+
subaccount_id = data.btp_subaccount.project.id
98+
app_name = "sapappstudio"
99+
plan_name = var.bas_service_plan
100+
depends_on = [btp_subaccount_entitlement.bas]
101+
}
102+
# Create app subscription to SAP Business Application Studio (depends on entitlement)
103+
resource "btp_subaccount_subscription" "cicd" {
104+
subaccount_id = data.btp_subaccount.project.id
105+
app_name = "cicd-app"
106+
plan_name = var.cicd_service_plan
107+
depends_on = [btp_subaccount_entitlement.cicd]
108+
}
109+
110+
###############################################################################################
111+
# Assign User to role collections
112+
###############################################################################################
113+
114+
115+
# Assign users to Role Collection: Launchpad_Admin
116+
resource "btp_subaccount_role_collection_assignment" "launchpad_admin" {
117+
for_each = toset("${var.service_admins}")
118+
subaccount_id = data.btp_subaccount.project.id
119+
role_collection_name = "Launchpad_Admin"
120+
user_name = each.value
121+
depends_on = [btp_subaccount_subscription.build_workzone]
122+
}
123+
124+
# Assign users to Role Collection: Business_Application_Studio_Administrator
125+
resource "btp_subaccount_role_collection_assignment" "bas_admin" {
126+
for_each = toset("${var.service_admins}")
127+
subaccount_id = data.btp_subaccount.project.id
128+
role_collection_name = "Business_Application_Studio_Administrator"
129+
user_name = each.value
130+
depends_on = [btp_subaccount_subscription.bas]
131+
}
132+
133+
# Assign users to Role Collection: Business_Application_Studio_Developer
134+
resource "btp_subaccount_role_collection_assignment" "bas_dev" {
135+
for_each = toset("${var.developers}")
136+
subaccount_id = data.btp_subaccount.project.id
137+
role_collection_name = "Business_Application_Studio_Developer"
138+
user_name = each.value
139+
depends_on = [btp_subaccount_subscription.bas]
140+
}
141+
142+
# Assign users to Role Collection: CICD Service Administrator
143+
resource "btp_subaccount_role_collection_assignment" "cicd_admin" {
144+
for_each = toset("${var.service_admins}")
145+
subaccount_id = data.btp_subaccount.project.id
146+
role_collection_name = "CICD Service Administrator"
147+
user_name = each.value
148+
depends_on = [btp_subaccount_subscription.cicd]
149+
}
150+
151+
# Assign users to Role Collection: CICD Service Developer
152+
resource "btp_subaccount_role_collection_assignment" "cicd_dev" {
153+
for_each = toset("${var.developers}")
154+
subaccount_id = data.btp_subaccount.project.id
155+
role_collection_name = "CICD Service Developer"
156+
user_name = each.value
157+
depends_on = [btp_subaccount_subscription.cicd]
158+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
terraform {
2+
required_providers {
3+
btp = {
4+
source = "sap/btp"
5+
version = "~> 1.4.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+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
########################################################################
2+
# Account settings
3+
########################################################################
4+
globalaccount = "<your global account id>"
5+
region = "us10"
6+
subaccount_name = "learningjourney"
7+
8+
# Set the subaccount_id ro run the script in an existing subaccount,
9+
# keep it empty to create a new one, for that you need the global account administration role
10+
subaccount_id = ""
11+
12+
#####################################################################################
13+
# Subaccount administrators - don't add your own user here, your ID is added automatically
14+
#####################################################################################
15+
subaccount_admins = ["[email protected]", "[email protected]"]
16+
17+
18+
#####################################################################################
19+
# Service administrators and developers - add your ID here
20+
#####################################################################################
21+
service_admins = ["[email protected]", "[email protected]"]
22+
developers = ["[email protected]"]
23+
24+
#####################################################################################
25+
# Service plans - for testing the services you can set "free" as value, the free service plan
26+
# is only supported for SAP BTP accounts with the CPEA, BTPEA or Pay-as-you-go commercial model
27+
#####################################################################################
28+
build_workzone_service_plan = "standard"
29+
bas_service_plan = "standard-edition"
30+
cicd_service_plan = "default"
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
variable "globalaccount" {
2+
type = string
3+
description = "The globalaccount subdomain where the sub account shall be created."
4+
}
5+
6+
variable "subaccount_name" {
7+
type = string
8+
description = "The subaccount name."
9+
default = "My SAP subaccount"
10+
}
11+
12+
variable "subaccount_id" {
13+
type = string
14+
description = "The subaccount ID."
15+
default = ""
16+
}
17+
variable "region" {
18+
type = string
19+
description = "The region where the subaccount shall be created in."
20+
default = "us10"
21+
}
22+
23+
variable "build_workzone_service_plan" {
24+
type = string
25+
description = "The plan for the SAP Build Workzone subscription"
26+
default = "free"
27+
validation {
28+
condition = contains(["free", "standard"], var.build_workzone_service_plan)
29+
error_message = "Invalid value for build_workzone_service_plan. Only 'free' and 'standard' are allowed."
30+
}
31+
}
32+
33+
variable "bas_service_plan" {
34+
type = string
35+
description = "The plan for SAP Business Application Studio subscription"
36+
default = "free"
37+
validation {
38+
condition = contains(["free", "standard-edition"], var.bas_service_plan)
39+
error_message = "Invalid value for SAP Business Application Studion. Only 'free' and 'standard-edition' are allowed."
40+
}
41+
}
42+
43+
variable "cicd_service_plan" {
44+
type = string
45+
description = "The plan for Continous Integraion & Delivery subscription"
46+
default = "free"
47+
validation {
48+
condition = contains(["free", "default"], var.cicd_service_plan)
49+
error_message = "Invalid value for Continous Integraion & Delivery. Only 'free' and 'default' are allowed."
50+
}
51+
}
52+
53+
variable "subaccount_admins" {
54+
type = list(string)
55+
description = "Defines the colleagues who are added to each subaccount as emergency administrators."
56+
}
57+
variable "service_admins" {
58+
type = list(string)
59+
description = "Defines the users who are added to each subaccount as service administrators."
60+
}
61+
variable "developers" {
62+
type = list(string)
63+
description = "Defines the colleagues who are added to services as developers."
64+
}
65+
66+
variable "btp_username" {
67+
type = string
68+
description = "SAP BTP user name"
69+
## set default value to "" when using environment values for user and password
70+
# default = ""
71+
}
72+
73+
74+
variable "btp_password" {
75+
type = string
76+
description = "Password for SAP BTP user"
77+
sensitive = true
78+
## set default value to "" when using environment values for user and password
79+
# default = ""
80+
}

0 commit comments

Comments
 (0)