Skip to content

Chore: Update DC Mission 4327 #276

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
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
78 changes: 78 additions & 0 deletions released/discovery_center/mission_4327/step1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Set Up SAP BTP Account using Terraform – Cloud Foundry

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.

Currently, the SAP BTP provider is available in beta for non productive usage: [SAP BTP Terraform](https://registry.terraform.io/providers/SAP/btp/latest).

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:

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).
2. Enables the SAP BTP runtime (Cloud Foundry or Kyma).
3. Creates the neccessary subscription to applications: SAP Business Application Studio (BAS), SAP Build Work Zone, standard edition, etc.
4. Assigns users the neccessary roles required to access the applications, such as SAP Business Application Studio.
5. Adds additional users to the subaccount.
### [Entitlements ](https://github.tools.sap/refapps/incidents-mgmt/blob/main/documentation/administrate/Prepare-BTP/Configure-BTP-CF.md)

| Service | Plan | Quota required |
| ------------- | :-----------: | ----: |
| Cloud Foundry Runtime | MEMORY | 1 |
| SAP Build Work Zone, standard edition | Standard | 1 |
| SAP HANA Cloud | hana | 1 |
| SAP HANA Cloud | tools | 1 |
| SAP HANA Schemas & HDI Containers | hdi-shared | 1 |

## Deploy the resources

To deploy the resources you must:
1. Clone repository `git clone https://github.com/SAP-samples/btp-terraform-samples.git`
2. Navigate to `released/discovery_center/mission_4327/setup_subaccount_cf`
3. You will be seeing these files named `main.tf`,`provider.tf`,`samples.tfvars`,`variables.tf`.
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)
Follow these steps to use the script:
5. Set `BTP_USERNAME`,`BTP_PASSWORD`,`CF_USER` and `CF_PASSWORD` as ENV variables.

Windows PowerShell:
```Powershell
$env:BTP_USERNAME="<your email address>"
$env:BTP_PASSWORD="<your password>"
$env:CF_USER="<your email address>"
$env:CF_PASSWORD="<your password>"
```
Linux, macOS:
```mac OS
export BTP_USERNAME="<your email address>"
export BTP_PASSWORD="<your password>"
export CF_USER="<your email address>"
export CF_PASSWORD="<your password>"
```
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:

```shell
terraform init
```

7. **Review Changes**: Generate an execution plan to review the changes that will be made to your SAP BTP account. Run:

```shell
terraform plan
```

8. **Apply Configuration**: Apply the Terraform configuration to create the SAP BTP subaccount and entitlements. Run:

```shell
terraform apply
```

Confirm the changes by typing "yes."

9. **Cleanup**: After your session or project is complete, you can delete the SAP BTP subaccount and associated resources to avoid charges:

```shell
terraform destroy
```

Confirm the resource destruction by typing "yes."

11. **Optional**: You can remove the Terraform state file (`terraform.tfstate`) manually if needed.

Please exercise caution when using this script, especially in production environments, and ensure you understand the resources that will be created or modified.
129 changes: 129 additions & 0 deletions released/discovery_center/mission_4327/step1/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
###############################################################################################
# Generating random ID for subdomain
###############################################################################################
resource "random_uuid" "uuid" {}
###############################################################################################
# Creation of subaccount
###############################################################################################
resource "btp_subaccount" "project" {
name = var.subaccount_name
subdomain = "btp-gp${random_uuid.uuid.result}"
region = lower(var.region)
}
data "btp_whoami" "me" {}

data "btp_subaccount_environments" "all" {
subaccount_id = btp_subaccount.project.id
}
# ------------------------------------------------------------------------------------------------------
# Take the landscape label from the first CF environment if no environment label is provided
# (this replaces the previous null_resource)
# ------------------------------------------------------------------------------------------------------
resource "terraform_data" "cf_landscape_label" {
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
}
###############################################################################################
# Creation of Cloud Foundry environment
###############################################################################################
resource "btp_subaccount_environment_instance" "cloudfoundry" {
subaccount_id = btp_subaccount.project.id
name = btp_subaccount.project.subdomain
landscape_label = terraform_data.cf_landscape_label.output
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 = btp_subaccount.project.subdomain
})
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
}
######################################################################
# Add entitlement for BAS, Subscribe BAS and add roles
######################################################################
resource "btp_subaccount_entitlement" "bas" {
subaccount_id = btp_subaccount.project.id
service_name = "sapappstudio"
plan_name = var.bas_plan_name
}
resource "btp_subaccount_subscription" "bas-subscribe" {
subaccount_id = btp_subaccount.project.id
app_name = "sapappstudio"
plan_name = var.bas_plan_name
depends_on = [btp_subaccount_entitlement.bas]
}
resource "btp_subaccount_role_collection_assignment" "Business_Application_Studio_Administrator" {
subaccount_id = btp_subaccount.project.id
role_collection_name = "Business_Application_Studio_Administrator"
user_name = data.btp_whoami.me.email
depends_on = [btp_subaccount_subscription.bas-subscribe]
}


