Skip to content

Commit db14966

Browse files
committed
QAS Polished and few fixes
1 parent 60c1ab7 commit db14966

File tree

10 files changed

+241
-131
lines changed

10 files changed

+241
-131
lines changed

released/discovery_center/mission_4371/step1/README.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Discovery Center Mission: Develop a CAP-based (multitenant) application using GenAI and RAG (4371)
1+
# Discovery Center Mission: Develop a CAP-based (multitenant) application using GenAI and RAG (4371) - Step 1
22

33
## Overview
44

@@ -18,27 +18,35 @@ The setup comprises the following resources:
1818

1919
To deploy the resources you must:
2020

21-
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.
21+
1. Set your credentials as environment variables
22+
23+
```bash
24+
export BTP_USERNAME ='<Email address of your BTP user>'
25+
export BTP_PASSWORD ='<Password of your BTP user>'
26+
export CF_USER ='<Email address of your BTP user>'
27+
export CF_PASSWORD ='<Password of your BTP user>'
28+
```
29+
30+
2. Change the variables in the `sample.tfvars` file in the main folder to meet your requirements
2231

23-
2. Change the variables in the `samples.tfvars` file in the main folder to meet your requirements
32+
> The minimal set of parameters you should specify (besides user_email and password) is global account (i.e. its subdomain) and the used custom_idp and all user assignments
2433
25-
> ⚠ 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]`.
34+
> ⚠ NOTE: You should pay attention **specifically** to the users defined in the sample.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]`.
2635
27-
3. Execute the apply.sh script.
2836

29-
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.
37+
3. Initialize your workspace:
3038

3139
```bash
3240
terraform init
3341
```
3442

35-
5. You can check what Terraform plans to apply based on your configuration:
43+
4. You can check what Terraform plans to apply based on your configuration:
3644

3745
```bash
3846
terraform plan -var-file="sample.tfvars"
3947
```
4048

41-
6. Apply your configuration to provision the resources:
49+
5. Apply your configuration to provision the resources:
4250

4351
```bash
4452
terraform apply -var-file="sample.tfvars"
@@ -50,4 +58,4 @@ You probably want to remove the assets after trying them out to avoid unnecessar
5058

5159
```bash
5260
terraform destroy -var-file="sample.tfvars"
53-
```
61+
```

released/discovery_center/mission_4371/step1/main.tf

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,30 @@ resource "btp_subaccount" "dc_mission" {
1919
usage = "USED_FOR_PRODUCTION"
2020
}
2121

22+
# ------------------------------------------------------------------------------------------------------
23+
# Assign custom IDP to sub account (if custom_idp is set)
24+
# ------------------------------------------------------------------------------------------------------
25+
resource "btp_subaccount_trust_configuration" "fully_customized" {
26+
# Only create trust configuration if custom_idp has been set
27+
count = var.custom_idp == "" ? 0 : 1
28+
subaccount_id = btp_subaccount.dc_mission.id
29+
identity_provider = var.custom_idp
30+
}
31+
32+
locals {
33+
custom_idp_tenant = var.custom_idp != "" ? element(split(".", var.custom_idp), 0) : ""
34+
origin_key = local.custom_idp_tenant != "" ? "${local.custom_idp_tenant}-platform" : "sap.default"
35+
origin_key_app_users = var.custom_idp != "" ? var.custom_idp_apps_origin_key : "sap.default"
36+
}
37+
2238
# ------------------------------------------------------------------------------------------------------
2339
# Assignment of users as sub account administrators
2440
# ------------------------------------------------------------------------------------------------------
2541
resource "btp_subaccount_role_collection_assignment" "subaccount-admins" {
2642
for_each = toset(var.subaccount_admins)
2743
subaccount_id = btp_subaccount.dc_mission.id
2844
role_collection_name = "Subaccount Administrator"
45+
origin = local.origin_key
2946
user_name = each.value
3047
}
3148
# ------------------------------------------------------------------------------------------------------
@@ -35,6 +52,7 @@ resource "btp_subaccount_role_collection_assignment" "subaccount-service-admins"
3552
for_each = toset(var.subaccount_service_admins)
3653
subaccount_id = btp_subaccount.dc_mission.id
3754
role_collection_name = "Subaccount Service Administrator"
55+
origin = local.origin_key
3856
user_name = each.value
3957
}
4058

