Skip to content

Commit f2fd128

Browse files
committed
feat: enhancements of subaccount setup
1 parent fe1113f commit f2fd128

File tree

13 files changed

+105
-24
lines changed

13 files changed

+105
-24
lines changed

sample-setup/README.md

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,17 @@
22

33
## Paradigms
44

5-
We follow the paradigms of a simpel and clear Terraform configuration as laid out in the [Simple, Clear, Maintainable](https://rosesecurity.dev/blog/2024/11/24/terraform-proverbs) blog post of the [Development Log](https://rosesecurity.dev/) namely:
5+
We follow the paradigms of a simpel and clear Terraform configuration as laid out in the [Simple, Clear, Maintainable](https://rosesecurity.dev/blog/2024/11/24/terraform-proverbs) blog post of the [Development Log](https://rosesecurity.dev/) especially:
66

77
- Clear is better than clever.
8-
- Version everything.
98
- Modules should be reusable, not rigid.
10-
- State is a liability; manage it wisely.
11-
- Every apply should be predictable.
129
- Outputs are for sharing.
13-
- Tags are free; use them liberally.
14-
- Understanding count versus for_each is essential.
10+
- Labels are free; use them liberally.
1511
- Descriptions are for users.
1612
- Use positive variable names to avoid double negatives.
17-
- Null is not the same as nothing.
18-
- Prefer a single object over many related variables.
19-
- Terraform is declarative; trust it to converge.
20-
- Never output secrets.
21-
- Upgrade deliberately, not impulsively.
2213
- Name with underscores, not dashes.
2314
- Using locals makes code descriptive and maintainable.
2415

25-
These paradigms will be reflected in the code samples provided in this repository and we encourage you to follow them in your own Terraform code.
26-
2716
## Naming Conventions and Tagging
2817

2918
Ensuring naming conventions is one import aspect when provisioing and managing your SAP BTP account. We will align our samples in accordance to the [Naming Conventions for SAP BTP Accounts](https://help.sap.com/docs/btp/btp-admin-guide/naming-conventions-for-sap-btp-accounts).

sample-setup/basic-setup/subaccount-setup/.terraform.lock.hcl

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
- Validation of Geo Region and Subaccount region
66
- Default Setup of custom IdP
77
- Provision CF env (optional)
8+
- Execute default plus à la carte entitlements

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,28 @@ resource "btp_subaccount_trust_configuration" "custom_idp" {
4747
available_for_user_logon = true
4848
}
4949

50+
module "subaccount_default_entitlements" {
51+
source = "../../modules/sap-btp-subaccount-default-entitlements"
52+
53+
stage = var.stage
54+
}
55+
56+
locals {
57+
finalized_entitlements = var.additional_entitlements == {} ? module.subaccount_default_entitlements.default_entitlements_for_stage : merge(
58+
module.subaccount_default_entitlements.default_entitlements_for_stage,
59+
var.additional_entitlements
60+
)
61+
}
62+
63+
module "sap_btp_entitlements" {
64+
65+
source = "aydin-ozcan/sap-btp-entitlements/btp"
66+
version = "~> 1.0.1"
67+
68+
subaccount = btp_subaccount.self.id
69+
entitlements = local.finalized_entitlements
70+
}
71+
5072
module "cf_environment" {
5173
source = "../../modules/sap-btp-environment/CloudFoundry"
5274

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
output "subaccount_url" {
2-
value = "https://emea.cockpit.btp.cloud.sap/cockpit/#globalaccount/${data.btp_globalaccount.this.id}/subaccount/${btp_subaccount.project_subaccount.id}"
2+
value = "https://emea.cockpit.btp.cloud.sap/cockpit/#globalaccount/${data.btp_globalaccount.this.id}/subaccount/${btp_subaccount.self.id}/overview"
33
description = "The URL to the provisioned subaccount on SAP BTP"
44
}
55

66
output "cf_api_url" {
7-
value = module.cf_environment.cf_api_url
7+
value = var.provision_cf_environment ? module.cf_environment[0].cf_api_url : "No Cloud Foundry environment was requested to be provisioned"
88
description = "The Cloud Foundry API URL"
99
}
1010

1111
output "cf_org_id" {
12-
value = module.cf_environment.cf_org_id
12+
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
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ variable "custom_indentity_provider" {
6565
description = "Custom IdP to be used for subaccount"
6666
}
6767

68+
variable "additional_entitlements" {
69+
type = map(list(string))
70+
description = "Entitlements to be provided in addition to the standard entitlements"
71+
default = {}
72+
}
73+
6874
variable "provision_cf_environment" {
6975
type = bool
7076
description = "Provision Cloud Foundry environment in subaccount"

sample-setup/modules/sap-btp-naming-conventions-directory/main.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
locals {
2-
costcenter_label_name = "Costcenter"
3-
directory_contact_label_name = "Directory responsibles"
4-
managedby_label_name = "Managed by"
2+
costcenter_label_name = "Costcenter"
3+
directory_contact_label_name = "Directory responsibles"
4+
managedby_label_name = "Managed by"
55

66
directory_name = var.region == null ? var.business_unit : format(
77
"%s%s%s",
@@ -19,9 +19,9 @@ locals {
1919
var.region
2020
)
2121

22-
costcenter_label_name_formatted = var.label_name_case == "lower" ? lower(local.costcenter_label_name) : var.label_name_case == "title" ? title(local.costcenter_label_name) : upper(local.costcenter_label_name)
23-
directory_contact_label_name_formatted = var.label_name_case == "lower" ? lower(local.directory_contact_label_name) : var.label_name_case == "title" ? title(local.directory_contact_label_name) : upper(local.directory_contact_label_name)
24-
managedby_label_name_formatted = var.label_name_case == "lower" ? lower(local.managedby_label_name) : var.label_name_case == "title" ? title(local.managedby_label_name) : upper(local.managedby_label_name)
22+
costcenter_label_name_formatted = var.label_name_case == "lower" ? lower(local.costcenter_label_name) : var.label_name_case == "title" ? title(local.costcenter_label_name) : upper(local.costcenter_label_name)
23+
directory_contact_label_name_formatted = var.label_name_case == "lower" ? lower(local.directory_contact_label_name) : var.label_name_case == "title" ? title(local.directory_contact_label_name) : upper(local.directory_contact_label_name)
24+
managedby_label_name_formatted = var.label_name_case == "lower" ? lower(local.managedby_label_name) : var.label_name_case == "title" ? title(local.managedby_label_name) : upper(local.managedby_label_name)
2525

2626
costcenter_label_value_formatted = var.label_value_case == "lower" ? lower(var.costcenter) : var.label_value_case == "title" ? title(var.costcenter) : var.label_value_case == "upper" ? upper(var.costcenter) : var.costcenter
2727
management_label_value_formatted = var.label_value_case == "lower" ? lower(var.management_tool) : var.label_value_case == "title" ? title(var.management_tool) : var.label_value_case == "upper" ? upper(var.management_tool) : var.management_tool

sample-setup/modules/sap-btp-naming-conventions-subaccount/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,5 @@ locals {
8080

8181
subaccount_usage = var.stage == "Prod" ? "USED_FOR_PRODUCTION" : "NOT_USED_FOR_PRODUCTION"
8282

83-
cloudfoundry_org_name = local.subaccount_subdomain
83+
cloudfoundry_org_name = substr(local.subaccount_subdomain, 0, 32)
8484
}

sample-setup/modules/sap-btp-naming-conventions-subaccount/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ variable "company_name" {
2222
Company name to be used for subaccount subdomains. The parameter is optional
2323
Default value: `null`.
2424
EOT
25-
default = null
25+
default = null
2626
}
2727

2828
variable "costcenter" {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
locals {
2+
default_entitlements = {
3+
"Dev" = {
4+
"alert-notification" = ["standard"],
5+
"auditlog" = ["standard=1"],
6+
"sapappstudio" = ["build-code"],
7+
"xsuaa" = ["application"]
8+
},
9+
"Test" = {
10+
"alert-notification" = ["standard"],
11+
"auditlog" = ["standard=1"],
12+
"xsuaa" = ["application"]
13+
},
14+
"Prod" = {
15+
"alert-notification" = ["standard"],
16+
"auditlog" = ["standard=1"],
17+
"xsuaa" = ["application"]
18+
},
19+
"Shared" = {
20+
"credstore" = ["standard"],
21+
"hana-cloud" = ["hana"],
22+
"hana" = ["hdi-shared"]
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)