Skip to content
Closed
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
48 changes: 48 additions & 0 deletions modules/azure-role-assignment/.terraform-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
formatter: "markdown"

version: ""

header-from: docs/header.md
footer-from: docs/footer.md

recursive:
enabled: false
path: modules
include-main: true

sections:
hide: []
show: []

content: ""

output:
file: "README.md"
mode: inject
template: |-
<!-- BEGIN_TF_DOCS -->
{{ .Content }}
<!-- END_TF_DOCS -->

output-values:
enabled: false
from: ""

sort:
enabled: true
by: name

settings:
anchor: true
color: true
default: true
description: false
escape: true
hide-empty: false
html: true
indent: 2
lockfile: true
read-comments: true
required: true
sensitive: true
type: true
107 changes: 73 additions & 34 deletions modules/azure-role-assignment/README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,21 @@
# Role Assignment Module
<!-- BEGIN_TF_DOCS -->
# Azure Role Assignment Terraform Module

This module creates a User Assigned Identity in Azure and assigns it role-based access control (RBAC) policies based on the role definition name or identifier.
## Overview

## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.7.5 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | = 4.26.0 |
This Terraform module allows you to create role assignments (RBAC) for User Assigned Identities, Service Principals, Users, or Groups in Azure, using either role definition names or IDs.

## Resources
## Main features
- Assign roles to Service Principals, Users, or Groups at any scope.
- Support for both role definition names and IDs.
- Flexible configuration using HCL or YAML.
- Realistic configuration example.

