Skip to content

Commit 22d58c3

Browse files
Update DC Mission 3252 (Kyma) for QAS (#265)
* auto-select kyma-region if params not provided + update Readme + add outputs.tf + add custom_idp + rename kyma variables + add validation * Update README.md * Update provider.tf --------- Co-authored-by: Rui Nogueira <[email protected]>
1 parent c89f480 commit 22d58c3

File tree

6 files changed

+88
-53
lines changed

6 files changed

+88
-53
lines changed

released/discovery_center/mission_3252/README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,20 @@ To deploy the resources you must:
2424
export BTP_USERNAME=<your_username>
2525
export BTP_PASSWORD=<your_password>
2626
```
27-
Alternativelly set:
2827

28+
Alternativelly set:
2929

30-
```bash
31-
export BTP_ENABLE_SSO=true
32-
```
30+
```bash
31+
export BTP_ENABLE_SSO=true
32+
```
3333

3434
2. Change the variables in the `sample.tfvars` file to meet your requirements
3535

36-
> The minimal set of parameters you should specify (beside user_email and password) is globalaccount (i.e. its subdomain)
36+
> You must at least set a value for `globalaccount` (i.e. the subdomain of the globalaccount to use).
37+
38+
> ⚠ NOTE: If you change the value of the `region` variable please ensure that you adjust the values for `kyma_instance_parameters` accordingly, or set it to `null` to use default values for the region. Please refer to the documentation about available service plans and cluster regions for Kyma environments, as well as the documentation for parameter values and defaults for the different service plans.
39+
> * [Regions for the Kyma Environemnt](https://help.sap.com/docs/btp/sap-business-technology-platform/regions-for-kyma-environment)
40+
> * [Provisioning and Updating Parameters in the Kyma Environment](https://help.sap.com/docs/btp/sap-business-technology-platform/provisioning-and-update-parameters-in-kyma-environment)
3741
3842
> ⚠ 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]`.
3943

released/discovery_center/mission_3252/main.tf

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ locals {
1111
###############################################################################################
1212
# Creation of subaccount
1313
###############################################################################################
14-
resource "btp_subaccount" "project" {
14+
resource "btp_subaccount" "dc_mission" {
1515
name = var.subaccount_name
1616
subdomain = local.project_subaccount_domain
1717
region = lower(var.region)
@@ -22,7 +22,7 @@ resource "btp_subaccount" "project" {
2222
###############################################################################################
2323
resource "btp_subaccount_role_collection_assignment" "subaccount-admins" {
2424
for_each = toset("${var.subaccount_admins}")
25-
subaccount_id = btp_subaccount.project.id
25+
subaccount_id = btp_subaccount.dc_mission.id
2626
role_collection_name = "Subaccount Administrator"
2727
user_name = each.value
2828
}
@@ -32,7 +32,7 @@ resource "btp_subaccount_role_collection_assignment" "subaccount-admins" {
3232
###############################################################################################
3333
resource "btp_subaccount_role_collection_assignment" "subaccount-service-admins" {
3434
for_each = toset("${var.subaccount_service_admins}")
35-
subaccount_id = btp_subaccount.project.id
35+
subaccount_id = btp_subaccount.dc_mission.id
3636
role_collection_name = "Subaccount Service Administrator"
3737
user_name = each.value
3838
}
@@ -44,33 +44,46 @@ data "btp_regions" "all" {}
4444

4545
#we take the iaas provider for the first region associated with the subaccount
4646
locals {
47-
subaccount_iaas_provider = [for region in data.btp_regions.all.values : region if region.region == btp_subaccount.project.region][0].iaas_provider
47+
subaccount_iaas_provider = [for region in data.btp_regions.all.values : region if region.region == btp_subaccount.dc_mission.region][0].iaas_provider
4848
}
4949

5050
resource "btp_subaccount_entitlement" "kymaruntime" {
51-
subaccount_id = btp_subaccount.project.id
51+
subaccount_id = btp_subaccount.dc_mission.id
5252
service_name = "kymaruntime"
5353
plan_name = lower(local.subaccount_iaas_provider)
5454
amount = 1
5555
}
5656

57+
data "btp_subaccount_environments" "all" {
58+
subaccount_id = btp_subaccount.dc_mission.id
59+
depends_on = [btp_subaccount_entitlement.kymaruntime]
60+
}
61+
62+
# Take the first kyma region from the first kyma environment if no kyma instance parameters are provided
63+
resource "null_resource" "cache_kyma_region" {
64+
triggers = {
65+
region = var.kyma_instance_parameters != null ? var.kyma_instance_parameters.region : jsondecode([for env in data.btp_subaccount_environments.all.values : env if env.service_name == "kymaruntime" && env.environment_type == "kyma" && env.plan_name == lower(local.subaccount_iaas_provider)][0].schema_create).parameters.properties.region.enum[0]
66+
}
67+
68+
lifecycle {
69+
ignore_changes = all
70+
}
71+
}
72+
73+
locals {
74+
kyma_instance_parameters = var.kyma_instance_parameters != null ? var.kyma_instance_parameters : {
75+
name = btp_subaccount.dc_mission.subdomain
76+
region = null_resource.cache_kyma_region.triggers.region
77+
}
78+
}
79+
5780
resource "btp_subaccount_environment_instance" "kyma" {
58-
subaccount_id = btp_subaccount.project.id
59-
name = var.kyma_instance.name
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
6083
environment_type = "kyma"
6184
service_name = "kymaruntime"
6285
plan_name = lower(local.subaccount_iaas_provider)
63-
parameters = jsonencode({
64-
name = var.kyma_instance.name
65-
region = var.kyma_instance.region
66-
machine_type = var.kyma_instance.machine_type
67-
auto_scaler_min = var.kyma_instance.auto_scaler_min
68-
auto_scaler_max = var.kyma_instance.auto_scaler_max
69-
})
70-
timeouts = {
71-
create = var.kyma_instance.createtimeout
72-
update = var.kyma_instance.updatetimeout
73-
delete = var.kyma_instance.deletetimeout
74-
}
75-
depends_on = [btp_subaccount_entitlement.kymaruntime]
86+
parameters = jsonencode(local.kyma_instance_parameters)
87+
timeouts = var.kyma_instance_timeouts
88+
depends_on = [btp_subaccount_entitlement.kymaruntime]
7689
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "subaccount_id" {
2+
value = btp_subaccount.dc_mission.id
3+
}

released/discovery_center/mission_3252/provider.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ terraform {
77
}
88
}
99

10+
# Please checkout documentation on how best to authenticate against SAP BTP
11+
# via the Terraform provider for SAP BTP
1012
provider "btp" {
13+
# Uncomment the idp in case you need it to connect to your global account
14+
# -------------------------------------------------------------------------
15+
idp = var.custom_idp
1116
globalaccount = var.globalaccount
1217
cli_server_url = var.cli_server_url
1318
}
Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
# ------------------------------------------------------------------------------------------------------
2-
# Provider configuration
2+
# Project specific configuration (please adapt!)
33
# ------------------------------------------------------------------------------------------------------
44
# Your global account subdomain
5-
globalaccount = "your global account id goes here eg. 0645xxxx-1xxx-4xxx-bxxx-4xxxxxxxxxxx"
6-
region = "eu10"
7-
subaccount_name = "DC Mission 3252 - Get Started with SAP BTP, Kyma runtime creating a Hello-World Function"
5+
globalaccount = "your global account id goes here eg. 0645xxxx-1xxx-4xxx-bxxx-4xxxxxxxxxxx"
6+
subaccount_name = "DC Mission 3252 - Get Started with SAP BTP, Kyma runtime creating a Hello-World Function"
7+
region = "eu10"
8+
subaccount_admins = ["[email protected]"]
9+
subaccount_service_admins = ["[email protected]"]
810

9-
kyma_instance = {
11+
# Kyma instance parameters. When set to null, the name will be set to the subaccount subdomain and the
12+
# first available cluster region for the subaccount will be selected.
13+
kyma_instance_parameters = {
1014
name = "my-kyma-environment"
1115
region = "eu-central-1"
1216
machine_type = "mx5.xlarge"
1317
auto_scaler_min = 3
1418
auto_scaler_max = 20
15-
createtimeout = "1h"
16-
updatetimeout = "35m"
17-
deletetimeout = "1h"
1819
}
19-
20-
# ------------------------------------------------------------------------------------------------------
21-
# Project specific configuration (please adapt!)
22-
# ------------------------------------------------------------------------------------------------------
23-
subaccount_admins = ["[email protected]"]
24-
subaccount_service_admins = ["[email protected]"]
25-

released/discovery_center/mission_3252/variables.tf

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ variable "cli_server_url" {
2626
default = "https://cpcli.cf.eu10.hana.ondemand.com"
2727
}
2828

29+
variable "custom_idp" {
30+
type = string
31+
description = "Defines the custom IDP to be used for the subaccount."
32+
default = ""
33+
}
34+
2935
variable "subaccount_admins" {
3036
type = list(string)
3137
description = "Defines the colleagues who are added to each subaccount as subaccount administrators."
@@ -36,26 +42,36 @@ variable "subaccount_service_admins" {
3642
description = "Defines the colleagues who are added to each subaccount as subaccount service administrators."
3743
}
3844

39-
variable "kyma_instance" {
45+
variable "kyma_instance_parameters" {
4046
type = object({
4147
name = string
4248
region = string
4349
machine_type = string
4450
auto_scaler_min = number
4551
auto_scaler_max = number
46-
createtimeout = string
47-
updatetimeout = string
48-
deletetimeout = string
4952
})
50-
description = "Your Kyma environment configuration"
53+
description = "Your Kyma environment configuration parameters. Name and region are mandatory. Please refer to the following documentation for more details: https://help.sap.com/docs/btp/sap-business-technology-platform/provisioning-and-update-parameters-in-kyma-environment."
54+
default = null
55+
56+
validation {
57+
condition = (
58+
var.kyma_instance_parameters == null ? true : length(var.kyma_instance_parameters.name) > 0 && length(var.kyma_instance_parameters.region) > 0
59+
)
60+
61+
error_message = "Value for kyma_instance_parameters must either be null or an object with values for at least name and region"
62+
}
63+
}
64+
65+
variable "kyma_instance_timeouts" {
66+
type = object({
67+
create = string
68+
update = string
69+
delete = string
70+
})
71+
description = "Timeouts for the creation, update, and deletion of the Kyma instance."
5172
default = {
52-
name = "my-kyma-environment"
53-
region = "eu-central-1"
54-
machine_type = "mx5.xlarge"
55-
auto_scaler_min = 3
56-
auto_scaler_max = 20
57-
createtimeout = "1h"
58-
updatetimeout = "35m"
59-
deletetimeout = "1h"
73+
create = "1h"
74+
update = "35m"
75+
delete = "1h"
6076
}
6177
}

0 commit comments

Comments
 (0)