diff --git a/avm/ptn/authorization/resource-role-assignment/README.md b/avm/ptn/authorization/resource-role-assignment/README.md index 19386cad59..2fa74eaa24 100644 --- a/avm/ptn/authorization/resource-role-assignment/README.md +++ b/avm/ptn/authorization/resource-role-assignment/README.md @@ -211,6 +211,7 @@ The unique guid name for the role assignment. - Required: No - Type: string +- Default: `[guid(parameters('resourceId'), parameters('principalId'), if(contains(parameters('roleDefinitionId'), '/providers/Microsoft.Authorization/roleDefinitions/'), parameters('roleDefinitionId'), subscriptionResourceId('Microsoft.Authorization/roleDefinitions', parameters('roleDefinitionId'))))]` ### Parameter: `principalType` diff --git a/avm/ptn/authorization/resource-role-assignment/main.bicep b/avm/ptn/authorization/resource-role-assignment/main.bicep index c6f4c838aa..675a38c2b9 100644 --- a/avm/ptn/authorization/resource-role-assignment/main.bicep +++ b/avm/ptn/authorization/resource-role-assignment/main.bicep @@ -6,7 +6,13 @@ metadata owner = 'Azure/module-maintainers' param resourceId string @sys.description('Optional. The unique guid name for the role assignment.') -param name string? +param name string = guid( + resourceId, + principalId, + contains(roleDefinitionId, '/providers/Microsoft.Authorization/roleDefinitions/') + ? roleDefinitionId + : subscriptionResourceId('Microsoft.Authorization/roleDefinitions', roleDefinitionId) +) @sys.description('Required. The role definition ID for the role assignment.') param roleDefinitionId string @@ -69,15 +75,7 @@ resource resourceRoleAssignment 'Microsoft.Resources/deployments@2023-07-01' = { value: resourceId } name: { - value: !empty(name) - ? name - : guid( - resourceId, - principalId, - contains(roleDefinitionId, '/providers/Microsoft.Authorization/roleDefinitions/') - ? roleDefinitionId - : subscriptionResourceId('Microsoft.Authorization/roleDefinitions', roleDefinitionId) - ) + value: name } roleDefinitionId: { value: contains(roleDefinitionId, '/providers/Microsoft.Authorization/roleDefinitions/') diff --git a/avm/ptn/authorization/resource-role-assignment/main.json b/avm/ptn/authorization/resource-role-assignment/main.json index 856d019b73..7271ed7a3a 100644 --- a/avm/ptn/authorization/resource-role-assignment/main.json +++ b/avm/ptn/authorization/resource-role-assignment/main.json @@ -1,12 +1,11 @@ { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", - "languageVersion": "2.0", "contentVersion": "1.0.0.0", "metadata": { "_generator": { "name": "bicep", "version": "0.26.170.59819", - "templateHash": "9533603348987584092" + "templateHash": "12472585536276024107" }, "name": "ResourceRole Assignments (All scopes)", "description": "This module deploys a Role Assignment for a specific resource.", @@ -21,7 +20,7 @@ }, "name": { "type": "string", - "nullable": true, + "defaultValue": "[guid(parameters('resourceId'), parameters('principalId'), if(contains(parameters('roleDefinitionId'), '/providers/Microsoft.Authorization/roleDefinitions/'), parameters('roleDefinitionId'), subscriptionResourceId('Microsoft.Authorization/roleDefinitions', parameters('roleDefinitionId'))))]", "metadata": { "description": "Optional. The unique guid name for the role assignment." } @@ -133,8 +132,8 @@ } } }, - "resources": { - "avmTelemetry": { + "resources": [ + { "condition": "[parameters('enableTelemetry')]", "type": "Microsoft.Resources/deployments", "apiVersion": "2023-07-01", @@ -154,7 +153,7 @@ } } }, - "resourceRoleAssignment": { + { "type": "Microsoft.Resources/deployments", "apiVersion": "2023-07-01", "name": "[format('{0}-ResourceRoleAssignment', guid(parameters('resourceId'), parameters('principalId'), parameters('roleDefinitionId')))]", @@ -169,7 +168,7 @@ "value": "[parameters('resourceId')]" }, "name": { - "value": "[if(not(empty(parameters('name'))), parameters('name'), guid(parameters('resourceId'), parameters('principalId'), if(contains(parameters('roleDefinitionId'), '/providers/Microsoft.Authorization/roleDefinitions/'), parameters('roleDefinitionId'), subscriptionResourceId('Microsoft.Authorization/roleDefinitions', parameters('roleDefinitionId')))))]" + "value": "[parameters('name')]" }, "roleDefinitionId": { "value": "[if(contains(parameters('roleDefinitionId'), '/providers/Microsoft.Authorization/roleDefinitions/'), parameters('roleDefinitionId'), subscriptionResourceId('Microsoft.Authorization/roleDefinitions', parameters('roleDefinitionId')))]" @@ -186,7 +185,7 @@ } } } - }, + ], "outputs": { "name": { "type": "string", @@ -207,7 +206,7 @@ "metadata": { "description": "The resource ID of the Role Assignment." }, - "value": "[reference('resourceRoleAssignment').outputs.roleAssignmentId.value]" + "value": "[reference(resourceId('Microsoft.Resources/deployments', format('{0}-ResourceRoleAssignment', guid(parameters('resourceId'), parameters('principalId'), parameters('roleDefinitionId')))), '2023-07-01').outputs.roleAssignmentId.value]" }, "resourceGroupName": { "type": "string", @@ -217,4 +216,4 @@ "value": "[resourceGroup().name]" } } -} \ No newline at end of file +}