| Name | Type |
|------|------|
| [azurerm_role_assignment](https://registry.terraform.io/providers/hashicorp/azurerm/4.26.0/docs/resources/role_assignment) | source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| role_assignments | A map of role assignments to create. The key is the scope, and the value is a map containing the role definition name and target ID. | `map(object({ scope = string type = string role_definition_name = optional(string) role_definition_id = optional(string) target_id = string }))` | `{}` | no |
| role_assignments.scope | The scope of the role assignment. | `string` | n/a | yes |
| role_assignments.type | The type of the role assignment. [`ServicePrincipal`, `Group`, `User`] | `string` | `ServicePrincipal` | no |
| role_assignments.role_definition_name | The name of the role definition. | `string` | n/a | yes |
| role_assignments.role_definition_id | The ID of the role definition. | `string` | n/a | yes |
| role_assignments.target_id | The ID of the target resource. | `string` | n/a | yes |

## Example
## Complete usage example

### HCL

```hcl
role_assignments = {
# Example role assignments
foo = {
scope = "/subscriptions/424f653a-bb14-441f-bc4a-6c4f3409cb41/resourceGroups/myResourceGroup"
role_definition_name = "Reader"
Expand All @@ -51,8 +29,7 @@ role_assignments = {
}
```

### Yaml

### YAML
```yaml
role_assignments:
foo:
Expand All @@ -64,3 +41,65 @@ role_assignments:
role_definition_id: "/subscriptions/424f653a-bb14-441f-bc4a-6c4f3409cb41/providers/Microsoft.Authorization/roleDefinitions/12345678-1234-1234-1234-123456789012"
target_id: "87654321-4321-4321-4321-210987654321"
```

## Notes
- You can use either `role_definition_name` or `role_definition_id` for each assignment.
- The `target_id` can be a Service Principal, User, or Group object ID.
- Assignments can be created at any Azure scope (subscription, resource group, resource, etc).

## File structure

```
.
├── role_assignment.tf
├── variables.tf
├── versions.tf
├── README.md
├── CHANGELOG.md
└── docs/
├── header.md
└── footer.md
```

## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.7.3 |
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | ~> 4.26.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | ~> 4.26.0 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [azurerm_role_assignment.role_assignment](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_role_assignments"></a> [role\_assignments](#input\_role\_assignments) | A map of role assignments to create. The key is the scope, and the value is a map containing the role definition name and target ID. | <pre>map(object({<br/> scope = string<br/> target_id = string<br/> type = optional(string, "ServicePrincipal")<br/> role_definition_name = optional(string)<br/> role_definition_id = optional(string)<br/> }))</pre> | `{}` | no |
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The input description says 'The key is the scope', but the provided examples use keys like 'foo' and 'bar' and place the scope inside the object. This is misleading for module consumers. Update the variable description (source of terraform-docs output) to reflect that the map key is an arbitrary assignment name/key, while 'scope' is a field in the value object.

Suggested change
| <a name="input_role_assignments"></a> [role\_assignments](#input\_role\_assignments) | A map of role assignments to create. The key is the scope, and the value is a map containing the role definition name and target ID. | <pre>map(object({<br/> scope = string<br/> target_id = string<br/> type = optional(string, "ServicePrincipal")<br/> role_definition_name = optional(string)<br/> role_definition_id = optional(string)<br/> }))</pre> | `{}` | no |
| <a name="input_role_assignments"></a> [role\_assignments](#input\_role\_assignments) | A map of role assignments to create. Each key is an arbitrary assignment name/key, and each value is an object containing the scope, target ID, and role definition configuration. | <pre>map(object({<br/> scope = string<br/> target_id = string<br/> type = optional(string, "ServicePrincipal")<br/> role_definition_name = optional(string)<br/> role_definition_id = optional(string)<br/> }))</pre> | `{}` | no |

Copilot uses AI. Check for mistakes.

## Outputs

No outputs.

## Resources and support

- [Official Azure Role Assignment documentation](https://learn.microsoft.com/en-us/azure/role-based-access-control/role-assignments-portal)
- [Terraform reference for azurerm\_role\_assignment](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment)

## Support

For issues, questions, or contributions related to this module, please visit the [repository's issue tracker](https://github.com/prefapp/tfm/issues).
<!-- END_TF_DOCS -->
16 changes: 16 additions & 0 deletions modules/azure-role-assignment/_examples/basic/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module "azure_role_assignment" {
source = "../../"

role_assignments = {
foo = {
scope = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup"
role_definition_name = "Reader"
target_id = "12345678-1234-1234-1234-123456789012"
}
bar = {
scope = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"
role_definition_id = "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions/12345678-1234-1234-1234-123456789012"
target_id = "87654321-4321-4321-4321-210987654321"
}
}
}
9 changes: 9 additions & 0 deletions modules/azure-role-assignment/_examples/basic/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
role_assignments:
foo:
scope: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup
role_definition_name: Reader
target_id: 12345678-1234-1234-1234-123456789012
bar:
scope: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM
role_definition_id: /subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions/12345678-1234-1234-1234-123456789012
target_id: 87654321-4321-4321-4321-210987654321
8 changes: 8 additions & 0 deletions modules/azure-role-assignment/docs/footer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Resources and support

- [Official Azure Role Assignment documentation](https://learn.microsoft.com/en-us/azure/role-based-access-control/role-assignments-portal)
- [Terraform reference for azurerm_role_assignment](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment)

## Support

For issues, questions, or contributions related to this module, please visit the [repository's issue tracker](https://github.com/prefapp/tfm/issues).
61 changes: 61 additions & 0 deletions modules/azure-role-assignment/docs/header.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Azure Role Assignment Terraform Module

## Overview

This Terraform module allows you to create role assignments (RBAC) for User Assigned Identities, Service Principals, Users, or Groups in Azure, using either role definition names or IDs.

## Main features
- Assign roles to Service Principals, Users, or Groups at any scope.
- Support for both role definition names and IDs.
- Flexible configuration using HCL or YAML.
- Realistic configuration example.

## Complete usage example

### HCL
```hcl
role_assignments = {
foo = {
scope = "/subscriptions/424f653a-bb14-441f-bc4a-6c4f3409cb41/resourceGroups/myResourceGroup"
role_definition_name = "Reader"
target_id = "12345678-1234-1234-1234-123456789012"
},
bar = {
scope = "/subscriptions/424f653a-bb14-441f-bc4a-6c4f3409cb41/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"
role_definition_id = "/subscriptions/424f653a-bb14-441f-bc4a-6c4f3409cb41/providers/Microsoft.Authorization/roleDefinitions/12345678-1234-1234-1234-123456789012"
target_id = "87654321-4321-4321-4321-210987654321"
}
}
```

### YAML
```yaml
role_assignments:
foo:
scope: "/subscriptions/424f653a-bb14-441f-bc4a-6c4f3409cb41/resourceGroups/myResourceGroup"
role_definition_name: "Reader"
target_id: "12345678-1234-1234-1234-123456789012"
bar:
scope: "/subscriptions/424f653a-bb14-441f-bc4a-6c4f3409cb41/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"
role_definition_id: "/subscriptions/424f653a-bb14-441f-bc4a-6c4f3409cb41/providers/Microsoft.Authorization/roleDefinitions/12345678-1234-1234-1234-123456789012"
target_id: "87654321-4321-4321-4321-210987654321"
```

## Notes
- You can use either `role_definition_name` or `role_definition_id` for each assignment.
- The `target_id` can be a Service Principal, User, or Group object ID.
- Assignments can be created at any Azure scope (subscription, resource group, resource, etc).

## File structure

```
.
├── role_assignment.tf
├── variables.tf
├── versions.tf
├── README.md
├── CHANGELOG.md
└── docs/
├── header.md
└── footer.md
```