@@ -76,6 +94,56 @@ resource "btp_subaccount_service_binding" "ai_core_binding" {
7694
name = "ai-core-key"
7795
}
7896

97+
# ------------------------------------------------------------------------------------------------------
98+
# Setup destination
99+
# ------------------------------------------------------------------------------------------------------
100+
# Entitle
101+
resource "btp_subaccount_entitlement" "destination" {
102+
subaccount_id = btp_subaccount.dc_mission.id
103+
service_name = "destination"
104+
plan_name = "lite"
105+
}
106+
107+
data "btp_subaccount_service_plan" "destination" {
108+
subaccount_id = btp_subaccount.dc_mission.id
109+
offering_name = "destination"
110+
name = "lite"
111+
depends_on = [btp_subaccount_entitlement.destination]
112+
}
113+
114+
# Create service instance
115+
resource "btp_subaccount_service_instance" "destination" {
116+
subaccount_id = btp_subaccount.dc_mission.id
117+
serviceplan_id = data.btp_subaccount_service_plan.destination.id
118+
name = "destination"
119+
depends_on = [btp_subaccount_service_binding.ai_core_binding, data.btp_subaccount_service_plan.destination]
120+
parameters = jsonencode({
121+
HTML5Runtime_enabled = true
122+
init_data = {
123+
subaccount = {
124+
existing_destinations_policy = "update"
125+
destinations = [
126+
# This is the destination to the ai-core binding
127+
{
128+
Description = "[Do not delete] PROVIDER_AI_CORE_DESTINATION_HUB"
129+
Type = "HTTP"
130+
clientId = "${jsondecode(btp_subaccount_service_binding.ai_core_binding.credentials)["clientid"]}"
131+
clientSecret = "${jsondecode(btp_subaccount_service_binding.ai_core_binding.credentials)["clientsecret"]}"
132+
"HTML5.DynamicDestination" = true
133+
"HTML5.Timeout" = 5000
134+
Authentication = "OAuth2ClientCredentials"
135+
Name = "PROVIDER_AI_CORE_DESTINATION_HUB"
136+
tokenServiceURL = "${jsondecode(btp_subaccount_service_binding.ai_core_binding.credentials)["url"]}/oauth/token"
137+
ProxyType = "Internet"
138+
URL = "${jsondecode(btp_subaccount_service_binding.ai_core_binding.credentials)["serviceurls"]["AI_API_URL"]}/v2"
139+
tokenServiceURLType = "Dedicated"
140+
}
141+
]
142+
}
143+
}
144+
})
145+
}
146+
79147

