Get Started with the Terraform Provider for BTP
Learn how to use Terraform to manage resources on SAP Business Technology Platform using code.
Overview
You will learn
- How to install and configure the Terraform Provider for BTP.
- How to manage your BTP resources as code, making them more reproducible, maintainable, and scalable.
- How to clean up your BTP resources when they are no longer needed, helping you avoid unnecessary costs and resource consumption.
Prerequisites
Prerequisites
Steps
Terraform is an open-source tool that allows you to define and provide cloud infrastructure using a declarative configuration language. It helps in building, changing, and managing resources in a safe, consistent, and efficient manner.
By combining Terraform with SAP Business Technology Platform (BTP), you can programmatically manage your BTP environments.
Create a new directory for the tutorial content. This directory will serve as the workspace for your Terraform configuration files. Afterwards, please open a terminal or command prompt and navigate to the newly created directory.
To install and configure the Terraform provider for BTP, add the following block to your Terraform configuration file (provider.tf).
terraform {
required_providers {
btp = {
source = "SAP/btp"
version = "~>1.25.0"
}
}
}
provider "btp" {
globalaccount = "4605efebtrial-ga"
}Replace "4605efebtrial-ga" with the subdomain of your own BTP trial account.
After setting up the provider configuration, run the following command in the terminal to let Terraform download all necessary dependencies:
terraform init
Last but not least, you need to pass credentials to the provider to authenticate and interact with your BTP environments. Please set the environment variables BTP_USERNAME and BTP_PASSWORD.
For Windows you have two options to export the environment variables:
If you use Windows CMD, do the export via the following commands:
set BTP_USERNAME=<your_username>
set BTP_PASSWORD=<your_password>If you use Powershell, do the export via the following commands:
$Env:BTP_USERNAME = '<your_username>'
$Env:BTP_PASSWORD = '<your_password>'For Mac OS export the environment variables via:
export BTP_USERNAME=<your_username>
export BTP_PASSWORD=<your_password>For Linux export the environment variables via:
export BTP_USERNAME=<your_username>
export BTP_PASSWORD=<your_password>Replace <your_username> and <your_password> with your actual BTP username and password.
You are now ready to use the Terraform provider for BTP to manage your resources.
With the provider set up, you can now provision resources on BTP. Let’s first create a subaccount using the btp_subaccount resource. Create a new file main.tf and add the following content:
resource "btp_subaccount" "my_project" {
name = "My Project"
subdomain = "my-project"
region = "us10"
}This code creates a subaccount named “My Project” in the “us10” region. The name, region, and subdomain parameters are all required. Now that you’ve defined your resources, you can apply the configuration using the following command:
terraform applyTerraform will prompt you to confirm the changes. Type yes and press Enter to proceed.

The subaccount has just been created for you.
To set an entitlement for the subaccount, you can use the btp_subaccount_entitlement resource. Here’s an example of how to do that, please add the following content to your main.tf file:
resource "btp_subaccount_entitlement" "alert_notification_service" {
subaccount_id = btp_subaccount.my_project.id
service_name = "alert-notification"
plan_name = "standard"
}This code assigns the “standard” plan of the “alert-notification” service to the previously created subaccount. The subaccount_id, service_name, and plan_name parameters are required.
Once you’ve defined the entitlement, you can apply the changes using the following command:
terraform applyTerraform will prompt you to confirm the changes. Type yes and press Enter to proceed.

The subaccount is now entitled for the alert-notification service.
The Terraform Provider for SAP BTP offers a wide range of resources that you can manage using Terraform. In addition to creating subaccounts and setting entitlements, you can provision and manage other resources such as service instances, service bindings, role collections, and more.
To get a better understanding of the capabilities of the provider and the available resources, check out the provider documentation at https://registry.terraform.io/providers/SAP/btp/latest/docs. It provides detailed information about each resource, including their properties and usage examples.
You may want to destroy the resources created in the previous examples when they are no longer needed. Terraform provides a convenient way to destroy resources using the terraform destroy command:
terraform destroyTerraform will prompt you to confirm the destruction of the resources. Type yes and press Enter to proceed.

Terraform will then destroy the subaccount and removing any entitlements associated with it.
Resources
Discussion
Share feedback on this tutorial or join the conversation in SAP Community.