diff --git a/released/usecases/cf_enable_application_runtime_memory/README.md b/released/usecases/cf_enable_application_runtime_memory/README.md new file mode 100644 index 00000000..a96e975d --- /dev/null +++ b/released/usecases/cf_enable_application_runtime_memory/README.md @@ -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='' + export BTP_PASSWORD='' + export CF_USER='' + export CF_PASSWORD='' + ``` + +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: jane.doe@test.com`. + + +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 +``` + diff --git a/released/usecases/cf_enable_application_runtime_memory/main.tf b/released/usecases/cf_enable_application_runtime_memory/main.tf new file mode 100644 index 00000000..87e44a05 --- /dev/null +++ b/released/usecases/cf_enable_application_runtime_memory/main.tf @@ -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 +} diff --git a/released/usecases/cf_enable_application_runtime_memory/provider.tf b/released/usecases/cf_enable_application_runtime_memory/provider.tf new file mode 100644 index 00000000..18c74094 --- /dev/null +++ b/released/usecases/cf_enable_application_runtime_memory/provider.tf @@ -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 +} diff --git a/released/usecases/cf_enable_application_runtime_memory/sample.tfvars b/released/usecases/cf_enable_application_runtime_memory/sample.tfvars new file mode 100644 index 00000000..44ef6287 --- /dev/null +++ b/released/usecases/cf_enable_application_runtime_memory/sample.tfvars @@ -0,0 +1,18 @@ +# ------------------------------------------------------------------------------------------------------ +# Provider configuration +# ------------------------------------------------------------------------------------------------------ +# Your global account subdomain +globalaccount = "Myglobalaccount" +# ------------------------------------------------------------------------------------------------------ +# Project specific configuration (please adapt!) +# ------------------------------------------------------------------------------------------------------ +# Subaccount configuration +region = "us10" +subaccount_name = "" +# To add extra users to the subaccount, the user running the script becomes the admin, without inclusion in admins. +subaccount_admins = ["joe.do@sap.com", "jane.do@sap.com"] +#------------------------------------------------------------------------------------------------------ +# Cloud Foundry +#------------------------------------------------------------------------------------------------------ +# Choose a unique organization name e.g., based on the global account subdomain and subaccount name +cf_org_name = "" diff --git a/released/usecases/cf_enable_application_runtime_memory/variables.tf b/released/usecases/cf_enable_application_runtime_memory/variables.tf new file mode 100644 index 00000000..45124749 --- /dev/null +++ b/released/usecases/cf_enable_application_runtime_memory/variables.tf @@ -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 = "" +} +