80148
# ------------------------------------------------------------------------------------------------------
81149
# Entitle subaccount for usage of SAP HANA Cloud tools
@@ -95,11 +163,11 @@ resource "btp_subaccount_subscription" "hana_cloud_tools" {
95163

96164
# Assign users to Role Collection: SAP HANA Cloud Administrator
97165
resource "btp_subaccount_role_collection_assignment" "hana_cloud_admin" {
98-
for_each = toset(var.hana_cloud_admins)
99166
subaccount_id = btp_subaccount.dc_mission.id
100167
role_collection_name = "SAP HANA Cloud Administrator"
101-
user_name = each.value
168+
user_name = var.hana_system_admin
102169
depends_on = [btp_subaccount_subscription.hana_cloud_tools]
170+
origin = local.origin_key_app_users
103171
}
104172

105173
# ------------------------------------------------------------------------------------------------------
@@ -197,10 +265,11 @@ resource "btp_subaccount_environment_instance" "cloudfoundry" {
197265
resource "local_file" "output_vars_step1" {
198266
count = var.create_tfvars_file_for_step2 ? 1 : 0
199267
content = <<-EOT
268+
globalaccount = "${var.globalaccount}"
200269
subaccount_id = "${btp_subaccount.dc_mission.id}"
201270
cf_api_url = "${jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["API Endpoint"]}"
202271
cf_org_id = "${jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["Org ID"]}"
203-
origin = "${var.origin}"
272+
custom_idp = ${jsonencode(var.custom_idp)}
204273
cf_space_name = "${var.cf_space_name}"
205274
cf_org_admins = ${jsonencode(var.cf_org_admins)}
206275
cf_org_users = ${jsonencode(var.cf_org_users)}

released/discovery_center/mission_4371/step1/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ output "cf_org_id" {
1717
value = jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["Org ID"]
1818
description = "The Cloudfoundry org id."
1919
}
20+
21+
output "hana_cloud_tools_url" {
22+
value = btp_subaccount_subscription.hana_cloud_tools.subscription_url
23+
}

released/discovery_center/mission_4371/step1/provider.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ terraform {
55
required_providers {
66
btp = {
77
source = "sap/btp"
8-
version = "~> 1.5.0"
8+
version = "~> 1.6.0"
99
}
1010
}
1111
}

released/discovery_center/mission_4371/step1/samples.tfvars

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
globalaccount = "yourglobalaccount"
66
region = "us10"
77
subaccount_name = "SAP Discovery Center Mission 4371"
8-
custom_idp = "sap.ids"
8+
custom_idp = "<your_idp>.accounts.ondemand.com"
99

1010
# ------------------------------------------------------------------------------------------------------
1111
# Project specific configuration (please adapt!)
@@ -15,7 +15,7 @@ custom_idp = "sap.ids"
1515
subaccount_admins = ["[email protected]"]
1616
subaccount_service_admins = ["[email protected]"]
1717

18-
hana_cloud_admins = ["[email protected]"]
18+
hana_system_admin = "[email protected]"
1919
hana_system_password = "Abc12345"
2020

2121
# Don't add the user, that is executing the TF script to cf_org_admins or cf_org_users!

released/discovery_center/mission_4371/step1/variables.tf

Lines changed: 32 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,39 @@ variable "cli_server_url" {
1313
default = "https://cli.btp.cloud.sap"
1414
}
1515

16+
variable "custom_idp" {
17+
type = string
18+
description = "The custom identity provider for the subaccount."
19+
default = ""
20+
}
21+
22+
variable "custom_idp_apps_origin_key" {
23+
type = string
24+
description = "The custom identity provider for the subaccount."
25+
default = "sap.custom"
26+
}
27+
28+
variable "origin" {
29+
type = string
30+
description = "Defines the origin key of the identity provider"
31+
default = "sap.ids"
32+
# The value for the origin_key can be defined
33+
# but are normally set to "sap.ids", "sap.default" or "sap.custom"
34+
}
35+
36+
variable "origin_key" {
37+
type = string
38+
description = "Defines the origin key of the identity provider"
39+
default = ""
40+
# The value for the origin_key can be defined, set to "sap.ids", "sap.default" or "sap.custom"
41+
}
42+
43+
1644
# subaccount
1745
variable "subaccount_name" {
1846
type = string
1947
description = "The subaccount name."
20-
default = "SAP Discovery Center Mission 3774 - Central Inbox with SAP Task Center"
48+
default = "SAP Discovery Center Mission 4371"
2149
}
2250
variable "subaccount_id" {
2351
type = string
@@ -28,25 +56,11 @@ variable "subaccount_id" {
2856
variable "subaccount_admins" {
2957
type = list(string)
3058
description = "Defines the colleagues who are added to each subaccount as subaccount administrators."
31-
32-
33-
# add validation to check if admins contains a list of valid email addresses
34-
validation {
35-
condition = length([for email in var.subaccount_admins : can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", email))]) == length(var.subaccount_admins)
36-
error_message = "Please enter a valid email address for the CF space managers."
37-
}
3859
}
3960

4061
variable "subaccount_service_admins" {
4162
type = list(string)
4263
description = "Defines the colleagues who are added to each subaccount as subaccount service administrators."
43-
44-
45-
# add validation to check if admins contains a list of valid email addresses
46-
validation {
47-
condition = length([for email in var.subaccount_service_admins : can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", email))]) == length(var.subaccount_service_admins)
48-
error_message = "Please enter a valid email address for the CF space managers."
49-
}
5064
}
5165

5266
variable "region" {
@@ -63,28 +77,16 @@ variable "region" {
6377
}
6478

6579

66-
variable "hana_cloud_admins" {
67-
type = list(string)
80+
variable "hana_system_admin" {
81+
type = string
6882
description = "Defines the colleagues who are added as admins to access the instance of SAP HANA Cloud."
69-
70-
71-
# add validation to check if admins contains a list of valid email addresses
72-
validation {
73-
condition = length([for email in var.hana_cloud_admins : can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", email))]) == length(var.hana_cloud_admins)
74-
error_message = "Please enter a valid email address for the admins of SAP HANA Cloud instance."
75-
}
7683
}
7784

78-
variable "custom_idp" {
79-
type = string
80-
description = "Defines the custom IdP"
81-
default = ""
82-
}
8385

8486
variable "create_tfvars_file_for_step2" {
8587
type = bool
8688
description = "Switch to enable the creation of the tfvars file for step 2."
87-
default = false
89+
default = true
8890
}
8991

9092
variable "ai_core_plan_name" {
@@ -127,19 +129,6 @@ variable "hana_system_password" {
127129
}
128130
}
129131

130-
variable "target_ai_core_model" {
131-
type = list(any)
132-
description = "Defines the target AI core model to be used by the AI Core service"
133-
default = ["gpt-35-turbo"]
134-
135-
validation {
136-
condition = length([
137-
for o in var.target_ai_core_model : true
138-
if contains(["gpt-35-turbo", "gpt-35-turbo-0125", "gpt-35-turbo-16k", "gpt-4", "gpt-4-32k", "text-embedding-ada-002", "gemini-1.0-pro", "text-bison", "chat-bison", "textembedding-gecko-multilingual", "textembedding-gecko", "tiiuae--falcon-40b-instruct"], o)
139-
]) == length(var.target_ai_core_model)
140-
error_message = "Please enter a valid entry for the target_ai_core_model of the AI Core service. Valid values are: gpt-35-turbo, gpt-35-turbo-16k, gpt-4, gpt-4-32k, text-embedding-ada-002, tiiuae--falcon-40b-instruct."
141-
}
142-
}
143132

144133
variable "cf_landscape_label" {
145134
type = string
@@ -162,53 +151,21 @@ variable "cf_space_name" {
162151
variable "cf_space_developers" {
163152
type = list(string)
164153
description = "CF Space developers"
165-
166-
# add validation to check if CF Space developers contains a list of valid email addresses
167-
validation {
168-
condition = length([for email in var.cf_space_developers : can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", email))]) == length(var.cf_space_developers)
169-
error_message = "Please enter a valid email address for the CF Space developers."
170-
}
171154
}
172155

173156
variable "cf_space_managers" {
174157
type = list(string)
175158
description = "CF Space managers"
176-
177-
# add validation to check if CF Space managers contains a list of valid email addresses
178-
validation {
179-
condition = length([for email in var.cf_space_managers : can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", email))]) == length(var.cf_space_managers)
180-
error_message = "Please enter a valid email address for the Cloud Connector Administrators."
181-
}
182159
}
183160

184161
variable "cf_org_admins" {
185162
type = list(string)
186163
description = "CF Org Admins"
187-
188-
# add validation to check if CF Org Admins contains a list of valid email addresses
189-
validation {
190-
condition = length([for email in var.cf_org_admins : can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", email))]) == length(var.cf_org_admins)
191-
error_message = "Please enter a valid email address for the CF Org Admins."
192-
}
193164
}
194165

195166
variable "cf_org_users" {
196167
type = list(string)
197168
description = "CF Org Users"
198-
199-
# add validation to check if CF Org Users contains a list of valid email addresses
200-
validation {
201-
condition = length([for email in var.cf_org_users : can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", email))]) == length(var.cf_org_users)
202-
error_message = "Please enter a valid email address for the CF Org Users."
203-
}
204-
}
205-
206-
variable "origin" {
207-
type = string
208-
description = "Defines the origin key of the identity provider"
209-
default = "sap.ids"
210-
# The value for the origin_key can be defined
211-
# but are normally set to "sap.ids", "sap.default" or "sap.custom"
212169
}
213170

214171
variable "cf_org_name" {

0 commit comments

Comments
 (0)