Skip to content

Commit 4387eb6

Browse files
committed
feat: Update SIT BLR handson
1 parent ddc61f3 commit 4387eb6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2190
-0
lines changed
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# SITBLR DECEMBER 2024 - HandsOn SAP Terraform Provider for SAP BTP
2+
3+
## Goal of this HandsOn 🎯
4+
5+
In this HandsOn you will learn how to use the [Terraform Provider for SAP BTP](https://registry.terraform.io/providers/SAP/cp/latest/docs) to provision and manage resources in SAP BTP.
6+
7+
## Scenario 📚
8+
9+
In this HandsOn we want to make you familiar with the Terraform Provider for SAP BTP. We will use the provider to provision and manage resources in SAP BTP. To achieve this we will walk through the following steps:
10+
11+
1. [Exercise 1 - Configure the Terraform Provider for SAP BTP](exercises/EXERCISE1/README.md)
12+
1. [Exercise 2 - Setup of a subaccount](exercises/EXERCISE2/README.md)
13+
1. [Exercise 3 - Assignment of subaccount emergency administrators](exercises/EXERCISE3/README.md)
14+
1. [Exercise 4 - Assign entitlements to a subaccount](exercises/EXERCISE4/README.md)
15+
1. [Exercise 5 - Create a service instance](exercises/EXERCISE5/README.md)
16+
1. [Exercise 6 - Handle configuration drift](exercises/EXERCISE6/README.md)
17+
1. [Exercise 7 - Setup a Cloud Foundry environment and a space (optional)](exercises/EXERCISE7/README.md)
18+
1. [Exercise 8 - Cleanup](exercises/EXERCISE8/README.md)
19+
20+
The level of the exercises is beginner. You don't need any prior knowledge about Terraform or the Terraform Provider for SAP BTP. We will guide you through the exercises step by step.
21+
22+
## Prerequisites 📝
23+
24+
Make sure that the following prerequisites are met:
25+
26+
- You have an SAP BTP Trial Account. If you don't have one yet, you can get one [here](https://developers.sap.com/tutorials/hcp-create-trial-account.html).
27+
- Make sure that your SAP Universal ID is configured correctly. You can find the instructions in [SAP Note 3085908](https://me.sap.com/notes/3085908).
28+
- The Terraform provider does not support SSO or 2FA. Make sure that these options are not enforced for your account.
29+
30+
## Tools 🛠️
31+
32+
To execute the exercises you have the following options concerning the required tools installed:
33+
34+
- local installation
35+
- usage of the provided dev container
36+
- usage of GitHub Codespaces
37+
38+
You find details about the installation of the tools in the following sections
39+
40+
In general you must clone this GitHub repository. You must have the Git client installed on your machine. You can find the installation instructions [here](https://git-scm.com/downloads).
41+
42+
You can then clone the repository via the following command:
43+
44+
```bash
45+
git clone https://github.com/SAP-samples/btp-terraform-samples.git
46+
```
47+
48+
you find the exercises in the folder `released/dsag/betriebstag2024/exercises`.
49+
50+
### Local Installation
51+
52+
You can install the required tools locally on your machine. The following tools are required:
53+
54+
- [Terraform CLI](https://developer.hashicorp.com/terraform/install?product_intent=terraform)
55+
- An editor of your choice. We recommend [Visual Studio Code](https://code.visualstudio.com/Download) with the [Terraform extension](https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform).
56+
57+
### Dev Container
58+
59+
As an alternative to the local installation you can use the provided dev container that contains all required tools. This requires that you have [Docker](https://www.docker.com/products/docker-desktop) installed on your machine. In addition you need the dev container extension for Visual Studio Code. You can find detailed instructions about the setup [here](https://code.visualstudio.com/docs/devcontainers/containers#_getting-started).
60+
61+
To start a dev container Docker must be running on your machine.
62+
63+
To use the dev container you must open the folder that contains the cloned repository in Visual Studio Code. You will be asked if you want to reopen the folder in the dev container. Confirm this.
64+
65+
If this is not the case execute the following steps:
66+
67+
1. Open the command palette in Visual Studio Code:
68+
69+
- Windows / Linux: `Ctrl + Shift + P`
70+
- Mac: `Cmd + Shift + P`
71+
72+
2. Enter `Dev Containers: Reopen in Container` and confirm with `Enter`.
73+
74+
3. You will then be asked to select a dev container. Select the `Terraform provider for SAP BTP - Default` container:
75+
76+
![Select dev container](assets/devcontainer-selection.png)
77+
78+
The dev container will automatically start and you are ready to go
79+
80+
### GitHub Codespaces
81+
82+
To use [Codespaces](https://docs.github.com/codespaces/overview) you must have a GitHub account. If you don't have one so far, please [sign-up on GitHub](https://github.com/signup) before going through the exercises.
83+
84+
You can then access the Codespace following these steps:
85+
86+
1. Open the [GitHub repository of the Terraform samples](https://github.com/SAP-samples/btp-terraform-samples).
87+
88+
![Screenshot of GitHub repository Terraform samples](assets/repo-terraform-samples.png)
89+
90+
2. Click on this button and create the code space:
91+
92+
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=656281656&skip_quickstart=true&machine=basicLinux32gb&geo=EuropeWest&devcontainer_path=.devcontainer%2Fdevcontainer.json)
93+
94+
This will take a few minutes. Be patient 🙂
95+
96+
![Screenshot of navigation to Codespace creation in the repository Terraform samples](assets/codespace-creation.png)
97+
98+
3. While the Codespace is created for you, you will see this screen
99+
100+
![Screenshot of setup screen for Codespace](assets/codespace-setup-process.png)
101+
102+
4. Once all is done, you are in your Codespace.
103+
104+
![Screenshot of GitHub Codespace view on the repository Terraform samples](assets/codespace-screen.png)
105+
106+
> [!IMPORTANT]
107+
> GitHub codespaces are free for a certain amount of time per month. For the hands-on session the free time is more than enough. **Don't forget to delete your codespace again after the hands-on session!**
108+
109+
110+
## Exporting environment variables
111+
112+
The last step in the setup is the export of the environment variables that are required to authenticate against the Terraform provider for SAP BTP. Fo that export the following environment variables:
113+
114+
- Windows:
115+
116+
```pwsh
117+
$env:BTP_USERNAME=<your SAP BTP username>
118+
$env:BTP_PASSWORD='<your SAP BTP password>'
119+
```
120+
121+
- Linux/MacOS/GitHub Codespaces:
122+
123+
```bash
124+
export BTP_USERNAME=<your SAP BTP username>
125+
export BTP_PASSWORD='<your SAP BTP password>'
126+
```
127+
128+
Validate that the values are set via:
129+
130+
- Windows: `$env:BTP_USERNAME` and `$env:BTP_PASSWORD`
131+
- Linux/MacOS/GitHub Codeapses: `echo $BTP_USERNAME` and `echo $BTP_PASSWORD`
132+
133+
## Folder layout
134+
135+
You find all exercises of this tutorial in the folder `released/dsag/betriebstag2024/exercises`. Each exercise is contained in a dedicated folder containing:
136+
137+
- A `README.md` file with the instructions for the exercise
138+
- A folder `SOLUTION_EX<number>` which contains the solution for the exercise if needed including the file `terraform.tfvars-sample` contains the definition of the local variables. In case you get stuck you can check the content of this folder.
139+
140+
In addition the folder `solution` contains the final configuration setup if you have gone through all exercises.
141+
142+
## Summary
143+
144+
You've now prepared your development environment and have all information to finally start using Terraform provider for SAP BTP.
145+
146+
Continue to - [Exercise 1 - Configure the Terraform Provider for SAP BTP](exercises/EXERCISE1/README.md).
34.4 KB
Loading
126 KB
Loading
30.7 KB
Loading
13 KB
Loading
55.9 KB
Loading
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Exercise 1 - Configure the Terraform Provider for SAP BTP
2+
3+
## Goal of this Exercise 🎯
4+
5+
The goal of this exercise is to configure the Terraform provider for SAP BTP. In addition we will create a basic setup of the file structure to implement the Terraform configuration.
6+
7+
## Step 1: Create a new directory
8+
9+
To make use of Terraform you must create several configuration files using the [Terraform configuration language](https://developer.hashicorp.com/terraform/language). Create a new directory named `my-tf-handson` under the folder `SITBLR2024`.
10+
11+
Terraform expects a specific file layout for its configurations. Create the following empty files in the directory `my-tf-handson`:
12+
13+
- `main.tf` - this file will contain the main configuration of the Terraform setup
14+
- `provider.tf` - this file will contain the provider configuration
15+
- `variables.tf` - this file will contain the variables to be used in the Terraform configuration
16+
- `outputs.tf` - this file will contain the outputs of the Terraform configuration
17+
- `terraform.tfvars` - this file will contain your specific variable values
18+
19+
## Step 2: Create the provider configuration
20+
21+
Next we must configure the Terraform provider for SAP BTP. This is done by adding the provider configuration to the `provider.tf` file. You find the information about the required parameters in the documentation of the [Terraform Provider for SAP BTP](https://registry.terraform.io/providers/SAP/btp/latest/docs).
22+
23+
Open the file `provider.tf` and add the following content:
24+
25+
```terraform
26+
terraform {
27+
required_providers {
28+
btp = {
29+
source = "sap/btp"
30+
version = "~> 1.8.0"
31+
}
32+
}
33+
}
34+
35+
provider "btp" {
36+
globalaccount = var.globalaccount
37+
}
38+
```
39+
40+
What have we done? First we defined which provider we want to use and which version of the provider we want to use. In this case we want to use the provider `sap/btp` in version `1.8.0` (including potential patch versions). Then we defined the provider configuration. In this case we only need to provide the `globalaccount` parameter where we reference a variable. We will define this variable in the next step.
41+
42+
> [!NOTE]
43+
> We do not need any authentication information in this file. We provided the authentication information via environment variables.
44+
45+
Next we must add the required variables to the `variables.tf` file. Open the file `variables.tf` and add the following content:
46+
47+
```terraform
48+
variable "globalaccount" {
49+
type = string
50+
description = "The subdomain of the SAP BTP global account."
51+
}
52+
```
53+
54+
We have now defined the variable `globalaccount` which is required for the provider configuration. We will provide the value for this variable via the `terraform.tfvars` file. Open
55+
the file `terraform.tfvars` and add the following content:
56+
57+
```terraform
58+
globalaccount = "<YOUR GLOBAL ACCOUNT SUBDOMAIN>"
59+
```
60+
61+
> [!NOTE]
62+
> We are using here a naming convention of Terraform to define the variable values. The file `terraform.tfvars` is used to define the variable values. The file is not checked into the source code repository. This is important to keep sensitive information out of the source code repository. When you run Terraform, it will automatically load the variable values from this file.
63+
64+
## Summary
65+
66+
You've now created a basic setup of the Terraform provider including its configuration.
67+
68+
Continue to - [Exercise 2 - Setup of a subaccount](../EXERCISE2/README.md).

released/SAP-Inside-Tracks/SITBLR_DEC_2024/exercises/EXERCISE1/SOLUTION_EX1/main.tf

Whitespace-only changes.

released/SAP-Inside-Tracks/SITBLR_DEC_2024/exercises/EXERCISE1/SOLUTION_EX1/outputs.tf

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
terraform {
3+
required_providers {
4+
btp = {
5+
source = "sap/btp"
6+
version = "~> 1.8.0"
7+
}
8+
}
9+
10+
}
11+
12+
# Please checkout documentation on how best to authenticate against SAP BTP
13+
# via the Terraform provider for SAP BTP
14+
provider "btp" {
15+
globalaccount = var.globalaccount
16+
}

0 commit comments

Comments
 (0)