Skip to content

Commit 176f6e4

Browse files
committed
chore: update cf steps
1 parent 121bee1 commit 176f6e4

File tree

6 files changed

+46
-103
lines changed

6 files changed

+46
-103
lines changed

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

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,35 @@ resource "btp_subaccount" "project" {
2222
}
2323

2424
###
25-
# Assignment of emergency admins to subaccount
25+
# Entitlement Subscription and Role Assignment for BAS
2626
###
27-
resource "btp_subaccount_role_collection_assignment" "subaccount_users" {
28-
for_each = toset(var.emergency_admins)
29-
subaccount_id = btp_subaccount.project.id
30-
role_collection_name = "Subaccount Administrator"
31-
user_name = each.value
32-
}
3327

34-
###
35-
# Assignment of entitlements
36-
###
37-
resource "btp_subaccount_entitlement" "entitlements" {
38-
for_each = {
39-
for index, entitlement in var.entitlements :
40-
index => entitlement
41-
}
28+
resource "btp_subaccount_entitlement" "bas" {
29+
subaccount_id = btp_subaccount.project.id
30+
service_name = "sapappstudio"
31+
plan_name = var.bas_plan
32+
amount = 1
33+
}
4234

35+
resource "btp_subaccount_subscription" "bas" {
4336
subaccount_id = btp_subaccount.project.id
44-
service_name = each.value.name
45-
plan_name = each.value.plan
37+
app_name = "sapappstudio"
38+
plan_name = var.bas_plan
39+
depends_on = [btp_subaccount_entitlement.bas]
4640
}
41+
42+
resource "btp_subaccount_role_collection_assignment" "bas_admin" {
43+
for_each = toset(var.bas_admins)
44+
subaccount_id = btp_subaccount.project.id
45+
role_collection_name = "Business_Application_Studio_Administrator"
46+
user_name = each.value
47+
depends_on = [btp_subaccount_subscription.bas]
48+
}
49+
50+
resource "btp_subaccount_role_collection_assignment" "bas_developer" {
51+
for_each = toset(var.bas_developers)
52+
subaccount_id = btp_subaccount.project.id
53+
role_collection_name = "Business_Application_Studio_Developer"
54+
user_name = each.value
55+
depends_on = [btp_subaccount_subscription.bas]
56+
}

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,6 @@ variable "org_name" {
6666
}
6767
}
6868

69-
###
70-
# Emergency admin setup
71-
###
72-
variable "emergency_admins" {
73-
type = list(string)
74-
description = "Defines the colleagues who are added to each subaccount as emergency administrators."
75-
76-
}
77-
78-
7969
###
8070
# Entitlement for BAS
8171
###

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

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ In this section, we will create a Cloud Foundry environment in the subaccount us
88

99
The Cloud Foundry Application Runtime service needs to be entitled to the subaccount. To achieve this, add the following resource to your Terraform configuration:
1010

11-
### Step 1: Add the module to the Terraform configuration
11+
### Step 1: Add the resources to the Terraform configuration for cloudfoundry setup
1212

1313
First we need to add one more local variable in the `main.tf` file. Open the `main.tf` file and add the following code to the `locals` block:
1414

