-
Notifications
You must be signed in to change notification settings - Fork 34
chore: Update new sample for Cloudfoundry application runtime creation #343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
released/usecases/cf_enable_application_runtime_memory/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
62
released/usecases/cf_enable_application_runtime_memory/main.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
released/usecases/cf_enable_application_runtime_memory/provider.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
18 changes: 18 additions & 0 deletions
18
released/usecases/cf_enable_application_runtime_memory/sample.tfvars
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>" |
56 changes: 56 additions & 0 deletions
56
released/usecases/cf_enable_application_runtime_memory/variables.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "" | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.