Skip to content

Commit fe1113f

Browse files
committed
enhanced subaccount setup
1 parent b83fed5 commit fe1113f

File tree

15 files changed

+175
-24
lines changed

15 files changed

+175
-24
lines changed

sample-setup/basic-setup/directory-setup/main.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module "directory" {
2-
source = "../../modules/base-directory-setup"
3-
for_each = var.directory_inputs
2+
source = "../../modules/base-directory-setup"
3+
4+
for_each = var.directory_inputs
5+
46
business_unit = each.value.business_unit
57
costcenter = each.value.costcenter
68
directory_contacts = each.value.directory_contacts

sample-setup/basic-setup/directory-setup/stack.tm.hcl

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
# Setup of a Subaccount
22

3-
Basic setup of a subaccount. Every subaccount is created seperately
3+
- Basic setup of a subaccount. Every subaccount is created seperately
4+
- Naming Conventions and Labels
5+
- Validation of Geo Region and Subaccount region
6+
- Default Setup of custom IdP
7+
- Provision CF env (optional)

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ locals {
1818
}
1919
}
2020

21+
data "btp_globalaccount" "this" {}
2122

2223
module "subaccount_namings" {
2324
source = "../../modules/sap-btp-naming-conventions-subaccount"
@@ -36,3 +37,22 @@ resource "btp_subaccount" "self" {
3637
usage = module.subaccount_namings.subaccount_usage
3738
labels = module.subaccount_namings.subaccount_labels
3839
}
40+
41+
resource "btp_subaccount_trust_configuration" "custom_idp" {
42+
subaccount_id = btp_subaccount.self.id
43+
identity_provider = var.custom_indentity_provider
44+
name = "default-corp-custom-idp"
45+
description = "Default Custom IdP of Corporate"
46+
auto_create_shadow_users = true
47+
available_for_user_logon = true
48+
}
49+
50+
module "cf_environment" {
51+
source = "../../modules/sap-btp-environment/CloudFoundry"
52+
53+
count = var.provision_cf_environment ? 1 : 0
54+
55+
subaccount_id = btp_subaccount.self.id
56+
instance_name = module.subaccount_namings.cloudfoundry_org_name
57+
cf_org_name = module.subaccount_namings.cloudfoundry_org_name
58+
}
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
output "subaccount_id" {
2-
value = btp_subaccount.self.id
3-
description = "Technical ID of the subaccount"
1+
output "subaccount_url" {
2+
value = "https://emea.cockpit.btp.cloud.sap/cockpit/#globalaccount/${data.btp_globalaccount.this.id}/subaccount/${btp_subaccount.project_subaccount.id}"
3+
description = "The URL to the provisioned subaccount on SAP BTP"
44
}
55

6-
output "subaccount_name" {
7-
value = btp_subaccount.self.name
8-
description = "The name of the subaccount"
6+
output "cf_api_url" {
7+
value = module.cf_environment.cf_api_url
8+
description = "The Cloud Foundry API URL"
9+
}
10+
11+
output "cf_org_id" {
12+
value = module.cf_environment.cf_org_id
13+
description = "The Cloud Foundry org ID"
914
}

sample-setup/basic-setup/subaccount-setup/stack.tm.hcl

Lines changed: 0 additions & 7 deletions
This file was deleted.

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,14 @@ variable "parent_id" {
5959
description = "ID of the parent directory"
6060
default = null
6161
}
62+
63+
variable "custom_indentity_provider" {
64+
type = string
65+
description = "Custom IdP to be used for subaccount"
66+
}
67+
68+
variable "provision_cf_environment" {
69+
type = bool
70+
description = "Provision Cloud Foundry environment in subaccount"
71+
default = true
72+
}

sample-setup/modules/base-directory-setup/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# SAP BTP - Directory Setup
2+
3+
This module encapsulates the creation of a directory on SAP BTP following standardized naming conventions.
4+
15
## Requirements
26

37
| Name | Version |
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SAP BTP - Environment Setup
2+
3+
This module encapsulates the creation of a Cloud Foundry environment in a subaccounton SAP BTP.
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+
| <a name="provider_null"></a> [null](#provider\_null) | n/a |
18+
19+
## Modules
20+
21+
No modules.
22+
23+
## Resources
24+
25+
| Name | Type |
26+
|------|------|
27+
| [btp_subaccount_environment_instance.self](https://registry.terraform.io/providers/SAP/btp/latest/docs/resources/subaccount_environment_instance) | resource |
28+
| [null_resource.cache_target_environment](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
29+
| [btp_subaccount_environments.all](https://registry.terraform.io/providers/SAP/btp/latest/docs/data-sources/subaccount_environments) | data source |
30+
31+
## Inputs
32+
33+
| Name | Description | Type | Default | Required |
34+
|------|-------------|------|---------|:--------:|
35+
| <a name="input_cf_org_name"></a> [cf\_org\_name](#input\_cf\_org\_name) | Name of the Cloud Foundry org. | `string` | n/a | yes |
36+
| <a name="input_instance_name"></a> [instance\_name](#input\_instance\_name) | Name of the Cloud Foundry environment instance. | `string` | n/a | yes |
37+
| <a name="input_plan_name"></a> [plan\_name](#input\_plan\_name) | Desired service plan for the Cloud Foundry environment instance. | `string` | `"standard"` | no |
38+
| <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 |
39+
40+
## Outputs
41+
42+
| Name | Description |
43+
|------|-------------|
44+
| <a name="output_cf_api_url"></a> [cf\_api\_url](#output\_cf\_api\_url) | The Cloud Foundry API URL |
45+
| <a name="output_cf_org_id"></a> [cf\_org\_id](#output\_cf\_org\_id) | The Cloud Foundry org ID |
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
data "btp_subaccount_environments" "all" {
2+
subaccount_id = var.subaccount_id
3+
}
4+
5+
resource "null_resource" "cache_target_environment" {
6+
triggers = {
7+
label = [for env in data.btp_subaccount_environments.all.values : env if env.service_name == "cloudfoundry" && env.environment_type == "cloudfoundry"][0].landscape_label
8+
}
9+
10+
lifecycle {
11+
ignore_changes = all
12+
}
13+
}
14+
15+
resource "btp_subaccount_environment_instance" "self" {
16+
subaccount_id = var.subaccount_id
17+
name = var.instance_name
18+
environment_type = "cloudfoundry"
19+
service_name = "cloudfoundry"
20+
plan_name = var.plan_name
21+
landscape_label = null_resource.cache_target_environment.triggers.label
22+
23+
parameters = jsonencode({
24+
instance_name = var.cf_org_name
25+
})
26+
}

0 commit comments

Comments
 (0)