@@ -47,7 +47,7 @@ resource "btp_subaccount_environment_instance" "cloudfoundry" {
4747

4848
### Step 2: Adjust the output variables
4949

50-
As we are using the output variables of the module, we need to adjust the output variables in the `outputs.tf` file. Open the `outputs.tf` file and add the following code:
50+
As we are using the output variables, we need to adjust the output variables in the `outputs.tf` file. Open the `outputs.tf` file and add the following code:
5151

5252
```terraform
5353
output "cloudfoundry_org_name" {
@@ -56,8 +56,6 @@ output "cloudfoundry_org_name" {
5656
}
5757
```
5858

59-
We reference the output variables of the module via the `module` keyword. Save the changes.
60-
6159
### Step 4: Adjust the provider configuration
6260

6361
As we are using an additional provider we must make Terraform aware of this in the `provider.tf` file. Open the `provider.tf` file and add the following code to the `required_provider` block:
@@ -76,7 +74,6 @@ provider "cloudfoundry" {
7674
api_url = "https://api.cf.${var.region}-001.hana.ondemand.com"
7775
}
7876
```
79-
8077
Save your changes.
8178

8279
> [!WARNING]
@@ -103,7 +100,7 @@ To fulfill all requirements for the authentication against the Cloud Foundry env
103100
104101
### Step 3: Apply the changes
105102
106-
As we have a new provider and a new module in place, we need to re-initialize the setup to download the required provider and module. Run the following command:
103+
As we have a new provider in place, we need to re-initialize the setup to download the required provider and module. Run the following command:
107104
108105
```bash
109106
terraform init
@@ -146,9 +143,9 @@ You can also check that everything is in place via the SAP BTP cockpit. You shou
146143

147144
## Creation of a Cloud Foundry space
148145

149-
As a last task we also want to add a Cloud Foundry space to the Cloud Foundry environment. We will use the same concept as before and leverage a module. Navigate to the `modules` folder in the root of this repo and you will find the fitting module at [environments/cloudfoundry/space_cf](../../modules/environment/cloudfoundry/space_cf/README.md).
146+
As a last task we also want to add a Cloud Foundry space to the Cloud Foundry environment.
150147

151-
### Step 1: Add the space name variable to the configuration
148+
### Step 1: Add the variable to the configuration for Space creation
152149

153150
First we need to add more variable in the `variables.tf` file. Open the `variables.tf` file and add the following code:
154151

@@ -198,9 +195,9 @@ variable "cf_space_auditors" {
198195

199196
This allows us to specify the name of the Cloud Foundry space. We also define a default value (`dev`) for the variable. Save the changes.
200197

201-
### Step 2: Add the module to the Terraform configuration
198+
### Step 2: Cloudfoundry Space Creation and Role Assignments
202199

203-
To trigger the creation of a Cloud Foundry space and space roles, we add the module to the `main.tf` file. Open the `main.tf` file and add the following code:
200+
To trigger the creation of a Cloud Foundry space and space roles, Open the `main.tf` file and add the following code:
204201

205202
```terraform
206203
resource "cloudfoundry_org_role" "my_role" {
@@ -240,21 +237,19 @@ resource "cloudfoundry_space_role" "cf_space_auditors" {
240237
}
241238
```
242239

243-
Save the changes.
244-
245-
### Step 3: Apply the changes
240+
### Step 3: Add the variables to tfvar file
246241

247-
As we have all prerequisites already in place when it comes to provider configuration and authentication. However, we need to reinitialize the module that we use. To achieve that run the following command:
242+
Now we can add `space developers` and `space managers` to the space we created, Add following variables to your `tfvars` file.
248243

249-
```bash
250-
terraform init
244+
```terraform
245+
cf_org_user = ["[email protected]"]
246+
cf_space_developers = ["[email protected]"]
251247
```
248+
Save the changes.
252249

253-
The output should look like this:
254-
255-
<img width="600px" src="assets/ex7_5.png" alt="executing terraform init with cloud foundry provider">
250+
### Step 4: Apply the changes
256251

257-
Once we have initialized the module we can proceed with the creation of the Cloud Foundry space. As before we execute the following commands:
252+
As we have all prerequisites already in place when it comes to provider configuration and authentication, we can proceed with applying the changes.
258253

259254
1. Plan the Terraform configuration to see what will be created:
260255

released/SAP-Inside-Tracks/SITBLR_DEC_2024/exercises/EXERCISE4/SOLUTION_EX4/main.tf

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@ resource "btp_subaccount" "project" {
2121
usage = "NOT_USED_FOR_PRODUCTION"
2222
}
2323

24-
###
25-
# Assignment of emergency admins to subaccount
26-
###
27-
resource "btp_subaccount_role_collection_assignment" "subaccount_users" {
28-
for_each = toset(var.emergency_admins)
29-
subaccount_id = btp_subaccount.project.id
30-
role_collection_name = "Subaccount Administrator"
31-
user_name = each.value
32-
}
33-
3424

3525
###
3626
# Creation of Cloud Foundry environment via module

released/SAP-Inside-Tracks/SITBLR_DEC_2024/exercises/EXERCISE4/SOLUTION_EX4/terraform.tfvars-sample

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,8 @@ globalaccount = "<YOUR GLOBAL ACCOUT SUBDOMAIN>"
22

33
region = "us10"
44

5-
costcenter = "9876543210"
5+
costcenter = "<YOUR NEW VALUE>"
66

7-
entitlements = [
8-
{
9-
name = "alert-notification"
10-
plan = "standard"
11-
amount = null
12-
},
13-
{
14-
name = "SAPLaunchpad"
15-
plan = "standard"
16-
amount = null
17-
},
18-
{
19-
name = "hana-cloud-trial"
20-
plan = "hana"
21-
amount = null
22-
},
23-
{
24-
name = "hana"
25-
plan = "hdi-shared"
26-
amount = null
27-
},
28-
{
29-
name = "sapappstudiotrial"
30-
plan = "trial"
31-
amount = null
32-
}
33-
]
34-
35-
subscriptions = [
36-
{
37-
app_name = "sapappstudiotrial"
38-
plan = "trial"
39-
}
40-
]
41-
42-
costcenter = "<YOUR NEW VALUE>"
7+
bas_plan_name = "trial"
8+
bas_admins = ["[email protected]"]
9+
bas_developers = ["[email protected]"]

released/SAP-Inside-Tracks/SITBLR_DEC_2024/exercises/EXERCISE4/SOLUTION_EX4/variables.tf

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,6 @@ variable "org_name" {
6666
}
6767
}
6868

69-
###
70-
# Emergency admin setup
71-
###
72-
variable "emergency_admins" {
73-
type = list(string)
74-
description = "Defines the colleagues who are added to each subaccount as emergency administrators."
75-
76-
}
77-
7869
variable "bas_plan_name" {
7970
description = "BAS plan"
8071
type = string

0 commit comments

Comments
 (0)