Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions released/usecases/cf_enable_application_runtime_memory/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Set Up Subaccount with Cloudfoundry Application Runtime

## Overview

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).

## Content of setup

The setup comprises the following resources:

- Creation of a SAP BTP subaccount.
- 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)
- Enable cloudfoundry runtime with standard plan.
- Assign Subaccount Administrator role to the users.

## Deploying the resources

To deploy the resources you must:

1. Export the variables for user name and password

```bash
export BTP_USERNAME='<Email address of your BTP user>'
export BTP_PASSWORD='<Password of your BTP user>'
export CF_USER='<Email address of your BTP user>'
export CF_PASSWORD='<Password of your BTP user>'
```

2. Change the variables in the `samples.tfvars` file to meet your requirements

> ⚠ 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]`.


3. Initialize your workspace:

```bash
terraform init
```

4. You can check what Terraform plans to apply based on your configuration:

```bash
terraform plan -var-file="sample.tfvars"
```

5. Apply your configuration to provision the resources:

```bash
terraform apply -var-file="sample.tfvars"
```

## In the end

You probably want to remove the assets after trying them out to avoid unnecessary costs. To do so execute the following command:

```bash
terraform destroy
```

62 changes: 62 additions & 0 deletions released/usecases/cf_enable_application_runtime_memory/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
###############################################################################################
# Generating random ID for subdomain
###############################################################################################
resource "random_uuid" "uuid" {}

locals {
random_uuid = random_uuid.uuid.result
subaccount_domain = "memory-${local.random_uuid}"
subaccount_cf_org = length(var.cf_org_name) > 0 ? var.cf_org_name : substr(replace("${local.subaccount_domain}", "-", ""), 0, 32)
}

###############################################################################################
# Creation of subaccount
###############################################################################################
resource "btp_subaccount" "project" {
name = var.subaccount_name
subdomain = local.subaccount_domain
region = lower(var.region)
}

data "btp_whoami" "me" {}

resource "btp_subaccount_entitlement" "cf_application_runtime" {
subaccount_id = btp_subaccount.project.id
service_name = "APPLICATION_RUNTIME"
plan_name = "MEMORY"
amount = 1
}
###############################################################################################
# Creation of Cloud Foundry environment
###############################################################################################
resource "btp_subaccount_environment_instance" "cloudfoundry" {
depends_on = [btp_subaccount_entitlement.cf_application_runtime]
subaccount_id = btp_subaccount.project.id
name = local.subaccount_cf_org
landscape_label = var.cf_landscape_label
environment_type = "cloudfoundry"
service_name = "cloudfoundry"
plan_name = "standard"
# ATTENTION: some regions offer multiple environments of a kind and you must explicitly select the target environment in which
# the instance shall be created using the parameter landscape label.
# available environments can be looked up using the btp_subaccount_environments datasource
parameters = jsonencode({
instance_name = local.subaccount_cf_org
memory = 1024
})
timeouts = {
create = "1h"
update = "35m"
delete = "30m"
}
}

###############################################################################################
# Assignment of users as sub account administrators
###############################################################################################
resource "btp_subaccount_role_collection_assignment" "subaccount-admins" {
for_each = toset(var.subaccount_admins)
subaccount_id = btp_subaccount.project.id
role_collection_name = "Subaccount Administrator"
user_name = each.value
}
16 changes: 16 additions & 0 deletions released/usecases/cf_enable_application_runtime_memory/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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
cli_server_url = var.cli_server_url
idp = var.custom_idp
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# ------------------------------------------------------------------------------------------------------
# Provider configuration
# ------------------------------------------------------------------------------------------------------
# Your global account subdomain
globalaccount = "Myglobalaccount"
# ------------------------------------------------------------------------------------------------------
# Project specific configuration (please adapt!)
# ------------------------------------------------------------------------------------------------------
# Subaccount configuration
region = "us10"
subaccount_name = "<name for subaccount>"
# To add extra users to the subaccount, the user running the script becomes the admin, without inclusion in admins.
subaccount_admins = ["[email protected]", "[email protected]"]
#------------------------------------------------------------------------------------------------------
# Cloud Foundry
#------------------------------------------------------------------------------------------------------
# Choose a unique organization name e.g., based on the global account subdomain and subaccount name
cf_org_name = "<unique org name>"
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
######################################################################
# Customer account setup
######################################################################
# global account
variable "globalaccount" {
type = string
description = "The globalaccount subdomain."
}
# subaccount
variable "subaccount_name" {
type = string
description = "The subaccount name."
}
# Region
variable "region" {
type = string
description = "The region where the project account shall be created in."
default = "us10"
}

# CLI server
variable "cli_server_url" {
type = string
description = "The BTP CLI server URL."
default = "https://cpcli.cf.eu10.hana.ondemand.com"
}

# Custom IdP
variable "custom_idp" {
type = string
description = "Custom IdP for provider login. Leave empty to use default SAP IdP."
default = ""
}

variable "subaccount_admins" {
type = list(string)
description = "Defines the colleagues who are added to each subaccount as subaccount administrators."
default = []
}

###
# Cloud Foundry
###

variable "cf_landscape_label" {
type = string
description = "The region where the project account shall be created in."
default = "cf-us10"
}

variable "cf_org_name" {
type = string
description = "The name for the Cloud Foundry Org."
default = ""
}