Skip to content

Commit 7b7b577

Browse files
authored
chore: Added new sample for role collection assignments (#346)
1 parent db3892f commit 7b7b577

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
locals {
2+
user_assignments = [
3+
for role in var.role_collection_assignments : [
4+
for user in role.users : {
5+
role_collection_name = role.role_collection_name
6+
user_name = user
7+
}
8+
]
9+
]
10+
}
11+
12+
resource "btp_subaccount_role_collection_assignment" "role_collection_assignment" {
13+
for_each = { for idx, assignment in flatten(local.user_assignments) : "${assignment.role_collection_name}-${assignment.user_name}" => assignment }
14+
15+
subaccount_id = var.subaccount_id
16+
role_collection_name = each.value.role_collection_name
17+
user_name = each.value.user_name
18+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
terraform {
3+
required_providers {
4+
btp = {
5+
source = "sap/btp"
6+
version = "~> 1.7.0"
7+
}
8+
}
9+
}
10+
11+
# Please checkout documentation on how best to authenticate against SAP BTP
12+
# via the Terraform provider for SAP BTP
13+
provider "btp" {
14+
globalaccount = var.globalaccount
15+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# BTP Role Collection Assignment
2+
3+
This Terraform configuration assigns role collections to users within an existing SAP BTP subaccount. The configuration does not create a new subaccount; it requires an existing subaccount ID to apply the assignments.
4+
5+
## Prerequisites
6+
7+
- Ensure you have the Subaccount Administrator role in the subaccount where you plan to assign role collections.
8+
9+
## Usage
10+
11+
### 1. Define Variables
12+
13+
Update the values of the following variables in your `terraform.tfvars` to match your setup:
14+
15+
- **`subaccount_id`**: The ID of the existing subaccount.
16+
- **`role_collection_assignments`**: A map of role collections and the users assigned to each. Each entry includes:
17+
- `role_collection_name`: Name of the role collection.
18+
- `users`: A list of users to assign to this role collection.
19+
20+
### 2. Example Variable Values
21+
22+
Here's an example of `terraform.tfvars` with sample input values:
23+
24+
```hcl
25+
subaccount_id = "your-existing-subaccount-id"
26+
27+
role_collection_assignments = [
28+
{
29+
role_collection_name = "Subaccount Service Administrator"
30+
31+
},
32+
{
33+
role_collection_name = "Subaccount Viewer"
34+
35+
},
36+
{
37+
role_collection_name = "Destination Administrator"
38+
39+
}
40+
]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
variable "globalaccount" {
2+
description = "Subdomain of your Globalaccount"
3+
type = string
4+
}
5+
6+
variable "subaccount_id" {
7+
description = "The ID of the existing subaccount."
8+
type = string
9+
}
10+
11+
variable "role_collection_assignments" {
12+
description = "A map of role collections and their assigned users."
13+
type = map(object({
14+
role_collection_name = string
15+
users = list(string)
16+
}))
17+
}
18+
19+
variable "cli_server_url" {
20+
type = string
21+
description = "The BTP CLI server URL."
22+
default = "https://cpcli.cf.eu10.hana.ondemand.com"
23+
}

0 commit comments

Comments
 (0)