Skip to content

Commit b4d25fb

Browse files
committed
chore: update for SIT
1 parent 4387eb6 commit b4d25fb

36 files changed

+487
-813
lines changed

released/SAP-Inside-Tracks/SITBLR_DEC_2024/exercises/EXERCISE3/README.md

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
1-
# Exercise 4 - Assign entitlements to a subaccount
1+
# Exercise 3 - Assign entitlement,Subscription and its role assignments to a subaccount
22

33
## Goal of this Exercise 🎯
44

5-
In this exercise, you will learn how to assign entitlements to a subaccount using Terraform. In addition, you will learn how to work with complex variables.
5+
In this exercise, you will learn how add an entitlement to a subaccount using Terraform.
66

7-
## Entitle the subaccount
7+
## Entitle the subaccount with Business Application Stuido (BAS)
88

9-
## Step 1: Enhance the variables
9+
## Step 1: Configure BAS
10+
11+
Our goal is to configure Business Application Studio (BAS) for the subaccount by defining the necessary resources for entitlement, subscription, and role assignments.
12+
13+
We will define the variables in the `variable.tf` file. Open the `variable.tf` file and add the following code.
1014

11-
Our goal is to have one variable that contains the list of entitlements that we want to assign to the subaccount. An entitlement is an object that consists of several attributes, such as the service name, the plan name, and if necessary the amount.
12-
We will define the variable `entitlements` in the `variables.tf` file. Open the `variables.tf` file and add the following code:
1315

1416
```terraform
15-
variable "entitlements" {
16-
type = list(object({
17-
name = string
18-
plan = string
19-
amount = number
20-
}))
21-
description = "List of entitlements for the subaccount."
22-
default = []
17+
variable "bas_admins" {
18+
type = list(string)
19+
description = "List of users to assign the Administrator role."
20+
21+
}
22+
variable "bas_developers" {
23+
type = list(string)
24+
description = "List of users to assign the Developer role."
25+
}
26+
variable "bas_plan" {
27+
type = string
28+
description = "Plan name for Business Application Studio."
29+
default = "standard"
2330
}
2431
```
2532

@@ -32,45 +39,53 @@ Now we need to specify the entitlements we want to create to the `terraform.tfva
3239
We want to add the following entitlements to the subaccount:
3340

3441
- `sapappstudiotrial` application with the `trial` plan
35-
- `cf_application_runtime` runtime with memory`1 GB`
3642

3743
Open the `terraform.tfvars` file and add the following code:
3844

3945
```terraform
40-
entitlements = [
41-
{
42-
name = "sapappstudiotrial"
43-
plan = "trial"
44-
amount = null
45-
},
46-
{
47-
name = "application_runtime"
48-
plan = "memory"
49-
amount = "null"
50-
}
51-
]
52-
```
46+
bas_plan = "trial"
5347
54-
As you can see, we define a list of objects, where each object has the attributes `name`, `plan`, and `amount`. We set the `amount` attribute to `null` for all entitlements. Save the changes.
48+
49+
bas_developers = ["[email protected]", "[email protected]"]
50+
```
5551

5652
## Step 3: Add the entitlements configuration
5753

