Skip to content

Add DC mission 4371 (genAI) #232

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 19 commits into from
Jul 11, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,4 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

.DS_Store
53 changes: 53 additions & 0 deletions released/discovery_center/mission_4371/step1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Discovery Center Mission: Develop a CAP-based (multitenant) application using GenAI and RAG (4371)

## Overview

This sample shows how to create a landscape for the Discovery Center Mission - [Develop a CAP-based (multitenant) application using GenAI and RAG](https://discovery-center.cloud.sap/missiondetail/4371/)

## Content of setup

The setup comprises the following resources:

- Creation of the SAP BTP subaccount
- Entitlements of services
- Subscriptions to applications
- Role collection assignments to users
- Management of users and roles on org and space level

## Deploying the resources

To deploy the resources you must:

1. Export environment variables BTP_USERNAME, BTP_PASSWORD, CF_USER, and CF_PASSWORD with your username and password for the custom IdP of your global account.

2. Change the variables in the `samples.tfvars` file in the main folder 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. Execute the apply.sh script.

4. Verify e.g., in BTP cockpit that a new subaccount with a integration suite, SAP Business Application Studio, CF environment instance and a CF space have been created.

```bash
terraform init
```

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

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

6. 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 -var-file="sample.tfvars"
```
211 changes: 211 additions & 0 deletions released/discovery_center/mission_4371/step1/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
# ------------------------------------------------------------------------------------------------------
# Setup of names in accordance to naming convention
# ------------------------------------------------------------------------------------------------------
resource "random_uuid" "uuid" {}

locals {
random_uuid = random_uuid.uuid.result
subaccount_domain = lower(replace("mission-4356-${local.random_uuid}", "_", "-"))
# If a cf_org_name was defined by the user, take that as a subaccount_cf_org. Otherwise create it.
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" "dc_mission" {
name = var.subaccount_name
subdomain = local.subaccount_domain
region = lower(var.region)
usage = "USED_FOR_PRODUCTION"
}

# ------------------------------------------------------------------------------------------------------
# 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.dc_mission.id
role_collection_name = "Subaccount Administrator"
user_name = each.value
}
# ------------------------------------------------------------------------------------------------------
# Assignment of users as sub account service administrators
# ------------------------------------------------------------------------------------------------------
resource "btp_subaccount_role_collection_assignment" "subaccount-service-admins" {
for_each = toset(var.subaccount_service_admins)
subaccount_id = btp_subaccount.dc_mission.id
role_collection_name = "Subaccount Service Administrator"
user_name = each.value
}


# ------------------------------------------------------------------------------------------------------
# Prepare & setup the SAP AI Core service (ensure your global account has the respective entitlements)
# ------------------------------------------------------------------------------------------------------

# Entitle subaccount for usage of SAP AI Core service
# ------------------------------------------------------------------------------------------------------
# Checkout https://github.com/SAP-samples/btp-service-metadata/blob/main/v0/developer/aicore.json for
# available plans and their region availability
resource "btp_subaccount_entitlement" "ai_core" {
subaccount_id = btp_subaccount.dc_mission.id
service_name = "aicore"
plan_name = var.ai_core_plan_name
}

# Get plan for SAP AI Core service
data "btp_subaccount_service_plan" "ai_core" {
subaccount_id = btp_subaccount.dc_mission.id
offering_name = "aicore"
name = var.ai_core_plan_name
depends_on = [btp_subaccount_entitlement.ai_core]
}

# Create service instance for SAP AI Core service
resource "btp_subaccount_service_instance" "ai_core" {
subaccount_id = btp_subaccount.dc_mission.id
serviceplan_id = data.btp_subaccount_service_plan.ai_core.id
name = "my-ai-core-instance"
depends_on = [btp_subaccount_entitlement.ai_core]
}

# Create service binding to SAP AI Core service (exposed for a specific user group)
resource "btp_subaccount_service_binding" "ai_core_binding" {
subaccount_id = btp_subaccount.dc_mission.id
service_instance_id = btp_subaccount_service_instance.ai_core.id
name = "ai-core-key"
}


# ------------------------------------------------------------------------------------------------------
# Entitle subaccount for usage of SAP HANA Cloud tools
# ------------------------------------------------------------------------------------------------------
resource "btp_subaccount_entitlement" "hana_cloud_tools" {
subaccount_id = btp_subaccount.dc_mission.id
service_name = "hana-cloud-tools"
plan_name = "tools"
}

resource "btp_subaccount_subscription" "hana_cloud_tools" {
subaccount_id = btp_subaccount.dc_mission.id
app_name = "hana-cloud-tools"
plan_name = "tools"
depends_on = [btp_subaccount_entitlement.hana_cloud_tools]
}

# Assign users to Role Collection: SAP HANA Cloud Administrator
resource "btp_subaccount_role_collection_assignment" "hana_cloud_admin" {
for_each = toset(var.hana_cloud_admins)
subaccount_id = btp_subaccount.dc_mission.id
role_collection_name = "SAP HANA Cloud Administrator"
user_name = each.value
depends_on = [btp_subaccount_subscription.hana_cloud_tools]
}

# ------------------------------------------------------------------------------------------------------
# Entitle subaccount for usage of SAP HANA Cloud
# ------------------------------------------------------------------------------------------------------
resource "btp_subaccount_entitlement" "hana_cloud" {
subaccount_id = btp_subaccount.dc_mission.id
service_name = "hana-cloud"
plan_name = "hana"
}

# Get plan for SAP HANA Cloud
data "btp_subaccount_service_plan" "hana_cloud" {
subaccount_id = btp_subaccount.dc_mission.id
offering_name = "hana-cloud"
name = "hana"
depends_on = [btp_subaccount_entitlement.hana_cloud]
}

resource "btp_subaccount_service_instance" "hana_cloud" {
subaccount_id = btp_subaccount.dc_mission.id
serviceplan_id = data.btp_subaccount_service_plan.hana_cloud.id
name = "my-hana-cloud-instance"
depends_on = [btp_subaccount_entitlement.hana_cloud]
parameters = jsonencode(
{
"data" : {
"memory" : 32,
"edition" : "cloud",
"systempassword" : "${var.hana_system_password}",
"additionalWorkers" : 0,
"disasterRecoveryMode" : "no_disaster_recovery",
"enabledservices" : {
"docstore" : false,
"dpserver" : true,
"scriptserver" : false
},
"requestedOperation" : {},
"serviceStopped" : false,
"slaLevel" : "standard",
"storage" : 120,
"vcpu" : 2,
"whitelistIPs" : ["0.0.0.0/0"]
}
})

timeouts = {
create = "45m"
update = "45m"
delete = "45m"
}
}

# Create service binding to SAP HANA Cloud service
resource "btp_subaccount_service_binding" "hana_cloud" {
subaccount_id = btp_subaccount.dc_mission.id
service_instance_id = btp_subaccount_service_instance.hana_cloud.id
name = "hana-cloud-key"
}



# ------------------------------------------------------------------------------------------------------
# CLOUDFOUNDRY PREPARATION
# ------------------------------------------------------------------------------------------------------
#
# Fetch all available environments for the subaccount
data "btp_subaccount_environments" "all" {
subaccount_id = btp_subaccount.dc_mission.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" "replacement" {
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.dc_mission.id
name = local.subaccount_cf_org
environment_type = "cloudfoundry"
service_name = "cloudfoundry"
plan_name = "standard"
landscape_label = terraform_data.replacement.output
parameters = jsonencode({
instance_name = local.subaccount_cf_org
})
}
# ------------------------------------------------------------------------------------------------------
# Create tfvars file for step 2 (if variable `create_tfvars_file_for_step2` is set to true)
# ------------------------------------------------------------------------------------------------------
resource "local_file" "output_vars_step1" {
count = var.create_tfvars_file_for_step2 ? 1 : 0
content = <<-EOT
subaccount_id = "${btp_subaccount.dc_mission.id}"
cf_api_url = "${jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["API Endpoint"]}"
cf_org_id = "${jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["Org ID"]}"
origin = "${var.origin}"
cf_space_name = "${var.cf_space_name}"
cf_org_admins = ${jsonencode(var.cf_org_admins)}
cf_org_users = ${jsonencode(var.cf_org_users)}
cf_space_developers = ${jsonencode(var.cf_space_developers)}
cf_space_managers = ${jsonencode(var.cf_space_managers)}
EOT
filename = "../step2/terraform.tfvars"
}
19 changes: 19 additions & 0 deletions released/discovery_center/mission_4371/step1/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
output "subaccount_id" {
value = btp_subaccount.dc_mission.id
description = "The ID of the subaccount."
}

output "cf_api_url" {
value = jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["API Endpoint"]
description = "The Cloudfoundry API endpoint."
}

output "cf_landscape_label" {
value = terraform_data.replacement.output
description = "The Cloudfoundry landscape label."
}

output "cf_org_id" {
value = jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["Org ID"]
description = "The Cloudfoundry org id."
}
16 changes: 16 additions & 0 deletions released/discovery_center/mission_4371/step1/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# ------------------------------------------------------------------------------------------------------
# Define the required providers for this module
# ------------------------------------------------------------------------------------------------------
terraform {
required_providers {
btp = {
source = "sap/btp"
version = "~> 1.4.0"
}
}
}

provider "btp" {
globalaccount = var.globalaccount
cli_server_url = var.cli_server_url
}
25 changes: 25 additions & 0 deletions released/discovery_center/mission_4371/step1/samples.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# ------------------------------------------------------------------------------------------------------
# Provider configuration
# ------------------------------------------------------------------------------------------------------
# Your global account subdomain
globalaccount = "yourglobalaccount"
region = "us10"
subaccount_name = "SAP Discovery Center Mission 4371"
custom_idp = "sap.ids"

# ------------------------------------------------------------------------------------------------------
# Project specific configuration (please adapt!)
# ------------------------------------------------------------------------------------------------------

# Don't add the user, that is executing the TF script to subaccount_admins or subaccount_service_admins!
subaccount_admins = ["another.user@test.com"]
subaccount_service_admins = ["another.user@test.com"]

hana_cloud_admins = ["another.user@test.com"]
hana_system_password = "Abc12345"

# Don't add the user, that is executing the TF script to cf_org_admins or cf_org_users!
cf_org_admins = ["another.user@test.com"]
cf_org_users = ["another.user@test.com"]
cf_space_managers = ["another.user@test.com", "you@test.com"]
cf_space_developers = ["another.user@test.com", "you@test.com"]
Loading