Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
CHERIANS committed Dec 6, 2024
1 parent c0702fb commit bece0c7
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 72 deletions.
2 changes: 1 addition & 1 deletion released/SAP-Inside-Tracks/SITBLR_DEC_2024/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SITBLR DECEMBER 2024 - HandsOn SAP Terraform Provider for SAP BTP

## Goal of this HandsOn 🎯
## Goal of this Hands-on 🎯

In this hands-on exercise you will learn how to use the [Terraform Provider for SAP BTP](https://registry.terraform.io/providers/SAP/btp/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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ As we have all variables in place, you should save the changes now.
> [!NOTE]
> As you can see you have a lot of possibilities to validate the user input in Terraform in this way ensure that the input is correct and meets your corporate requirements.
We have defined the `project_name` which is required for the subaccount creation. We will provide the value for this variable via the `terraform.tfvars` file. Open
the file `terraform.tfvars` and append the following content to the end of the file:

```terraform
project_name = "<YOUR LAST NAME>"
```

### Step 2: Local values

Now we want to leverage the input variables to create a subaccount name that follows a specific naming convention. Here are the conditions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ variable "bas_plan" {
}
```

We define a complex variable type, which is a [list](https://developer.hashicorp.com/terraform/language/expressions/types#lists-tuples) of [objects](https://developer.hashicorp.com/terraform/language/expressions/types#maps-objects). Each object has three attributes: `name`, `plan`, and `amount`. The `name` and `plan` attributes are strings, and the `amount` attribute is a number. We define a default value for the variable, which is an empty list.We will provide values for this parameter via the file `terraform.tfvars` in the next step. Save the changes.
We define a complex variable type, which is a [list](https://developer.hashicorp.com/terraform/language/expressions/types#lists-tuples) of [objects](https://developer.hashicorp.com/terraform/language/expressions/types#maps-objects). Each object has three attributes: `name` and `plan`. The `name` and `plan` attributes are strings. We define a default value for the variable, which is an empty list.We will provide values for this parameter via the file `terraform.tfvars` in the next step. Save the changes.

## Step 2: Add the variable to the tfvars file

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ output "cloudfoundry_org_name" {
```

You will be prompted to confirm the creation of the environment. Type `yes` and press `Enter` to continue.
The output should look like this:

<img width="600px" src="assets/ex7_3.png" alt="executing terraform apply with cloud foundry provider">

You can also check that everything is in place via the SAP BTP cockpit. You should see the Cloud Foundry environment in the subaccount:

<img width="600px" src="assets/ex7_4.png" alt="SAP BTP Cockpit with Cloud Foundry environment">
## Summary

You've now successfully created a Cloud Foundry environment instance as well as a Cloud Foundry space in SAP BTP.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,6 @@

In this exercise you will learn how to use the [Terraform Provider for CloudFoundry](https://registry.terraform.io/providers/cloudfoundry/cloudfoundry/latest/docs) and create a space.

### Step 3: Adjust the provider configuration

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:

```terraform
cloudfoundry = {
source = "cloudfoundry/cloudfoundry"
version = "1.1.0"
}
```

To configure the Cloud Foundry provider add the following lines at the end of the file:

```terraform
provider "cloudfoundry" {
api_url = "https://api.cf.${var.region}-001.hana.ondemand.com"
}
```
Save your changes.

> [!WARNING]
> 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.
To fulfill all requirements for the authentication against the Cloud Foundry environment you must export the following environment variables:

- Windows:
Expand All @@ -43,57 +20,36 @@ To fulfill all requirements for the authentication against the Cloud Foundry env
export CF_PASSWORD='<your SAP BTP password>'
```
> [!NOTE]
> 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.
### Step 3: Apply the changes
### Step 1: Adjust the provider configuration
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:
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:
```bash
terraform init
```terraform
cloudfoundry = {
source = "cloudfoundry/cloudfoundry"
version = "1.1.0"
}
```

The output should look like this:

<img width="600px" src="assets/ex7_1.png" alt="executing terraform init with cloud foundry provider">

> [!NOTE]
> 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.
You know the drill by now:

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

```bash
terraform plan
```

The output should look like this:

<img width="600px" src="assets/ex7_2.png" alt="executing terraform plan with cloud foundry">

2. Apply the Terraform configuration to create the environment:

```bash
terraform apply
```

You will be prompted to confirm the creation of the environment. Type `yes` and press `Enter` to continue.

The result should look like this:
To configure the Cloud Foundry provider add the following lines at the end of the file:

<img width="600px" src="assets/ex7_3.png" alt="executing terraform apply with cloud foundry provider">
```terraform
provider "cloudfoundry" {
api_url = "https://api.cf.${var.region}-001.hana.ondemand.com"
}
```
Save your changes.

You can also check that everything is in place via the SAP BTP cockpit. You should see the Cloud Foundry environment in the subaccount:
> [!WARNING]
> 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.
<img width="600px" src="assets/ex7_4.png" alt="SAP BTP Cockpit with Cloud Foundry environment">

## Creation of a Cloud Foundry space
> [!NOTE]
> 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.
As a last task we also want to add a Cloud Foundry space to the Cloud Foundry environment.

### Step 1: Add the variable to the configuration for Space creation
### Step 2: Add the variable to the configuration for Space creation

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

Expand Down Expand Up @@ -131,7 +87,7 @@ variable "cf_space_auditors" {

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.

### Step 2: Cloudfoundry Space Creation and Role Assignments
### Step 3: Cloudfoundry Space Creation and Role Assignments

To trigger the creation of a Cloud Foundry space and space roles, Open the `main.tf` file and add the following code:

Expand Down Expand Up @@ -173,7 +129,7 @@ resource "cloudfoundry_space_role" "cf_space_auditors" {
}
```

### Step 3: Add the variables to tfvar file
### Step 4: Add the variables to tfvar file

Now we can add `space developers` and `space managers` to the space we created, Add following variables to your `tfvars` file.

Expand All @@ -183,21 +139,26 @@ cf_space_developers = ["[email protected]"]
```
Save the changes.

### Step 4: Apply the changes

### Step 5: Apply the changes
As we have all prerequisites already in place when it comes to provider configuration and authentication, we can proceed with applying the changes.

1. Plan the Terraform configuration to see what will be created:
1. 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:

```bash
terraform init
```

2. Plan the Terraform configuration to see what will be created:

```bash
terraform plan
```

The output should look like this:

<img width="600px" src="assets/ex7_6.png" alt="executing terraform plan for cloud foundry space creation">
<img width="600px" src="assets/ex7_2.png" alt="executing terraform plan for cloud foundry space creation">

2. Apply the Terraform configuration to create the space:
3. Apply the Terraform configuration to create the space:

```bash
terraform apply
Expand Down
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.

0 comments on commit bece0c7

Please sign in to comment.