Skip to content

Commit 1de2c2a

Browse files
committed
refactor chapters
1 parent cb6325e commit 1de2c2a

File tree

11 files changed

+201
-242
lines changed

11 files changed

+201
-242
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ In this HandsOn we want to make you familiar with the Terraform Provider for SAP
7171
1. [Exercise 1 - Configure the Terraform Provider for SAP BTP](exercises/EXERCISE1/README.md)
7272
1. [Exercise 2 - Setup of a subaccount](exercises/EXERCISE2/README.md)
7373
1. [Exercise 3 - Assign entitlement,Subscription and its role assignments to a subaccount](exercises/EXERCISE3/README.md)
74-
1. [Exercise 4 - Setup a Cloud Foundry environment and a space (optional)](exercises/EXERCISE4/README.md)
75-
1. [Exercise 5 - Exercise 5 - Assignment of subaccount emergency administrators](exercises/EXERCISE5/README.md)
74+
1. [Exercise 4 - Setup a Cloud Foundry environment](exercises/EXERCISE4/README.md)
75+
1. [Exercise 5 - Create a CloudFoundry Space](exercises/EXERCISE5/README.md)
7676
1. [Exercise 6 - Cleanup](exercises/EXERCISE6/README.md)
7777
7878

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

Lines changed: 12 additions & 204 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ First we need to add one more local variable in the `main.tf` file. Open the `ma
1515
```terraform
1616
project_subaccount_cf_org = replace("${var.org_name}_${lower(var.project_name)}-${lower(var.stage)}", " ", "_")
1717
```
18+
We will define the variables in the `variable.tf` file. Open the `variable.tf` file and add the following code.
19+
20+
21+
```terraform
22+
variable "cf_landscape_label" {
23+
type = string
24+
description = "The region where the project account shall be created in."
25+
default = "cf-us10-001"
26+
}
27+
```
28+
1829
Then add the following code to the `main.tf`
1930

2031
```terraform
@@ -55,66 +66,8 @@ output "cloudfoundry_org_name" {
5566
description = "The name of the cloudfoundry org connected to the project account."
5667
}
5768
```
58-
59-
### Step 4: Adjust the provider configuration
60-
61-
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:
62-
63-
```terraform
64-
cloudfoundry = {
65-
source = "cloudfoundry/cloudfoundry"
66-
version = "1.1.0"
67-
}
68-
```
69-
70-
To configure the Cloud Foundry provider add the following lines at the end of the file:
71-
72-
```terraform
73-
provider "cloudfoundry" {
74-
api_url = "https://api.cf.${var.region}-001.hana.ondemand.com"
75-
}
76-
```
77-
Save your changes.
78-
79-
> [!WARNING]
80-
> We assume that the Cloud Foundry environment is deployed to the extension landscape 001. If this is not the case the authentication might fail. In a real-world scenario you would probably have a different boundary of content to the module.
81-
82-
To fulfill all requirements for the authentication against the Cloud Foundry environment you must export the following environment variables:
83-
84-
- Windows:
85-
86-
```pwsh
87-
$env:CF_USER=<your SAP BTP username>
88-
$env:CF_PASSWORD='<your SAP BTP password>'
89-
```
90-
91-
- Linux/MacOS/GitHub Codespaces:
92-
93-
```bash
94-
export CF_USER=<your SAP BTP username>
95-
export CF_PASSWORD='<your SAP BTP password>'
96-
```
97-
98-
> [!NOTE]
99-
> Although we do not use the Cloud Foundry part of the module namely the assignment of users to the organization, Terraform will initialize the Cloud Foundry provider and try to authenticate against the Cloud Foundry environment. This is why we need to define the configuration and provide the credentials.
100-
10169
### Step 3: Apply the changes
10270

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:
104-
105-
```bash
106-
terraform init
107-
```
108-
109-
The output should look like this:
110-
111-
<img width="600px" src="assets/ex7_1.png" alt="executing terraform init with cloud foundry provider">
112-
113-
> [!NOTE]
114-
> There is also a command parameter called `--upgrade` for the `terraform init` command. This parameter will *upgrade* the provider to the latest version. As we are adding new providers, we do not need to use this parameter.
115-
116-
You know the drill by now:
117-
11871
1. Plan the Terraform configuration to see what will be created:
11972

12073
```bash
@@ -132,153 +85,8 @@ You know the drill by now:
13285
```
13386

13487
You will be prompted to confirm the creation of the environment. Type `yes` and press `Enter` to continue.
135-
136-
The result should look like this:
137-
138-
<img width="600px" src="assets/ex7_3.png" alt="executing terraform apply with cloud foundry provider">
139-
140-
You can also check that everything is in place via the SAP BTP cockpit. You should see the Cloud Foundry environment in the subaccount:
141-
142-
<img width="600px" src="assets/ex7_4.png" alt="SAP BTP Cockpit with Cloud Foundry environment">
143-
144-
## Creation of a Cloud Foundry space
145-
146-
As a last task we also want to add a Cloud Foundry space to the Cloud Foundry environment.
147-
148-
### Step 1: Add the variable to the configuration for Space creation
149-
150-
First we need to add more variable in the `variables.tf` file. Open the `variables.tf` file and add the following code:
151-
152-
```terraform
153-
variable "cf_space_name" {
154-
type = string
155-
description = "The name of the Cloud Foundry space."
156-
default = "dev"
157-
}
158-
159-
variable "cf_landscape_label" {
160-
type = string
161-
description = "The region where the project account shall be created in."
162-
default = "cf-us10-001"
163-
}
164-
165-
variable "cf_org_name" {
166-
type = string
167-
description = "The name for the Cloud Foundry Org."
168-
default = ""
169-
}
170-
171-
variable "cf_org_user" {
172-
type = set(string)
173-
description = "Defines the colleagues who are added to each subaccount as subaccount administrators."
174-
175-
}
176-
177-
variable "cf_space_managers" {
178-
type = list(string)
179-
description = "The list of Cloud Foundry space managers."
180-
default = []
181-
}
182-
183-
variable "cf_space_developers" {
184-
type = list(string)
185-
description = "The list of Cloud Foundry space developers."
186-
default = []
187-
}
188-
189-
variable "cf_space_auditors" {
190-
type = list(string)
191-
description = "The list of Cloud Foundry space auditors."
192-
default = []
193-
}
194-
```
195-
196-
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.
197-
198-
### Step 2: Cloudfoundry Space Creation and Role Assignments
199-
200-
To trigger the creation of a Cloud Foundry space and space roles, Open the `main.tf` file and add the following code:
201-
202-
```terraform
203-
resource "cloudfoundry_org_role" "my_role" {
204-
for_each = var.cf_org_user
205-
username = each.value
206-
type = "organization_user"
207-
org = btp_subaccount_environment_instance.cloudfoundry.platform_id
208-
}
209-
210-
resource "cloudfoundry_space" "space" {
211-
name = var.name
212-
org = btp_subaccount_environment_instance.cloudfoundry.platform_id
213-
}
214-
215-
resource "cloudfoundry_space_role" "cf_space_managers" {
216-
for_each = toset(var.cf_space_managers)
217-
username = each.value
218-
type = "space_manager"
219-
space = cloudfoundry_space.space.id
220-
depends_on = [ cloudfoundry_org_role.my_role ]
221-
}
222-
223-
resource "cloudfoundry_space_role" "cf_space_developers" {
224-
for_each = toset(var.cf_space_developers)
225-
username = each.value
226-
type = "space_developer"
227-
space = cloudfoundry_space.space.id
228-
depends_on = [ cloudfoundry_org_role.my_role ]
229-
}
230-
231-
resource "cloudfoundry_space_role" "cf_space_auditors" {
232-
for_each = toset(var.cf_space_auditors)
233-
username = each.value
234-
type = "space_auditor"
235-
space = cloudfoundry_space.space.id
236-
depends_on = [ cloudfoundry_org_role.my_role ]
237-
}
238-
```
239-
240-
### Step 3: Add the variables to tfvar file
241-
242-
Now we can add `space developers` and `space managers` to the space we created, Add following variables to your `tfvars` file.
243-
244-
```terraform
245-
cf_org_user = ["[email protected]"]
246-
cf_space_developers = ["[email protected]"]
247-
```
248-
Save the changes.
249-
250-
### Step 4: Apply the changes
251-
252-
As we have all prerequisites already in place when it comes to provider configuration and authentication, we can proceed with applying the changes.
253-
254-
1. Plan the Terraform configuration to see what will be created:
255-
256-
```bash
257-
terraform plan
258-
```
259-
260-
The output should look like this:
261-
262-
<img width="600px" src="assets/ex7_6.png" alt="executing terraform plan for cloud foundry space creation">
263-
264-
2. Apply the Terraform configuration to create the space:
265-
266-
```bash
267-
terraform apply
268-
```
269-
270-
You will be prompted to confirm the creation of the space. Type `yes` and press `Enter` to continue.
271-
272-
The result should look like this:
273-
274-
<img width="600px" src="assets/ex7_7.png" alt="executing terraform apply for cloud foundry space creation">
275-
276-
You can also check that everything is in place via the SAP BTP cockpit. You should see the Cloud Foundry space in the subaccount:
277-
278-
<img width="600px" src="assets/ex7_8.png" alt="SAP BTP Cockpit with Cloud Foundry space">
279-
28088
## Summary
28189

28290
You've now successfully created a Cloud Foundry environment instance as well as a Cloud Foundry space in SAP BTP.
28391
284-
Continue to - [Exercise 5 - Adding Emergency Administrators](../EXERCISE5/README.md).
92+
Continue to - [Exercise 5 - Create a CloudFoundry Space](../EXERCISE5/README.md).

0 commit comments

Comments
 (0)