In this exercise, we will implement the basic Terraform configuration.
Note
You find the solution for this exercise in the solutions/ex1 folder.
After completing these steps, you will have created the file layout needed for the Terraform configuration.
- Go to the root directory of this project and create a new directory called
terraform_build
- Navigate into the directory
terraform_build
. - Create the following files inside of the directory:
main.tf
- this file will contain the main Terraform configurationprovider.tf
- this file will contain the provider configurationvariables.tf
- this file will contain the variable definitions making your terraform setup more flexibleoutputs.tf
- this file will contain the output definitions, so that you get the information you need after the terraform setup is doneterraform.tfvars
- this file will contain the actual values for the variables defined invariables.tf
as key-value pairs
After completing these steps, you will have created the provider configuration.
The basic configuration of the Terraform provider for SAP BTP is available in the official documentation located in the Terraform registry. Looking at the documentation we see that we need to tell Terraform which provider to use and how to authenticate against the SAP BTP. Let's do that
-
Open the file
provider.tf
. -
Add the following code to the file and save the changes:
terraform { required_providers { btp = { source = "SAP/btp" version = "~> 1.7.0" } } } # Please checkout documentation on how best to authenticate against SAP BTP # via the Terraform provider for SAP BTP provider "btp" { globalaccount = var.globalaccount }
In accordance to the documentation we instruct Terraform to use the provider in version 1.7.0 . We also added the authentication information as a variable to increase flexibility. To make the story complete we need to define the variable.
-
Open the file
variables.tf
. -
Add the following code to the file and save the changes:
variable "globalaccount" { type = string }
-
As we do not want to hard code or default the value for the global account, we need to provide the value in the
terraform.tfvars
file. Open the fileterraform.tfvars
and add the following code:globalaccount = "<your-global-account-subdomain>"
Enter the subdomain value of your global account which has the format
xxxxxxxxtrial-ga
and save your changes.You find the value in the SAP BTP Cockpit in the account explorer:
You've now finished the basic setup namely the provider configuration to start with the Terraform configuration for our desired setup.
Continue to - Exercise 2 - Create a Subaccount