Skip to content

Commit db3892f

Browse files
authored
chore: Update new sample for Cloudfoundry application runtime creation (#343)
* chore: Added new sample for CF application runtime * chore: update usecase * chore: update readme
1 parent 550a2b1 commit db3892f

File tree

5 files changed

+211
-0
lines changed

5 files changed

+211
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Set Up Subaccount with Cloudfoundry Application Runtime
2+
3+
## Overview
4+
5+
This sample shows how to create subaaccount and cloudfoundry environment instance with [Application Runtime](https://help.sap.com/docs/btp/sap-business-technology-platform/cloud-foundry-environment?q=cloudfoundry+application+runtime#commercial-information-for-cloud-foundry-runtime). To create cloudfoundry environment with free plan refer to this [Terraform Sample](https://github.com/SAP-samples/btp-terraform-samples/blob/main/released/discovery_center/mission_4327/step1/main.tf#L95).
6+
7+
## Content of setup
8+
9+
The setup comprises the following resources:
10+
11+
- Creation of a SAP BTP subaccount.
12+
- Add entitlement for cf_application_runtime with memory of 1024 MB (Change the memory limit according to your requirement, You can find it in main.tf)
13+
- Enable cloudfoundry runtime with standard plan.
14+
- Assign Subaccount Administrator role to the users.
15+
16+
## Deploying the resources
17+
18+
To deploy the resources you must:
19+
20+
1. Export the variables for user name and password
21+
22+
```bash
23+
export BTP_USERNAME='<Email address of your BTP user>'
24+
export BTP_PASSWORD='<Password of your BTP user>'
25+
export CF_USER='<Email address of your BTP user>'
26+
export CF_PASSWORD='<Password of your BTP user>'
27+
```
28+
29+
2. Change the variables in the `samples.tfvars` file to meet your requirements
30+
31+
> ⚠ NOTE: You should pay attention **specifically** to the users defined in the samples.tfvars whether they already exist in your SAP BTP accounts. Otherwise you might get error messages like e.g. `Error: The user could not be found: [email protected]`.
32+
33+
34+
3. Initialize your workspace:
35+
36+
```bash
37+
terraform init
38+
```
39+
40+
4. You can check what Terraform plans to apply based on your configuration:
41+
42+
```bash
43+
terraform plan -var-file="sample.tfvars"
44+
```
45+
46+
5. Apply your configuration to provision the resources:
47+
48+
```bash
49+
terraform apply -var-file="sample.tfvars"
50+
```
51+
52+
## In the end
53+
54+
You probably want to remove the assets after trying them out to avoid unnecessary costs. To do so execute the following command:
55+
56+
```bash
57+
terraform destroy
58+
```
59+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
###############################################################################################
2+
# Generating random ID for subdomain
3+
###############################################################################################
4+
resource "random_uuid" "uuid" {}
5+
6+
locals {
7+
random_uuid = random_uuid.uuid.result
8+
subaccount_domain = "memory-${local.random_uuid}"
9+
subaccount_cf_org = length(var.cf_org_name) > 0 ? var.cf_org_name : substr(replace("${local.subaccount_domain}", "-", ""), 0, 32)
10+
}
11+
12+
###############################################################################################
13+
# Creation of subaccount
14+
###############################################################################################
15+
resource "btp_subaccount" "project" {
16+
name = var.subaccount_name
17+
subdomain = local.subaccount_domain
18+
region = lower(var.region)
19+
}
20+
21+
data "btp_whoami" "me" {}
22+
23+
resource "btp_subaccount_entitlement" "cf_application_runtime" {
24+
subaccount_id = btp_subaccount.project.id
25+
service_name = "APPLICATION_RUNTIME"
26+
plan_name = "MEMORY"
27+
amount = 1
28+
}
29+
###############################################################################################
30+
# Creation of Cloud Foundry environment
31+
###############################################################################################
32+
resource "btp_subaccount_environment_instance" "cloudfoundry" {
33+
depends_on = [btp_subaccount_entitlement.cf_application_runtime]
34+
subaccount_id = btp_subaccount.project.id
35+
name = local.subaccount_cf_org
36+
landscape_label = var.cf_landscape_label
37+
environment_type = "cloudfoundry"
38+
service_name = "cloudfoundry"
39+
plan_name = "standard"
40+
# ATTENTION: some regions offer multiple environments of a kind and you must explicitly select the target environment in which
41+
# the instance shall be created using the parameter landscape label.
42+
# available environments can be looked up using the btp_subaccount_environments datasource
43+
parameters = jsonencode({
44+
instance_name = local.subaccount_cf_org
45+
memory = 1024
46+
})
47+
timeouts = {
48+
create = "1h"
49+
update = "35m"
50+
delete = "30m"
51+
}
52+
}
53+
54+
###############################################################################################
55+
# Assignment of users as sub account administrators
56+
###############################################################################################
57+
resource "btp_subaccount_role_collection_assignment" "subaccount-admins" {
58+
for_each = toset(var.subaccount_admins)
59+
subaccount_id = btp_subaccount.project.id
60+
role_collection_name = "Subaccount Administrator"
61+
user_name = each.value
62+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
terraform {
2+
required_providers {
3+
btp = {
4+
source = "sap/btp"
5+
version = "1.7.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+
idp = var.custom_idp
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# ------------------------------------------------------------------------------------------------------
2+
# Provider configuration
3+
# ------------------------------------------------------------------------------------------------------
4+
# Your global account subdomain
5+
globalaccount = "Myglobalaccount"
6+
# ------------------------------------------------------------------------------------------------------
7+
# Project specific configuration (please adapt!)
8+
# ------------------------------------------------------------------------------------------------------
9+
# Subaccount configuration
10+
region = "us10"
11+
subaccount_name = "<name for subaccount>"
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+
#------------------------------------------------------------------------------------------------------
15+
# Cloud Foundry
16+
#------------------------------------------------------------------------------------------------------
17+
# Choose a unique organization name e.g., based on the global account subdomain and subaccount name
18+
cf_org_name = "<unique org name>"
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
######################################################################
2+
# Customer account setup
3+
######################################################################
4+
# global account
5+
variable "globalaccount" {
6+
type = string
7+
description = "The globalaccount subdomain."
8+
}
9+
# subaccount
10+
variable "subaccount_name" {
11+
type = string
12+
description = "The subaccount name."
13+
}
14+
# Region
15+
variable "region" {
16+
type = string
17+
description = "The region where the project account shall be created in."
18+
default = "us10"
19+
}
20+
21+
# CLI server
22+
variable "cli_server_url" {
23+
type = string
24+
description = "The BTP CLI server URL."
25+
default = "https://cpcli.cf.eu10.hana.ondemand.com"
26+
}
27+
28+
# Custom IdP
29+
variable "custom_idp" {
30+
type = string
31+
description = "Custom IdP for provider login. Leave empty to use default SAP IdP."
32+
default = ""
33+
}
34+
35+
variable "subaccount_admins" {
36+
type = list(string)
37+
description = "Defines the colleagues who are added to each subaccount as subaccount administrators."
38+
default = []
39+
}
40+
41+
###
42+
# Cloud Foundry
43+
###
44+
45+
variable "cf_landscape_label" {
46+
type = string
47+
description = "The region where the project account shall be created in."
48+
default = "cf-us10"
49+
}
50+
51+
variable "cf_org_name" {
52+
type = string
53+
description = "The name for the Cloud Foundry Org."
54+
default = ""
55+
}
56+

0 commit comments

Comments
 (0)