Skip to content

Commit 310160f

Browse files
authored
feat: app identifier for role collections (#455)
Co-authored-by: Christian Lechner <[email protected]>
1 parent d495bac commit 310160f

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Creation of role collections
2+
3+
In some scenarios the creation of a service instance or an app subscription only creates the roles but leaves the creation of the role collections to the user. The biggest pain point when automating this setup is to fetch the correct app identifier.
4+
5+
In this setup we want to show how you can fetch this identifier and use it to create the role collections.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
resource "btp_subaccount" "self" {
2+
name = "My Dev Project"
3+
subdomain = "my-dev-project"
4+
region = var.region
5+
}
6+
7+
resource "btp_subaccount_entitlement" "auditlog-management_default" {
8+
subaccount_id = btp_subaccount.self.id
9+
service_name = "auditlog-management"
10+
plan_name = "default"
11+
}
12+
13+
data "btp_subaccount_service_plan" "auditlog_default" {
14+
name = "default"
15+
offering_name = "auditlog-management"
16+
subaccount_id = btp_subaccount.self.id
17+
18+
depends_on = [btp_subaccount_entitlement.auditlog-management_default]
19+
}
20+
21+
resource "btp_subaccount_service_instance" "auditlog_default" {
22+
name = "auditlog-default-dev"
23+
serviceplan_id = data.btp_subaccount_service_plan.auditlog_default.id
24+
subaccount_id = btp_subaccount.self.id
25+
}
26+
27+
data "btp_subaccount_apps" "all" {
28+
subaccount_id = btp_subaccount.self.id
29+
30+
depends_on = [btp_subaccount_service_instance.auditlog_default]
31+
}
32+
33+
locals {
34+
app_id = try(
35+
{ for app in data.btp_subaccount_apps.all.values : app.xsappname => app.id
36+
if app.xsappname == "auditlog-management" }
37+
)
38+
}
39+
40+
resource "btp_subaccount_role_collection" "auditlog-viewer" {
41+
42+
description = "Audit Log Viewer Role Collection"
43+
name = "Audit Log Viewer"
44+
roles = [
45+
{
46+
name = "Auditlog_Auditor"
47+
role_template_app_id = local.app_id.auditlog-management
48+
role_template_name = "Auditlog_Auditor"
49+
},
50+
]
51+
subaccount_id = btp_subaccount.self.id
52+
53+
depends_on = [data.btp_subaccount_apps.all]
54+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
terraform {
2+
required_providers {
3+
btp = {
4+
source = "sap/btp"
5+
version = "~>1.12.0"
6+
}
7+
}
8+
}
9+
10+
# Please checkout documentation on how best to authenticate against SAP BTP
11+
# via the Terraform provider for SAP BTP
12+
provider "btp" {
13+
globalaccount = var.globalaccount
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
variable "globalaccount" {
2+
description = "The subdomainof the global account to use for the SAP BTP provider"
3+
type = string
4+
}
5+
6+
variable "region" {
7+
description = "The region of the subaccount"
8+
type = string
9+
default = "us10"
10+
}

0 commit comments

Comments
 (0)