Skip to content

Commit 8b77ff4

Browse files
committed
4441_trial: Polishing the QAS enabled Mission
- polished code to be consistent with other QAS missions (like 4024 or 3585)
1 parent ba5935f commit 8b77ff4

File tree

5 files changed

+105
-55
lines changed

5 files changed

+105
-55
lines changed

released/discovery_center/mission_4441_trial/README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,23 @@
22

33
## Overview
44

5-
This sample shows how to create a landscape for the Discovery Center Mission - [Get Started with SAP Build Code and Joule using Generative AI](https://discovery-center.cloud.sap/missiondetail/4441/) for a Trial account.
5+
This sample shows how to setup your SAP BTP account for the Discovery Center Mission - [Get Started with SAP Build Code and Joule using Generative AI](https://discovery-center.cloud.sap/missiondetail/4441/) for your trial account.
6+
7+
The respective setup of an Enterprise account is described in [SAP-samples/btp-terraform-samples/tree/main/released/discovery_center/mission_4441/README.md](https://github.com/SAP-samples/btp-terraform-samples/blob/main/released/discovery_center/mission_4441/full_setup_enterprise/step1/README.md)
8+
9+
## Important: Trial Account Prerequisites
10+
Contrary to an Enterprise account (where the setup will happen in a newly created subaccount, where entitlements are added), we make the assumption that in your trial account there is already a subaccount (by default named 'trial') with all the required service entitlements and not already in use!
11+
12+
In a newly created trial account this is already true and you are good to go immediately with this setup.
13+
14+
But if you have already used services and/or setup subscriptions in your trial account, you have to make sure that you free up these resources to start with this setup here (i.e. delete the corresponding services/subscriptions used for this Discover Center Mission setup). Otherwise the setup would fail!
15+
16+
For this mission setup the following resources (services, subscriptions, etc.) are used:
17+
18+
- SAP Build Code (Subscription)
19+
20+
You could delete these resources in your [BTP Trial Cockpit](https://cockpit.btp.cloud.sap/trial) on the corresponding trial subaccount pages
21+
- Services > Instances and Subscriptions
622

723
## Content of setup
824

@@ -15,7 +31,7 @@ The setup comprises the following resources:
1531

1632
## Deploying the resources
1733

18-
Make sure that you are familiar with SAP BTP and know both the [Get Started with btp-terraform-samples](https://github.com/SAP-samples/btp-terraform-samples/blob/main/GET_STARTED.md) and the [Get Started with the Terraform Provider for BTP](https://developers.sap.com/tutorials/btp-terraform-get-started.html)
34+
Make sure that (1.) your trial account fulfills the above described important trial prerequisites and (2.) you are familiar with SAP BTP and know both the [Get Started with btp-terraform-samples](https://github.com/SAP-samples/btp-terraform-samples/blob/main/GET_STARTED.md) and the [Get Started with the Terraform Provider for BTP](https://developers.sap.com/tutorials/btp-terraform-get-started.html)
1935

2036
To deploy the resources you must:
2137

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,76 @@
11
# ------------------------------------------------------------------------------------------------------
2-
# SUBACCOUNT SETUP
2+
# Subaccount setup for DC mission 4441 (trial)
33
# ------------------------------------------------------------------------------------------------------
4-
data "btp_subaccounts" "all" {}
4+
# Setup subaccount domain (to ensure uniqueness in BTP global account)
5+
resource "random_uuid" "uuid" {}
56

6-
resource "terraform_data" "dc_mission_subaccount" {
7-
input = [for subaccount in data.btp_subaccounts.all.values : subaccount if subaccount.name == "trial"][0]
7+
locals {
8+
random_uuid = random_uuid.uuid.result
9+
subaccount_domain = "dcmission4441trial${local.random_uuid}"
810
}
911

12+
# ------------------------------------------------------------------------------------------------------
13+
# Creation of subaccount
14+
# ------------------------------------------------------------------------------------------------------
15+
resource "btp_subaccount" "dc_mission" {
16+
count = var.subaccount_id == "" ? 1 : 0
17+
18+
name = var.subaccount_name
19+
subdomain = local.subaccount_domain
20+
region = var.region
21+
}
22+
23+
data "btp_subaccount" "dc_mission" {
24+
id = var.subaccount_id != "" ? var.subaccount_id : btp_subaccount.dc_mission[0].id
25+
}
26+
27+
1028
# ------------------------------------------------------------------------------------------------------
1129
# APP SUBSCRIPTIONS
1230
# ------------------------------------------------------------------------------------------------------
1331
#
32+
locals {
33+
service_name__build_code = "build-code"
34+
}
1435
# ------------------------------------------------------------------------------------------------------
15-
# Setup build-code
36+
# Setup build-code (SAP Build Code)
1637
# ------------------------------------------------------------------------------------------------------
1738
# Entitle
1839
resource "btp_subaccount_entitlement" "build_code" {
19-
subaccount_id = terraform_data.dc_mission_subaccount.output.id
20-
service_name = "build-code"
21-
plan_name = "free"
40+
subaccount_id = data.btp_subaccount.dc_mission.id
41+
service_name = local.service_name__build_code
42+
plan_name = var.service_plan__build_code
2243
amount = 1
2344
}
2445
# Subscribe
2546
resource "btp_subaccount_subscription" "build_code" {
26-
subaccount_id = terraform_data.dc_mission_subaccount.output.id
27-
app_name = "build-code"
28-
plan_name = "free"
47+
subaccount_id = data.btp_subaccount.dc_mission.id
48+
app_name = local.service_name__build_code
49+
plan_name = var.service_plan__build_code
2950
depends_on = [btp_subaccount_entitlement.build_code]
3051
}
3152

3253
# ------------------------------------------------------------------------------------------------------
3354
# USERS AND ROLES
3455
# ------------------------------------------------------------------------------------------------------
3556
#
57+
locals {
58+
build_code_admins = var.build_code_admins
59+
build_code_developers = var.build_code_developers
60+
}
61+
3662
# Get all available subaccount roles
3763
data "btp_subaccount_roles" "all" {
38-
subaccount_id = terraform_data.dc_mission_subaccount.output.id
64+
subaccount_id = data.btp_subaccount.dc_mission.id
3965
depends_on = [btp_subaccount_subscription.build_code]
4066
}
67+
4168
# ------------------------------------------------------------------------------------------------------
4269
# Assign role collection for Build Code Administrator
4370
# ------------------------------------------------------------------------------------------------------
4471
# Assign roles to the role collection "Build Code Administrator"
4572
resource "btp_subaccount_role_collection" "build_code_administrator" {
46-
subaccount_id = terraform_data.dc_mission_subaccount.output.id
73+
subaccount_id = data.btp_subaccount.dc_mission.id
4774
name = "Build Code Administrator"
4875
description = "The role collection for an administrator on SAP Build Code"
4976

@@ -58,9 +85,10 @@ resource "btp_subaccount_role_collection" "build_code_administrator" {
5885
# Assign users to the role collection "Build Code Administrator"
5986
resource "btp_subaccount_role_collection_assignment" "build_code_administrator" {
6087
for_each = toset("${var.build_code_admins}")
61-
subaccount_id = terraform_data.dc_mission_subaccount.output.id
88+
subaccount_id = data.btp_subaccount.dc_mission.id
6289
role_collection_name = "Build Code Administrator"
6390
user_name = each.value
91+
origin = "sap.default"
6492
depends_on = [btp_subaccount_role_collection.build_code_administrator]
6593
}
6694

@@ -69,7 +97,7 @@ resource "btp_subaccount_role_collection_assignment" "build_code_administrator"
6997
# ------------------------------------------------------------------------------------------------------
7098
# Create role collection "Build Code Developer"
7199
resource "btp_subaccount_role_collection" "build_code_developer" {
72-
subaccount_id = terraform_data.dc_mission_subaccount.output.id
100+
subaccount_id = data.btp_subaccount.dc_mission.id
73101
name = "Build Code Developer"
74102
description = "The role collection for a developer on SAP Build Code"
75103

@@ -84,8 +112,9 @@ resource "btp_subaccount_role_collection" "build_code_developer" {
84112
# Assign users to the role collection "Build Code Developer"
85113
resource "btp_subaccount_role_collection_assignment" "build_code_developer" {
86114
for_each = toset("${var.build_code_developers}")
87-
subaccount_id = terraform_data.dc_mission_subaccount.output.id
115+
subaccount_id = data.btp_subaccount.dc_mission.id
88116
role_collection_name = "Build Code Developer"
89117
user_name = each.value
118+
origin = "sap.default"
90119
depends_on = [btp_subaccount_role_collection.build_code_developer]
91120
}

released/discovery_center/mission_4441_trial/outputs.tf

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
output "globalaccount" {
2-
value = var.globalaccount
3-
description = "The Global Account subdomain."
4-
}
5-
6-
output "cli_server_url" {
7-
value = var.cli_server_url
8-
description = "The BTP CLI server URL."
9-
}
10-
111
output "subaccount_id" {
12-
value = terraform_data.dc_mission_subaccount.output.id
13-
description = "The Global Account subdomain id."
2+
value = data.btp_subaccount.dc_mission.id
3+
description = "The ID of the subaccount where dc mission is set up."
144
}
155

166
output "build_code_subscription_url" {
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# ------------------------------------------------------------------------------------------------------
2-
# Provider configuration
2+
# Account settings
33
# ------------------------------------------------------------------------------------------------------
44
# Your global account subdomain
5-
globalaccount = "xxxxxxxxtrial-ga"
5+
globalaccount = "<your-globalaccount-subdomain>" // <xxxxxxxx>trial-ga
66

7-
# The CLI server URL (needs to be set to null if you are using the default CLI server)
8-
cli_server_url = null
7+
# Region for your trial subaccount
8+
region = "us10"
9+
10+
subaccount_id = "<your trial Subaccount ID>"
911

1012
# ------------------------------------------------------------------------------------------------------
11-
# USER ROLES
13+
# Use case specific role assignments
1214
# ------------------------------------------------------------------------------------------------------
1315
build_code_admins = ["[email protected]", "[email protected]"]
14-
build_code_developers = ["[email protected]", "[email protected]"]
16+
build_code_developers = ["[email protected]", "[email protected]"]
Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,56 @@
1+
# ------------------------------------------------------------------------------------------------------
2+
# Account variables
3+
# ------------------------------------------------------------------------------------------------------
14
variable "globalaccount" {
25
type = string
36
description = "The globalaccount subdomain where the sub account shall be created."
47
}
58

6-
variable "subaccount_id" {
9+
variable "cli_server_url" {
710
type = string
8-
description = "The subaccount ID."
9-
default = ""
11+
description = "The BTP CLI server URL."
12+
default = "https://cli.btp.cloud.sap"
13+
}
14+
15+
variable "region" {
16+
type = string
17+
description = "The region where the subaccount shall be created in."
18+
default = "us10"
1019
}
1120

1221
variable "subaccount_name" {
1322
type = string
1423
description = "The subaccount name."
15-
default = "My SAP Build Code subaccount."
24+
default = "My SAP DC mission subaccount."
1625
}
1726

18-
variable "cli_server_url" {
27+
variable "subaccount_id" {
1928
type = string
20-
description = "The BTP CLI server URL."
21-
default = "https://cli.btp.cloud.sap"
29+
description = "The subaccount ID."
30+
default = ""
31+
}
32+
33+
# ------------------------------------------------------------------------------------------------------
34+
# app subscription plans
35+
# ------------------------------------------------------------------------------------------------------
36+
variable "service_plan__build_code" {
37+
type = string
38+
description = "The plan for service 'SAP Build Code' with technical name 'build-code'"
39+
default = "free"
40+
validation {
41+
condition = contains(["free"], var.service_plan__build_code)
42+
error_message = "Invalid value for service_plan__build_code. Only 'free' is allowed."
43+
}
2244
}
2345

46+
# ------------------------------------------------------------------------------------------------------
47+
# User lists
48+
# ------------------------------------------------------------------------------------------------------
2449
variable "build_code_admins" {
2550
type = list(string)
2651
description = "Defines the colleagues who are admins for SAP Build Code."
27-
28-
# add validation to check if admins contains a list of valid email addresses
29-
validation {
30-
condition = length([for email in var.build_code_admins : can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", email))]) == length(var.build_code_admins)
31-
error_message = "Please enter a valid email address for the Build Code admins."
32-
}
3352
}
3453
variable "build_code_developers" {
3554
type = list(string)
3655
description = "Defines the colleagues who are developers for SAP Build Code."
37-
38-
# add validation to check if admins contains a list of valid email addresses
39-
validation {
40-
condition = length([for email in var.build_code_developers : can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", email))]) == length(var.build_code_developers)
41-
error_message = "Please enter a valid email address for the Build Code developers."
42-
}
4356
}

0 commit comments

Comments
 (0)