Skip to content

Commit 1a3393b

Browse files
authored
Chore: Update DC Mission 4327 (#276)
1 parent ab0a495 commit 1a3393b

File tree

22 files changed

+592
-0
lines changed

22 files changed

+592
-0
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Set Up SAP BTP Account using Terraform – Cloud Foundry
2+
3+
The Terraform provider for SAP Business Technology Platform (BTP) enables you to automate the provisioning, management, and configuration of resources on SAP BTP. By leveraging this provider, you can simplify and streamline the deployment and maintenance of SAP BTP services and applications.
4+
5+
Currently, the SAP BTP provider is available in beta for non productive usage: [SAP BTP Terraform](https://registry.terraform.io/providers/SAP/btp/latest).
6+
7+
The Terraform script documented here automates the setup of an SAP BTP subaccount based on a predefined template. The scripts can be used create SAP BTP subaccount with Cloud Foundry or Kyma runtime. The Terraform script does the below configuration after creating a SAP BTP subaccount:
8+
9+
1. Configures the SAP BTP entitlements required to complete the mission. See [Setup SAP BTP Account using Terraform](https://github.com/SAP-samples/btp-terraform-samples/blob/main/released/discovery_center/mission_4327/setup_subaccount_cf/README.md#entitlements).
10+
2. Enables the SAP BTP runtime (Cloud Foundry or Kyma).
11+
3. Creates the neccessary subscription to applications: SAP Business Application Studio (BAS), SAP Build Work Zone, standard edition, etc.
12+
4. Assigns users the neccessary roles required to access the applications, such as SAP Business Application Studio.
13+
5. Adds additional users to the subaccount.
14+
### [Entitlements ](https://github.tools.sap/refapps/incidents-mgmt/blob/main/documentation/administrate/Prepare-BTP/Configure-BTP-CF.md)
15+
16+
| Service | Plan | Quota required |
17+
| ------------- | :-----------: | ----: |
18+
| Cloud Foundry Runtime | MEMORY | 1 |
19+
| SAP Build Work Zone, standard edition | Standard | 1 |
20+
| SAP HANA Cloud | hana | 1 |
21+
| SAP HANA Cloud | tools | 1 |
22+
| SAP HANA Schemas & HDI Containers | hdi-shared | 1 |
23+
24+
## Deploy the resources
25+
26+
To deploy the resources you must:
27+
1. Clone repository `git clone https://github.com/SAP-samples/btp-terraform-samples.git`
28+
2. Navigate to `released/discovery_center/mission_4327/setup_subaccount_cf`
29+
3. You will be seeing these files named `main.tf`,`provider.tf`,`samples.tfvars`,`variables.tf`.
30+
4. Create a file named `terraform.tfvars` and copy `samples.tfvars` content to `terraform.tfvars`. Update the variables to meet your requirements (By default free-tier plans are used, if you want to use it for production update in the `terraform.tfvars` accordingly)
31+
Follow these steps to use the script:
32+
5. Set `BTP_USERNAME`,`BTP_PASSWORD`,`CF_USER` and `CF_PASSWORD` as ENV variables.
33+
34+
Windows PowerShell:
35+
```Powershell
36+
$env:BTP_USERNAME="<your email address>"
37+
$env:BTP_PASSWORD="<your password>"
38+
$env:CF_USER="<your email address>"
39+
$env:CF_PASSWORD="<your password>"
40+
```
41+
Linux, macOS:
42+
```mac OS
43+
export BTP_USERNAME="<your email address>"
44+
export BTP_PASSWORD="<your password>"
45+
export CF_USER="<your email address>"
46+
export CF_PASSWORD="<your password>"
47+
```
48+
6. **Install Terraform Plugins**: Open a terminal and navigate to the directory containing your Terraform configuration files. Run the following command to initialize and upgrade Terraform plugins:
49+
50+
```shell
51+
terraform init
52+
```
53+
54+
7. **Review Changes**: Generate an execution plan to review the changes that will be made to your SAP BTP account. Run:
55+
56+
```shell
57+
terraform plan
58+
```
59+
60+
8. **Apply Configuration**: Apply the Terraform configuration to create the SAP BTP subaccount and entitlements. Run:
61+
62+
```shell
63+
terraform apply
64+
```
65+
66+
Confirm the changes by typing "yes."
67+
68+
9. **Cleanup**: After your session or project is complete, you can delete the SAP BTP subaccount and associated resources to avoid charges:
69+
70+
```shell
71+
terraform destroy
72+
```
73+
74+
Confirm the resource destruction by typing "yes."
75+
76+
11. **Optional**: You can remove the Terraform state file (`terraform.tfstate`) manually if needed.
77+
78+
Please exercise caution when using this script, especially in production environments, and ensure you understand the resources that will be created or modified.
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
###############################################################################################
2+
# Generating random ID for subdomain
3+
###############################################################################################
4+
resource "random_uuid" "uuid" {}
5+
###############################################################################################
6+
# Creation of subaccount
7+
###############################################################################################
8+
resource "btp_subaccount" "project" {
9+
name = var.subaccount_name
10+
subdomain = "btp-gp${random_uuid.uuid.result}"
11+
region = lower(var.region)
12+
}
13+
data "btp_whoami" "me" {}
14+
15+
data "btp_subaccount_environments" "all" {
16+
subaccount_id = btp_subaccount.project.id
17+
}
18+
# ------------------------------------------------------------------------------------------------------
19+
# Take the landscape label from the first CF environment if no environment label is provided
20+
# (this replaces the previous null_resource)
21+
# ------------------------------------------------------------------------------------------------------
22+
resource "terraform_data" "cf_landscape_label" {
23+
input = length(var.cf_landscape_label) > 0 ? var.cf_landscape_label : [for env in data.btp_subaccount_environments.all.values : env if env.service_name == "cloudfoundry" && env.environment_type == "cloudfoundry"][0].landscape_label
24+
}
25+
###############################################################################################
26+
# Creation of Cloud Foundry environment
27+
###############################################################################################
28+
resource "btp_subaccount_environment_instance" "cloudfoundry" {
29+
subaccount_id = btp_subaccount.project.id
30+
name = btp_subaccount.project.subdomain
31+
landscape_label = terraform_data.cf_landscape_label.output
32+
environment_type = "cloudfoundry"
33+
service_name = "cloudfoundry"
34+
plan_name = "standard"
35+
# ATTENTION: some regions offer multiple environments of a kind and you must explicitly select the target environment in which
36+
# the instance shall be created using the parameter landscape label.
37+
# available environments can be looked up using the btp_subaccount_environments datasource
38+
parameters = jsonencode({
39+
instance_name = btp_subaccount.project.subdomain
40+
})
41+
timeouts = {
42+
create = "1h"
43+
update = "35m"
44+
delete = "30m"
45+
}
46+
}
47+
48+
###############################################################################################
49+
# Assignment of users as sub account administrators
50+
###############################################################################################
51+
resource "btp_subaccount_role_collection_assignment" "subaccount-admins" {
52+
for_each = toset("${var.subaccount_admins}")
53+
subaccount_id = btp_subaccount.project.id
54+
role_collection_name = "Subaccount Administrator"
55+
user_name = each.value
56+
}
57+
######################################################################
58+
# Add entitlement for BAS, Subscribe BAS and add roles
59+
######################################################################
60+
resource "btp_subaccount_entitlement" "bas" {
61+
subaccount_id = btp_subaccount.project.id
62+
service_name = "sapappstudio"
63+
plan_name = var.bas_plan_name
64+
}
65+
resource "btp_subaccount_subscription" "bas-subscribe" {
66+
subaccount_id = btp_subaccount.project.id
67+
app_name = "sapappstudio"
68+
plan_name = var.bas_plan_name
69+
depends_on = [btp_subaccount_entitlement.bas]
70+
}
71+
resource "btp_subaccount_role_collection_assignment" "Business_Application_Studio_Administrator" {
72+
subaccount_id = btp_subaccount.project.id
73+
role_collection_name = "Business_Application_Studio_Administrator"
74+
user_name = data.btp_whoami.me.email
75+
depends_on = [btp_subaccount_subscription.bas-subscribe]
76+
}
77+
78+
79+
resource "btp_subaccount_role_collection_assignment" "Business_Application_Studio_Developer" {
80+
subaccount_id = btp_subaccount.project.id
81+
role_collection_name = "Business_Application_Studio_Developer"
82+
user_name = data.btp_whoami.me.email
83+
depends_on = [btp_subaccount_subscription.bas-subscribe]
84+
}
85+
######################################################################
86+
# Add Build Workzone entitlement subscription and role Assignment
87+
######################################################################
88+
resource "btp_subaccount_entitlement" "build_workzone" {
89+
subaccount_id = btp_subaccount.project.id
90+
service_name = "SAPLaunchpad"
91+
plan_name = var.build_workzone_plan_name
92+
}
93+
resource "btp_subaccount_subscription" "build_workzone_subscribe" {
94+
subaccount_id = btp_subaccount.project.id
95+
app_name = "SAPLaunchpad"
96+
plan_name = var.build_workzone_plan_name
97+
depends_on = [btp_subaccount_entitlement.build_workzone]
98+
}
99+
resource "btp_subaccount_role_collection_assignment" "launchpad_admin" {
100+
subaccount_id = btp_subaccount.project.id
101+
role_collection_name = "Launchpad_Admin"
102+
user_name = data.btp_whoami.me.email
103+
depends_on = [btp_subaccount_subscription.build_workzone_subscribe]
104+
}
105+
######################################################################
106+
# Create HANA entitlement subscription
107+
######################################################################
108+
resource "btp_subaccount_entitlement" "hana-cloud" {
109+
subaccount_id = btp_subaccount.project.id
110+
service_name = "hana-cloud"
111+
plan_name = var.hana-cloud_plan_name
112+
}
113+
# Enable HANA Cloud Tools
114+
resource "btp_subaccount_entitlement" "hana-cloud-tools" {
115+
subaccount_id = btp_subaccount.project.id
116+
service_name = "hana-cloud-tools"
117+
plan_name = "tools"
118+
}
119+
resource "btp_subaccount_subscription" "hana-cloud-tools" {
120+
subaccount_id = btp_subaccount.project.id
121+
app_name = "hana-cloud-tools"
122+
plan_name = "tools"
123+
depends_on = [btp_subaccount_entitlement.hana-cloud-tools]
124+
}
125+
resource "btp_subaccount_entitlement" "hana-hdi-shared" {
126+
subaccount_id = btp_subaccount.project.id
127+
service_name = "hana"
128+
plan_name = "hdi-shared"
129+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
terraform {
2+
required_providers {
3+
btp = {
4+
source = "sap/btp"
5+
version = "1.5.0"
6+
}
7+
}
8+
}
9+
10+
# Please checkout documentation on how best to authenticate against SAP BTP
11+
# via the Terraform provider for SAP BTP
12+
provider "btp" {
13+
globalaccount = var.globalaccount
14+
cli_server_url = var.cli_server_url
15+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# ------------------------------------------------------------------------------------------------------
2+
# Provider configuration
3+
# ------------------------------------------------------------------------------------------------------
4+
# Your global account subdomain
5+
globalaccount = "myglobalaccount"
6+
region = "us10"
7+
subaccount_name = "DCM Goldenpath"
8+
cf_org_name = "cf-environment"
9+
# ------------------------------------------------------------------------------------------------------
10+
# Project specific configuration (please adapt!)
11+
# ------------------------------------------------------------------------------------------------------
12+
# To add extra users to the subaccount, the user running the script becomes the admin, without inclusion in admins.
13+
subaccount_admins = ["[email protected]", "[email protected]"]
14+
# To Create Cloudfoundry Org and add users with specific roles
15+
#------------------------------------------------------------------------------------------------------
16+
# Entitlements plan update
17+
#------------------------------------------------------------------------------------------------------
18+
# For production use of Business Application Studio, upgrade the plan from the `free-tier` to the appropriate plan e.g standard-edition
19+
bas_plan_name = "standard-edition"
20+
#-------------------------------------------------------------------------------------------------------
21+
#For production use of Build Workzone, upgrade the plan from the `free-tier` to the appropriate plan e.g standard
22+
build_workzone_plan_name = "standard"
23+
#--------------------------------------------------------------------------------------------------------
24+
# For production use of HANA, upgrade the plan from the `free-tier` to the appropriate plan e.g hana
25+
hana-cloud_plan_name = "hana"

0 commit comments

Comments
 (0)