Skip to content

Commit e708ec3

Browse files
committed
feat: include Kyma environment to basic setup
1 parent 2669578 commit e708ec3

File tree

14 files changed

+232
-7
lines changed

14 files changed

+232
-7
lines changed

sample-setups/basic-setup/subaccount-setup/README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,25 @@ To ease the provisioning of entitlements we use the Terraform community module [
4141

4242
The setup of a Cloud Foundry environment is optional. The caller can decide if a Cloud Foundry environment is required or not e.g. when setting up a shared subaccount. The boolean variable is `provision_cf_environment` in the [variables.tf](./variables.tf) file.
4343

44+
The configuration of the setup is done in the corresponding module [`sap-btp-environment/cloudfoundry`](../../modules/sap-btp-environment/cloudfoundry/README.md).
45+
46+
### Setup of Kyma Environment
47+
48+
The setup of a Kyma environment is optional. The caller can decide if a Kyma environment is required or not e.g. when setting up a shared subaccount. The boolean variable is `provision_kyma_environment` in the [variables.tf](./variables.tf) file.
49+
50+
If the Kyma environemnt is requested, the variable `kyma_administrators` in the [variables.tf](./variables.tf) file must be filled with the users that should be assigned as administrators. This condition is validated
51+
52+
The configuration of the setup is done in the corresponding module [`sap-btp-environment/kyma`](../../modules/sap-btp-environment/kyma/README.md).
4453

4554
### Output
4655

4756
The output defined in the [outputs.tf](./outputs.tf) file returns the main information relevant for the development team namely:
4857

4958
- a link to the subaccount
50-
- The ID of the Cloud Foundry org
51-
- The API endpoint of the Cloud Foundry environment
52-
53-
59+
- The ID of the Cloud Foundry org if a Cloud Foundry environment is created
60+
- The API endpoint of the Cloud Foundry environment if a Cloud Foundry environment is created
61+
- The URL to the Kyma dashboard if a Kyma environment is created
62+
- The URL to the Kubeconfig file for the Kyma runtime if a Kyma environment is created
5463

5564
## SAP BTP Administrator's Guide - References
5665

sample-setups/basic-setup/subaccount-setup/main.tf

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,21 @@ module "sap_btp_entitlements" {
7070
}
7171

7272
module "cf_environment" {
73-
source = "../../modules/sap-btp-environment/CloudFoundry"
73+
source = "../../modules/sap-btp-environment/cloudfoundry"
7474

7575
count = var.provision_cf_environment ? 1 : 0
7676

7777
subaccount_id = btp_subaccount.self.id
7878
instance_name = module.subaccount_namings.cloudfoundry_org_name
7979
cf_org_name = module.subaccount_namings.cloudfoundry_org_name
8080
}
81+
82+
module "kyma_environment" {
83+
source = "../../modules/sap-btp-environment/kyma"
84+
85+
count = var.provision_kyma_environment ? 1 : 0
86+
87+
subaccount_id = btp_subaccount.self.id
88+
instance_name = module.subaccount_namings.kyma_instance_name
89+
kyma_administrators = var.kyma_administrators
90+
}

sample-setups/basic-setup/subaccount-setup/outputs.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,13 @@ output "cf_org_id" {
1212
value = var.provision_cf_environment ? module.cf_environment[0].cf_org_id : "No Cloud Foundry environment was requested to be provisioned"
1313
description = "The Cloud Foundry org ID"
1414
}
15+
16+
output "kyma_dashboard_url" {
17+
value = var.provision_kyma_environment ? module.kyma_environment[0].kyma_dashboard_url : "No Kyma environment was requested to be provisioned"
18+
description = "The URL to the Kyma dashboard"
19+
}
20+
21+
output "kyma_kubeconfig_url" {
22+
value = var.provision_kyma_environment ? module.kyma_environment[0].kyma_kubeconfig_url : "No Kyma environment was requested to be provisioned"
23+
description = "The URL to the Kubeconfig file for the Kyma runtime"
24+
}

sample-setups/basic-setup/subaccount-setup/variables.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,20 @@ variable "provision_cf_environment" {
7676
description = "Provision Cloud Foundry environment in subaccount"
7777
default = true
7878
}
79+
80+
variable "provision_kyma_environment" {
81+
type = bool
82+
description = "Provision Kyma environment in subaccount"
83+
default = false
84+
}
85+
86+
variable "kyma_administrators" {
87+
description = "Users to be assigned as administrators for the Kyma environment."
88+
type = list(string)
89+
default = null
90+
91+
validation {
92+
condition = var.provision_kyma_environment ? length(var.kyma_administrators) > 0 : true
93+
error_message = "Kyma administrators must be provided if a Kyma environment is provisioned"
94+
}
95+
}

sample-setups/modules/sap-btp-environment/CloudFoundry/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SAP BTP - Environment Setup
1+
# SAP BTP - CLoud Foundry Environment Setup
22

33
This module encapsulates the creation of a Cloud Foundry environment in a subaccount on SAP BTP.
44

sample-setups/modules/sap-btp-environment/CloudFoundry/variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ variable "subaccount_id" {
22
type = string
33
description = "ID of the subaccount where the Cloud Foundry environment will be created."
44
}
5+
56
variable "instance_name" {
67
type = string
78
description = "Name of the Cloud Foundry environment instance."
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# SAP BTP - Kyma Environment Setup
2+
3+
This module encapsulates the creation of a Kyma environment in a subaccount on SAP BTP. The configuration is a basic setup. In a real world scenario, you would likely want to customize the setuo further with resoect to the available parameters like machine type etc. as described in the [documentation](https://help.sap.com/docs/btp/sap-business-technology-platform/provisioning-and-update-parameters-in-kyma-environment) depending on the stage of the environment (development, test, production).
4+
5+
## Requirements
6+
7+
| Name | Version |
8+
|------|---------|
9+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.11 |
10+
| <a name="requirement_btp"></a> [btp](#requirement\_btp) | >= 1.11.0 |
11+
12+
## Providers
13+
14+
| Name | Version |
15+
|------|---------|
16+
| <a name="provider_btp"></a> [btp](#provider\_btp) | >= 1.11.0 |
17+
18+
## Modules
19+
20+
No modules.
21+
22+
## Resources
23+
24+
| Name | Type |
25+
|------|------|
26+
| [btp_subaccount_entitlement.kymaruntime](https://registry.terraform.io/providers/SAP/btp/latest/docs/resources/subaccount_entitlement) | resource |
27+
| [btp_subaccount_environment_instance.kymaruntime](https://registry.terraform.io/providers/SAP/btp/latest/docs/resources/subaccount_environment_instance) | resource |
28+
| [btp_regions.all](https://registry.terraform.io/providers/SAP/btp/latest/docs/data-sources/regions) | data source |
29+
| [btp_subaccount.this](https://registry.terraform.io/providers/SAP/btp/latest/docs/data-sources/subaccount) | data source |
30+
31+
## Inputs
32+
33+
| Name | Description | Type | Default | Required |
34+
|------|-------------|------|---------|:--------:|
35+
| <a name="input_instance_name"></a> [instance\_name](#input\_instance\_name) | Name of the Kyma environment instance. | `string` | n/a | yes |
36+
| <a name="input_kyma_administrators"></a> [kyma\_administrators](#input\_kyma\_administrators) | Users to be assigned as administrators. | `list(string)` | `[]` | no |
37+
| <a name="input_oidc"></a> [oidc](#input\_oidc) | Custom OpenID Connect IdP configuration to authenticate users in your Kyma runtime. | <pre>object({<br/> # the URL of the OpenID issuer (use the https schema)<br/> issuer_url = string<br/><br/> # the client ID for the OpenID client<br/> client_id = string<br/><br/> #the name of a custom OpenID Connect claim for specifying user groups<br/> groups_claim = string<br/><br/> # the list of allowed cryptographic algorithms used for token signing. The allowed values are defined by RFC 7518.<br/> signing_algs = set(string)<br/><br/> # the prefix for all usernames. If you don't provide it, username claims other than “email” are prefixed by the issuerURL to avoid clashes. To skip any prefixing, provide the value as -.<br/> username_prefix = string<br/><br/> # the name of a custom OpenID Connect claim for specifying a username<br/> username_claim = string<br/> })</pre> | `null` | no |
38+
| <a name="input_plan_name"></a> [plan\_name](#input\_plan\_name) | Desired service plan for the Kyma environment instance.<br/>If not provided it will be set to the default value of the region. | `string` | `null` | no |
39+
| <a name="input_subaccount_id"></a> [subaccount\_id](#input\_subaccount\_id) | ID of the subaccount where the Cloud Foundry environment will be created. | `string` | n/a | yes |
40+
41+
## Outputs
42+
43+
| Name | Description |
44+
|------|-------------|
45+
| <a name="output_kyma_dashboard_url"></a> [kyma\_dashboard\_url](#output\_kyma\_dashboard\_url) | The URL to the Kyma dashboard |
46+
| <a name="output_kyma_kubeconfig_url"></a> [kyma\_kubeconfig\_url](#output\_kyma\_kubeconfig\_url) | The URL to the Kubeconfig file for the Kyma runtime |
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
data "btp_regions" "all" {}
2+
3+
data "btp_subaccount" "this" {
4+
id = var.subaccount_id
5+
}
6+
7+
locals {
8+
subaccount_iaas_provider = [for region in data.btp_regions.all.values : region if region.region == data.btp_subaccount.this.region][0].iaas_provider
9+
}
10+
11+
resource "btp_subaccount_entitlement" "kymaruntime" {
12+
subaccount_id = var.instance_name
13+
service_name = "kymaruntime"
14+
plan_name = var.plan_name != null ? var.plan_name : lower(local.subaccount_iaas_provider)
15+
amount = 1
16+
}
17+
18+
resource "btp_subaccount_environment_instance" "kymaruntime" {
19+
subaccount_id = var.subaccount_id
20+
name = var.instance_name
21+
environment_type = "kyma"
22+
service_name = btp_subaccount_entitlement.kymaruntime.service_name
23+
plan_name = btp_subaccount_entitlement.kymaruntime.plan_name
24+
parameters = jsonencode(merge({
25+
name = var.instance_name
26+
administrators = toset(var.kyma_administrators)
27+
},
28+
var.oidc == null ? null : {
29+
issuerURL = var.oidc.issuer_url
30+
clientID = var.oidc.client_id
31+
groupsClaim = var.oidc.groups_claim
32+
usernameClaim = var.oidc.username_claim
33+
usernamePrefix = var.oidc.username_prefix
34+
signingAlgs = var.oidc.signing_algs
35+
}))
36+
37+
depends_on = [btp_subaccount_entitlement.kymaruntime]
38+
39+
timeouts = {
40+
read = "10m"
41+
create = "60m"
42+
update = "60m"
43+
delete = "120m"
44+
}
45+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "kyma_dashboard_url" {
2+
value = btp_subaccount_environment_instance.kymaruntime.dashboard_url
3+
description = "The URL to the Kyma dashboard"
4+
}
5+
6+
output "kyma_kubeconfig_url" {
7+
value = jsondecode(btp_subaccount_environment_instance.kymaruntime.labels)["KubeconfigURL"]
8+
description = "The URL to the Kubeconfig file for the Kyma runtime"
9+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
variable "subaccount_id" {
2+
type = string
3+
description = "ID of the subaccount where the Cloud Foundry environment will be created."
4+
}
5+
6+
variable "instance_name" {
7+
type = string
8+
description = "Name of the Kyma environment instance."
9+
10+
validation {
11+
condition = can(regex("^[a-zA-Z0-9_\\-\\.]{1,32}$", var.instance_name))
12+
error_message = "Please provide a valid instance name (^[a-zA-Z0-9_\\-\\.]{1,32})."
13+
}
14+
}
15+
16+
variable "plan_name" {
17+
type = string
18+
description = <<-EOT
19+
Desired service plan for the Kyma environment instance.
20+
If not provided it will be set to the default value of the region.
21+
EOT
22+
default = null
23+
}
24+
25+
variable "kyma_administrators" {
26+
description = "Users to be assigned as administrators."
27+
type = list(string)
28+
default = []
29+
}
30+
31+
variable "oidc" {
32+
description = "Custom OpenID Connect IdP configuration to authenticate users in your Kyma runtime."
33+
type = object({
34+
# the URL of the OpenID issuer (use the https schema)
35+
issuer_url = string
36+
37+
# the client ID for the OpenID client
38+
client_id = string
39+
40+
#the name of a custom OpenID Connect claim for specifying user groups
41+
groups_claim = string
42+
43+
# the list of allowed cryptographic algorithms used for token signing. The allowed values are defined by RFC 7518.
44+
signing_algs = set(string)
45+
46+
# the prefix for all usernames. If you don't provide it, username claims other than “email” are prefixed by the issuerURL to avoid clashes. To skip any prefixing, provide the value as -.
47+
username_prefix = string
48+
49+
# the name of a custom OpenID Connect claim for specifying a username
50+
username_claim = string
51+
})
52+
default = null
53+
}

0 commit comments

Comments
 (0)