Skip to content

Commit 5b59a24

Browse files
authored
4356 Polished the QAS enabled Mission (#317)
1 parent 519a88c commit 5b59a24

File tree

6 files changed

+122
-85
lines changed

6 files changed

+122
-85
lines changed
Lines changed: 57 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,56 @@
1-
###############################################################################################
2-
# Setup of names in accordance to naming convention
3-
###############################################################################################
1+
# ------------------------------------------------------------------------------------------------------
2+
# Subaccount setup for DC mission 3252
3+
# ------------------------------------------------------------------------------------------------------
4+
# Setup subaccount domain (to ensure uniqueness in BTP global account)
45
resource "random_uuid" "uuid" {}
56

67
locals {
7-
random_uuid = random_uuid.uuid.result
8-
project_subaccount_domain = lower(replace("mission-3252-${local.random_uuid}", "_", "-"))
8+
random_uuid = random_uuid.uuid.result
9+
subaccount_domain = lower(replace("mission-3260-${local.random_uuid}", "_", "-"))
910
}
1011

11-
###############################################################################################
12+
# ------------------------------------------------------------------------------------------------------
1213
# Creation of subaccount
13-
###############################################################################################
14+
# ------------------------------------------------------------------------------------------------------
1415
resource "btp_subaccount" "dc_mission" {
16+
count = var.subaccount_id == "" ? 1 : 0
1517
name = var.subaccount_name
16-
subdomain = local.project_subaccount_domain
17-
region = lower(var.region)
18+
subdomain = local.subaccount_domain
19+
region = var.region
1820
}
1921

20-
###############################################################################################
21-
# Assignment of users as sub account administrators
22-
###############################################################################################
23-
resource "btp_subaccount_role_collection_assignment" "subaccount-admins" {
24-
for_each = toset("${var.subaccount_admins}")
25-
subaccount_id = btp_subaccount.dc_mission.id
26-
role_collection_name = "Subaccount Administrator"
27-
user_name = each.value
22+
data "btp_subaccount" "dc_mission" {
23+
id = var.subaccount_id != "" ? var.subaccount_id : btp_subaccount.dc_mission[0].id
2824
}
2925

30-
###############################################################################################
31-
# Assignment of users as sub account service administrators
32-
###############################################################################################
33-
resource "btp_subaccount_role_collection_assignment" "subaccount-service-admins" {
34-
for_each = toset("${var.subaccount_service_admins}")
35-
subaccount_id = btp_subaccount.dc_mission.id
36-
role_collection_name = "Subaccount Service Administrator"
37-
user_name = each.value
26+
# ------------------------------------------------------------------------------------------------------
27+
# SERVICES
28+
# ------------------------------------------------------------------------------------------------------
29+
#
30+
locals {
31+
service_name__kymaruntime = "kymaruntime"
3832
}
3933

40-
######################################################################
41-
# Setup Kyma
42-
######################################################################
34+
# ------------------------------------------------------------------------------------------------------
35+
# Setup kymaruntime (Kyma Runtime)
36+
# ------------------------------------------------------------------------------------------------------
37+
#
4338
data "btp_regions" "all" {}
4439

45-
#we take the iaas provider for the first region associated with the subaccount
40+
# we take the iaas provider for the first region associated with the subaccount
4641
locals {
47-
subaccount_iaas_provider = [for region in data.btp_regions.all.values : region if region.region == btp_subaccount.dc_mission.region][0].iaas_provider
42+
subaccount_iaas_provider = [for region in data.btp_regions.all.values : region if region.region == data.btp_subaccount.dc_mission.region][0].iaas_provider
4843
}
49-
44+
# Entitle
5045
resource "btp_subaccount_entitlement" "kymaruntime" {
51-
subaccount_id = btp_subaccount.dc_mission.id
52-
service_name = "kymaruntime"
46+
subaccount_id = data.btp_subaccount.dc_mission.id
47+
service_name = local.service_name__kymaruntime
5348
plan_name = lower(local.subaccount_iaas_provider)
5449
amount = 1
5550
}
5651

5752
data "btp_subaccount_environments" "all" {
58-
subaccount_id = btp_subaccount.dc_mission.id
53+
subaccount_id = data.btp_subaccount.dc_mission.id
5954
depends_on = [btp_subaccount_entitlement.kymaruntime]
6055
}
6156

@@ -72,18 +67,42 @@ resource "null_resource" "cache_kyma_region" {
7267

7368
locals {
7469
kyma_instance_parameters = var.kyma_instance_parameters != null ? var.kyma_instance_parameters : {
75-
name = btp_subaccount.dc_mission.subdomain
70+
name = data.btp_subaccount.dc_mission.subdomain
7671
region = null_resource.cache_kyma_region.triggers.region
7772
}
7873
}
7974

8075
resource "btp_subaccount_environment_instance" "kyma" {
81-
subaccount_id = btp_subaccount.dc_mission.id
82-
name = var.kyma_instance_parameters != null ? var.kyma_instance_parameters.name : btp_subaccount.dc_mission.subdomain
76+
subaccount_id = data.btp_subaccount.dc_mission.id
77+
name = var.kyma_instance_parameters != null ? var.kyma_instance_parameters.name : data.btp_subaccount.dc_mission.subdomain
8378
environment_type = "kyma"
84-
service_name = "kymaruntime"
79+
service_name = local.service_name__kymaruntime
8580
plan_name = lower(local.subaccount_iaas_provider)
8681
parameters = jsonencode(local.kyma_instance_parameters)
8782
timeouts = var.kyma_instance_timeouts
8883
depends_on = [btp_subaccount_entitlement.kymaruntime]
8984
}
85+
86+
# ------------------------------------------------------------------------------------------------------
87+
# USERS AND ROLES
88+
# ------------------------------------------------------------------------------------------------------
89+
#
90+
# ------------------------------------------------------------------------------------------------------
91+
# Assign role collection "Subaccount Administrator"
92+
# ------------------------------------------------------------------------------------------------------
93+
resource "btp_subaccount_role_collection_assignment" "subaccount_admins" {
94+
for_each = toset(var.subaccount_admins)
95+
subaccount_id = data.btp_subaccount.dc_mission.id
96+
role_collection_name = "Subaccount Administrator"
97+
user_name = each.value
98+
}
99+
100+
# ------------------------------------------------------------------------------------------------------
101+
# Assign role collection "Subaccount Service Administrator"
102+
# ------------------------------------------------------------------------------------------------------
103+
resource "btp_subaccount_role_collection_assignment" "subaccount_service_admins" {
104+
for_each = toset(var.subaccount_service_admins)
105+
subaccount_id = data.btp_subaccount.dc_mission.id
106+
role_collection_name = "Subaccount Service Administrator"
107+
user_name = each.value
108+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
output "subaccount_id" {
2-
value = btp_subaccount.dc_mission.id
2+
value = data.btp_subaccount.dc_mission.id
33
}

released/discovery_center/mission_3252/provider.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ terraform {
1212
provider "btp" {
1313
# Uncomment the idp in case you need it to connect to your global account
1414
# -------------------------------------------------------------------------
15-
idp = var.custom_idp
15+
#idp = var.custom_idp
1616
globalaccount = var.globalaccount
1717
cli_server_url = var.cli_server_url
1818
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# ------------------------------------------------------------------------------------------------------
2+
# Provider configuration
3+
# ------------------------------------------------------------------------------------------------------
4+
custom_idp = "<<tenant-id>>.accounts.ondemand.com"
5+
6+
# ------------------------------------------------------------------------------------------------------
7+
# Account settings
8+
# ------------------------------------------------------------------------------------------------------
9+
globalaccount = "<your-global-account-subdomain>"
10+
region = "eu10"
11+
subaccount_name = "SAP Discovery Center Mission 3252"
12+
13+
# ------------------------------------------------------------------------------------------------------
14+
# Use case specific configuration
15+
# ------------------------------------------------------------------------------------------------------
16+
subaccount_admins = ["[email protected]", "[email protected]"]
17+
subaccount_service_admins = ["[email protected]", "[email protected]"]
18+
19+
# Kyma instance parameters. When set to null, the name will be set to the subaccount subdomain and the
20+
# first available cluster region for the subaccount will be selected.
21+
kyma_instance_parameters = {
22+
name = "my-kyma-environment"
23+
region = "eu-central-1"
24+
machine_type = "mx5.xlarge"
25+
auto_scaler_min = 3
26+
auto_scaler_max = 20
27+
}

released/discovery_center/mission_3252/samples.tfvars

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,44 @@
1-
######################################################################
2-
# Customer account setup
3-
######################################################################
4-
# subaccount
1+
# ------------------------------------------------------------------------------------------------------
2+
# Account variables
3+
# ------------------------------------------------------------------------------------------------------
54
variable "globalaccount" {
65
type = string
7-
description = "The globalaccount subdomain."
8-
}
9-
# subaccount
10-
variable "subaccount_name" {
11-
type = string
12-
description = "The subaccount name."
13-
default = "DC Mission 3252 - Get Started with SAP BTP, Kyma runtime creating a Hello-World Function"
14-
}
15-
# Region
16-
variable "region" {
17-
type = string
18-
description = "The region where the project account shall be created in."
19-
default = "eu10"
6+
description = "The globalaccount subdomain where the sub account shall be created."
207
}
218

22-
# CLI server
239
variable "cli_server_url" {
2410
type = string
2511
description = "The BTP CLI server URL."
26-
default = "https://cpcli.cf.eu10.hana.ondemand.com"
12+
default = "https://cli.btp.cloud.sap"
2713
}
2814

2915
variable "custom_idp" {
3016
type = string
31-
description = "Defines the custom IDP to be used for the subaccount."
17+
description = "The custom identity provider for the subaccount."
3218
default = ""
3319
}
3420

35-
variable "subaccount_admins" {
36-
type = list(string)
37-
description = "Defines the colleagues who are added to each subaccount as subaccount administrators."
21+
variable "region" {
22+
type = string
23+
description = "The region where the subaccount shall be created in."
24+
default = "eu10"
3825
}
3926

40-
variable "subaccount_service_admins" {
41-
type = list(string)
42-
description = "Defines the colleagues who are added to each subaccount as subaccount service administrators."
27+
variable "subaccount_name" {
28+
type = string
29+
description = "The subaccount name."
30+
default = "My SAP DC mission subaccount."
31+
}
32+
33+
variable "subaccount_id" {
34+
type = string
35+
description = "The subaccount ID."
36+
default = ""
4337
}
4438

39+
# ------------------------------------------------------------------------------------------------------
40+
# service parameters
41+
# ------------------------------------------------------------------------------------------------------
4542
variable "kyma_instance_parameters" {
4643
type = object({
4744
name = string
@@ -74,4 +71,17 @@ variable "kyma_instance_timeouts" {
7471
update = "35m"
7572
delete = "1h"
7673
}
74+
}
75+
76+
# ------------------------------------------------------------------------------------------------------
77+
# User lists
78+
# ------------------------------------------------------------------------------------------------------
79+
variable "subaccount_admins" {
80+
type = list(string)
81+
description = "Defines the users who are added to subaccount as administrators."
82+
}
83+
84+
variable "subaccount_service_admins" {
85+
type = list(string)
86+
description = "Defines the users who are added to subaccount as service administrators."
7787
}

0 commit comments

Comments
 (0)