58-
As we have the variable and the values for the entitlements in place, we can now add the configuration to assign the entitlements to the subaccount. We use the resource [btp_subaccount_entitlement](https://registry.terraform.io/providers/SAP/btp/latest/docs/resources/subaccount_entitlement) to achieve this. Open the `main.tf` file and add the following code:
54+
As we have the variable and the values for the `BAS` in place, we can now add the configuration to assign the entitlement to the subaccount. We use the resource [btp_subaccount_entitlement](https://registry.terraform.io/providers/SAP/btp/latest/docs/resources/subaccount_entitlement) to achieve this. Open the `main.tf` file and add the following code:
5955

6056
```terraform
61-
resource "btp_subaccount_entitlement" "entitlements" {
62-
for_each = {
63-
for index, entitlement in var.entitlements :
64-
index => entitlement
65-
}
57+
resource "btp_subaccount_entitlement" "bas" {
58+
subaccount_id = btp_subaccount.project.id
59+
service_name = "sapappstudio"
60+
plan_name = var.bas_plan
61+
amount = 1
62+
}
6663
64+
resource "btp_subaccount_subscription" "bas" {
6765
subaccount_id = btp_subaccount.project.id
68-
service_name = each.value.name
69-
plan_name = each.value.plan
66+
app_name = "sapappstudio"
67+
plan_name = var.bas_plan
68+
depends_on = [btp_subaccount_entitlement.bas]
69+
}
70+
71+
resource "btp_subaccount_role_collection_assignment" "bas_admin" {
72+
for_each = toset(var.bas_admins)
73+
subaccount_id = btp_subaccount.project.id
74+
role_collection_name = "Business_Application_Studio_Administrator"
75+
user_name = each.value
76+
depends_on = [btp_subaccount_subscription.bas]
77+
}
78+
79+
resource "btp_subaccount_role_collection_assignment" "bas_developer" {
80+
for_each = toset(var.bas_developers)
81+
subaccount_id = btp_subaccount.project.id
82+
role_collection_name = "Business_Application_Studio_Developer"
83+
user_name = each.value
84+
depends_on = [btp_subaccount_subscription.bas]
7085
}
7186
```
7287

73-
We iterate through the list of entitlements and create a resource for each entitlement. We use the[`for_each` meta-argument](https://developer.hashicorp.com/terraform/language/meta-arguments/for_each) to achieve this. The `for_each` argument works on a map, so we must transform our list of entitlements into a map leveraging Terraform's automatic type conversion via the [`for` expression](https://developer.hashicorp.com/terraform/language/expressions/for#result-types) for setting up the map. As for the subaccount administrators we access the value of the current iteration via `each.value` and reference the corresponding attributes of the object. The `subaccount_id` is set to the id of the subaccount we created in the previous exercise. Save the changes.
88+
We iterate through the list of entitlement and create a resource for `BAS`. We use the[`for_each` meta-argument](https://developer.hashicorp.com/terraform/language/meta-arguments/for_each) to achieve this. The `for_each` argument works on a map, so we must transform our list of users into a map leveraging Terraform's automatic type conversion via the [`for` expression](https://developer.hashicorp.com/terraform/language/expressions/for#result-types) for setting up the map. As for the subaccount administrators we access the value of the current iteration via `each.value` and reference the corresponding attributes of the object. The `subaccount_id` is set to the id of the subaccount we created in the previous exercise. Save the changes.
7489

7590
## Step 4: Apply the changes
7691

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,6 @@
11
globalaccount = "<YOUR GLOBAL ACCOUT SUBDOMAIN>"
22

3-
entitlements = [
4-
{
5-
name = "alert-notification"
6-
plan = "standard"
7-
amount = null
8-
},
9-
{
10-
name = "SAPLaunchpad"
11-
plan = "standard"
12-
amount = null
13-
},
14-
{
15-
name = "hana-cloud-trial"
16-
plan = "hana"
17-
amount = null
18-
},
19-
{
20-
name = "hana"
21-
plan = "hdi-shared"
22-
amount = null
23-
},
24-
{
25-
name = "sapappstudiotrial"
26-
plan = "trial"
27-
amount = null
28-
}
29-
]
3+
bas_plan = "trial"
4+
5+
6+
bas_developers = ["[email protected]", "[email protected]"]

released/SAP-Inside-Tracks/SITBLR_DEC_2024/exercises/EXERCISE3/SOLUTION_EX3/variables.tf

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,19 @@ variable "emergency_admins" {
7777

7878

7979
###
80-
# Entitlements for Subaccount
80+
# Entitlement for BAS
8181
###
82-
variable "entitlements" {
83-
type = list(object({
84-
name = string
85-
plan = string
86-
amount = number
87-
}))
88-
description = "List of entitlements for the subaccount."
89-
default = []
82+
variable "bas_admins" {
83+
type = list(string)
84+
description = "List of users to assign the Administrator role."
85+
9086
}
87+
variable "bas_developers" {
88+
type = list(string)
89+
description = "List of users to assign the Developer role."
90+
}
91+
variable "bas_plan" {
92+
type = string
93+
description = "Plan name for Business Application Studio."
94+
default = "standard"
95+
}

0 commit comments

Comments
 (0)