Skip to content

feat: SIT BLR handson exercises #365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions released/SAP-Inside-Tracks/SITBLR_DEC_2024/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# SITBLR DECEMBER 2024 - HandsOn SAP Terraform Provider for SAP BTP

## Goal of this HandsOn 🎯

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. 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.

## Prerequisites 📝

Make sure that the following prerequisites are met:

- 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).
- 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).
- The Terraform provider does not support SSO or 2FA. Make sure that these options are not enforced for your account.


## Tools 🛠️

To execute the exercises you have the following options concerning the required tools installed:

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).

You can then clone the repository via the following command:

```bash
git clone https://github.com/SAP-samples/btp-terraform-samples.git
```

you find the exercises in the folder `released/SAP-Inside-Tracks/SITBLR_DEC_2024/exercises`.


You can install the required tools locally on your machine. The following tools are required:

- [Terraform CLI](https://developer.hashicorp.com/terraform/install?product_intent=terraform)
- 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).


## Exporting environment variables

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:

- Windows:

```pwsh
$env:BTP_USERNAME=<your SAP BTP username>
$env:BTP_PASSWORD='<your SAP BTP password>'
```

- Linux/MacOS/GitHub Codespaces:

```bash
export BTP_USERNAME=<your SAP BTP username>
export BTP_PASSWORD='<your SAP BTP password>'
```

Validate that the values are set via:

- Windows: `$env:BTP_USERNAME` and `$env:BTP_PASSWORD`
- Linux/MacOS/GitHub Codeapses: `echo $BTP_USERNAME` and `echo $BTP_PASSWORD`


## Summary

You've now prepared your development environment and have all information to finally start using Terraform provider for SAP BTP.



## Exercises 📚

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:

1. [Exercise 1 - Configure the Terraform Provider for SAP BTP](exercises/EXERCISE1/README.md)
1. [Exercise 2 - Setup of a subaccount](exercises/EXERCISE2/README.md)
1. [Exercise 3 - Assign entitlement,Subscription and its role assignments to a subaccount](exercises/EXERCISE3/README.md)
1. [Exercise 4 - Setup a Cloud Foundry environment](exercises/EXERCISE4/README.md)
1. [Exercise 5 - Create a CloudFoundry Space](exercises/EXERCISE5/README.md)
1. [Exercise 6 - Cleanup](exercises/EXERCISE6/README.md)




Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Exercise 1 - Configure the Terraform Provider for SAP BTP

## Goal of this Exercise 🎯

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.

## Step 1: Create a new directory

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`.

Terraform expects a specific file layout for its configurations. Create the following empty files in the directory `my-tf-handson`:

- `main.tf` - this file will contain the main configuration of the Terraform setup
- `provider.tf` - this file will contain the provider configuration
- `variables.tf` - this file will contain the variables to be used in the Terraform configuration
- `outputs.tf` - this file will contain the outputs of the Terraform configuration
- `terraform.tfvars` - this file will contain your specific variable values

## Step 2: Create the provider configuration

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).

Open the file `provider.tf` and add the following content:

```terraform
terraform {
required_providers {
btp = {
source = "sap/btp"
version = "~> 1.8.0"
}
}
}

provider "btp" {
globalaccount = var.globalaccount
}
```

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.

> [!NOTE]
> We do not need any authentication information in this file. We provided the authentication information via environment variables.

Next we must add the required variables to the `variables.tf` file. Open the file `variables.tf` and add the following content:

```terraform
variable "globalaccount" {
type = string
description = "The subdomain of the SAP BTP global account."
}
```

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
the file `terraform.tfvars` and add the following content:

```terraform
globalaccount = "<YOUR GLOBAL ACCOUNT SUBDOMAIN>"
```

The SAP BTP Global Account Subdomain can be found in the SAP BTP Cockpit as shown below
<img width="600px" src="assets/trial-account.png" alt="SAP BTP Global Account Subdomain">

> [!NOTE]
> 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.

## Summary

You've now created a basic setup of the Terraform provider including its configuration.

Continue to - [Exercise 2 - Setup of a subaccount](../EXERCISE2/README.md).
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

terraform {
required_providers {
btp = {
source = "sap/btp"
version = "~> 1.8.0"
}
}

}

# Please checkout documentation on how best to authenticate against SAP BTP
# via the Terraform provider for SAP BTP
provider "btp" {
globalaccount = var.globalaccount
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
globalaccount = "<YOUR GLOBAL ACCOUT SUBDOMAIN>"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
###
# Provider configuration
###
variable "globalaccount" {
type = string
description = "The subdomain of the SAP BTP global account."
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading