Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions released/usecases/role_assignments/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
locals {
user_assignments = [
for role in var.role_collection_assignments : [
for user in role.users : {
role_collection_name = role.role_collection_name
user_name = user
}
]
]
}

resource "btp_subaccount_role_collection_assignment" "role_collection_assignment" {
for_each = { for idx, assignment in flatten(local.user_assignments) : "${assignment.role_collection_name}-${assignment.user_name}" => assignment }

subaccount_id = var.subaccount_id
role_collection_name = each.value.role_collection_name
user_name = each.value.user_name
}
15 changes: 15 additions & 0 deletions released/usecases/role_assignments/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

terraform {
required_providers {
btp = {
source = "sap/btp"
version = "~> 1.7.0"
}
}
}

# Please checkout documentation on how best to authenticate against SAP BTP
# via the Terraform provider for SAP BTP
provider "btp" {
globalaccount = var.globalaccount
}
40 changes: 40 additions & 0 deletions released/usecases/role_assignments/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# BTP Role Collection Assignment

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.

## Prerequisites

- Ensure you have the Subaccount Administrator role in the subaccount where you plan to assign role collections.

## Usage

### 1. Define Variables

Update the values of the following variables in your `terraform.tfvars` to match your setup:

- **`subaccount_id`**: The ID of the existing subaccount.
- **`role_collection_assignments`**: A map of role collections and the users assigned to each. Each entry includes:
- `role_collection_name`: Name of the role collection.
- `users`: A list of users to assign to this role collection.

### 2. Example Variable Values

Here's an example of `terraform.tfvars` with sample input values:

```hcl
subaccount_id = "your-existing-subaccount-id"

role_collection_assignments = [
{
role_collection_name = "Subaccount Service Administrator"
users = ["[email protected]", "[email protected]"]
},
{
role_collection_name = "Subaccount Viewer"
users = ["[email protected]", "[email protected]"]
},
{
role_collection_name = "Destination Administrator"
users = [ "[email protected]", "[email protected]"]
}
]
23 changes: 23 additions & 0 deletions released/usecases/role_assignments/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
variable "globalaccount" {
description = "Subdomain of your Globalaccount"
type = string
}

variable "subaccount_id" {
description = "The ID of the existing subaccount."
type = string
}

variable "role_collection_assignments" {
description = "A map of role collections and their assigned users."
type = map(object({
role_collection_name = string
users = list(string)
}))
}

variable "cli_server_url" {
type = string
description = "The BTP CLI server URL."
default = "https://cpcli.cf.eu10.hana.ondemand.com"
}