resource "btp_subaccount_role_collection_assignment" "Business_Application_Studio_Developer" {
subaccount_id = btp_subaccount.project.id
role_collection_name = "Business_Application_Studio_Developer"
user_name = data.btp_whoami.me.email
depends_on = [btp_subaccount_subscription.bas-subscribe]
}
######################################################################
# Add Build Workzone entitlement subscription and role Assignment
######################################################################
resource "btp_subaccount_entitlement" "build_workzone" {
subaccount_id = btp_subaccount.project.id
service_name = "SAPLaunchpad"
plan_name = var.build_workzone_plan_name
}
resource "btp_subaccount_subscription" "build_workzone_subscribe" {
subaccount_id = btp_subaccount.project.id
app_name = "SAPLaunchpad"
plan_name = var.build_workzone_plan_name
depends_on = [btp_subaccount_entitlement.build_workzone]
}
resource "btp_subaccount_role_collection_assignment" "launchpad_admin" {
subaccount_id = btp_subaccount.project.id
role_collection_name = "Launchpad_Admin"
user_name = data.btp_whoami.me.email
depends_on = [btp_subaccount_subscription.build_workzone_subscribe]
}
######################################################################
# Create HANA entitlement subscription
######################################################################
resource "btp_subaccount_entitlement" "hana-cloud" {
subaccount_id = btp_subaccount.project.id
service_name = "hana-cloud"
plan_name = var.hana-cloud_plan_name
}
# Enable HANA Cloud Tools
resource "btp_subaccount_entitlement" "hana-cloud-tools" {
subaccount_id = btp_subaccount.project.id
service_name = "hana-cloud-tools"
plan_name = "tools"
}
resource "btp_subaccount_subscription" "hana-cloud-tools" {
subaccount_id = btp_subaccount.project.id
app_name = "hana-cloud-tools"
plan_name = "tools"
depends_on = [btp_subaccount_entitlement.hana-cloud-tools]
}
resource "btp_subaccount_entitlement" "hana-hdi-shared" {
subaccount_id = btp_subaccount.project.id
service_name = "hana"
plan_name = "hdi-shared"
}
15 changes: 15 additions & 0 deletions released/discovery_center/mission_4327/step1/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
terraform {
required_providers {
btp = {
source = "sap/btp"
version = "1.5.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
}
25 changes: 25 additions & 0 deletions released/discovery_center/mission_4327/step1/samples.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# ------------------------------------------------------------------------------------------------------
# Provider configuration
# ------------------------------------------------------------------------------------------------------
# Your global account subdomain
globalaccount = "myglobalaccount"
region = "us10"
subaccount_name = "DCM Goldenpath"
cf_org_name = "cf-environment"
# ------------------------------------------------------------------------------------------------------
# Project specific configuration (please adapt!)
# ------------------------------------------------------------------------------------------------------
# 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"]
# To Create Cloudfoundry Org and add users with specific roles
#------------------------------------------------------------------------------------------------------
# Entitlements plan update
#------------------------------------------------------------------------------------------------------
# For production use of Business Application Studio, upgrade the plan from the `free-tier` to the appropriate plan e.g standard-edition
bas_plan_name = "standard-edition"
#-------------------------------------------------------------------------------------------------------
#For production use of Build Workzone, upgrade the plan from the `free-tier` to the appropriate plan e.g standard
build_workzone_plan_name = "standard"
#--------------------------------------------------------------------------------------------------------
# For production use of HANA, upgrade the plan from the `free-tier` to the appropriate plan e.g hana
hana-cloud_plan_name = "hana"
120 changes: 120 additions & 0 deletions released/discovery_center/mission_4327/step1/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
######################################################################
# Customer account setup
######################################################################
# subaccount
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"
}

variable "subaccount_admins" {
type = list(string)
description = "Defines the colleagues who are added to each subaccount as subaccount administrators."
default = ["jane.doe@test.com", "john.doe@test.com"]
}

#cf_landscape_label
variable "cf_landscape_label" {
type = string
description = "The region where the project account shall be created in."
default = "us10"
}
###
# Entitlements
###
variable "entitlements" {
type = list(object({
service_name = string
plan_name = string
type = string
}))
description = "The list of entitlements that shall be added to the subaccount."
default = [
{
service_name = "connectivity"
plan_name = "lite",
type = "service"
},
{
service_name = "destination"
plan_name = "lite",
type = "service"
},
{
service_name = "html5-apps-repo"
plan_name = "app-host",
type = "service"
},
{
service_name = "sapappstudio"
plan_name = "standard-edition",
type = "app"
},
{
service_name = "enterprise-messaging"
plan_name = "default",
type = "service"
},
{
service_name = "enterprise-messaging-hub"
plan_name = "standard",
type = "app"
},
{
service_name = "privatelink"
plan_name = "standard",
type = "service"
},
{
service_name = "xsuaa"
plan_name = "application",
type = "service"
},
{
service_name = "hana"
plan_name = "hdi-shared",
type = "service"
},
{
service_name = "hana-cloud"
plan_name = "hana",
type = "service"
}
]
}
# Plan_name update
variable "bas_plan_name" {
description = "BAS plan"
type = string
default = "free-tier"
}

variable "build_workzone_plan_name" {
description = "Build Workzone plan"
type = string
default = "free-tier"
}

variable "hana-cloud_plan_name" {
description = "hana-cloud plan"
type = string
default = "free"
}
Loading
Loading