Azure / Azure/Azure-Verified-Modules

[Question/Feedback]: Adding Scope to Role Assignment Variable

Open
#2,001 5 comments 0 reactions 1 assignee Claimed by @matt-FFFFFF View on GitHub
Language: Terraform :globe_with_meridians: Needs: Author Feedback :ear: Status: No Recent Activity :zzz: Type: Question/Feedback :raising_hand:
Dominant language
PowerShell
Stars
580
Forks
161
Avg merge
11h 3m
Merged PRs (30d)
15

Description

### Check for previous/existing GitHub issues

- [x] I have checked for previous/existing GitHub issues

### Description

# Issue Statement: Adding Scope to Role Assignment Variable in AVM Data Protection Backup Vault Module

## Problem

When developing the Azure Data Protection Backup Vault module, linting fails because interfaces don't support the 'scope' attribute, which is needed to assign roles to external resources through the `role_assignments` variable.

```terraform
# Current variable definition lacks scope
variable "role_assignments" {
type = map(object({
role_definition_id_or_name = string
principal_id = string
description = optional(string, null)
# scope is missing
}))
}
```

## Critical Workflow Issue

Our backup workflow follows this sequence:
1. Resource Group is created with base Terraform
2. Module creates Backup Vault with Managed Identity
3. Module creates Backup Policy
4. **⚠️ Managed Identity needs permissions on Resource Group**
5. Backup instances are created using the policy

The module fails when trying to assign Resource Group permissions in step 4 because:
1. The identity doesn't exist until step 2 (can't create assignment before module)
2. The backup instance in step 4 requires permissions to be already established
3. The current module can't assign permissions outside the vault itself

## Impact

PostgreSQL Flexible Server backups consistently fail with `ProtectionError`:
```
Error: waiting for Backup Instance...unexpected state 'ProtectionError'
```

This occurs because the Backup Vault's identity needs Reader permissions on the Resource Group, but our module can't assign these permissions.

## Proposed Solution

Add `scope` to the `role_assignments` variable:

```terraform
variable "role_assignments" {
type = map(object({
role_definition_id_or_name = string
principal_id = string
description = optional(string, null)
# Other existing attributes...
scope = optional(string, null) # Add this
}))
}
```

This change aligns with Azure best practices and would fix PostgreSQL backup scenarios where Resource Group permissions are required for successful operation.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.