Skip to content

Commit b38b87b

Browse files
authored
Merge pull request #198130 from schaffererin/role-assignment-bicep-quickstart
Creating new Bicep quickstart - RBAC role assignment
2 parents 530c247 + 18a531b commit b38b87b

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

articles/azure-resource-manager/bicep/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@
132132
items:
133133
- name: Resource Graph
134134
href: ../../governance/resource-graph/shared-query-bicep.md?toc=/azure/azure-resource-manager/bicep/toc.json
135+
- name: Role-based access control - role assignment
136+
href: ../../role-based-access-control/quickstart-role-assignments-bicep.md?toc=/azure/azure-resource-manager/bicep/toc.json
135137
- name: Site Recovery
136138
href: ../../site-recovery/quickstart-create-vault-bicep.md?toc=/azure/azure-resource-manager/bicep/toc.json
137139
- name: Media Services

articles/role-based-access-control/TOC.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
items:
1414
- name: Check access for a user
1515
href: check-access.md
16+
- name: Bicep
17+
displayName: ARM, Resource Manager, Template
18+
href: quickstart-role-assignments-bicep.md
1619
- name: ARM template
1720
displayName: Resource Manager
1821
href: quickstart-role-assignments-template.md
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
title: "Quickstart: Assign an Azure role using Bicep - Azure RBAC"
3+
description: Learn how to grant access to Azure resources for a user at resource group scope using Bicep and Azure role-based access control (Azure RBAC).
4+
services: role-based-access-control,azure-resource-manager
5+
author: schaffererin
6+
ms.service: role-based-access-control
7+
ms.topic: quickstart
8+
ms.custom: subject-armqs, mode-arm
9+
ms.workload: identity
10+
ms.date: 06/30/2022
11+
ms.author: v-eschaffer
12+
#Customer intent: As a new user, I want to see how to grant access to resources using Bicep so that I can start automating role assignment processes.
13+
---
14+
15+
# Quickstart: Assign an Azure role using Bicep
16+
17+
[Azure role-based access control (Azure RBAC)](overview.md) is the way that you manage access to Azure resources. In this quickstart, you create a resource group and grant a user access to create and manage virtual machines in the resource group. This quickstart uses Bicep to grant the access.
18+
19+
[!INCLUDE [About Bicep](../../includes/resource-manager-quickstart-bicep-introduction.md)]
20+
21+
## Prerequisites
22+
23+
To assign Azure roles and remove role assignments, you must have:
24+
25+
- If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
26+
- `Microsoft.Authorization/roleAssignments/write` and `Microsoft.Authorization/roleAssignments/delete` permissions, such as [User Access Administrator](built-in-roles.md#user-access-administrator) or [Owner](built-in-roles.md#owner).
27+
- To assign a role, you must specify three elements: security principal, role definition, and scope. For this quickstart, the security principal is you or another user in your directory, the role definition is [Virtual Machine Contributor](built-in-roles.md#virtual-machine-contributor), and the scope is a resource group that you specify.
28+
29+
## Review the Bicep file
30+
31+
The Bicep file used in this quickstart is from [Azure Quickstart Templates](https://azure.microsoft.com/resources/templates/rbac-builtinrole-resourcegroup/). The Bicep file has two parameters and a resources section. In the resources section, notice that it has the three elements of a role assignment: security principal, role definition, and scope.
32+
33+
:::code language="bicep" source="~/quickstart-templates/quickstarts/microsoft.authorization/rbac-builtinrole-resourcegroup/main.bicep":::
34+
35+
The resource defined in the Bicep file is:
36+
37+
- [Microsoft.Authorization/roleAssignments](/azure/templates/Microsoft.Authorization/roleAssignments)
38+
39+
## Deploy the Bicep file
40+
41+
1. Save the Bicep file as **main.bicep** to your local computer.
42+
1. Deploy the Bicep file using either Azure CLI or Azure PowerShell.
43+
44+
# [CLI](#tab/CLI)
45+
46+
```azurecli
47+
az group create --name exampleRG --location eastus
48+
az deployment group create --resource-group exampleRG --template-file main.bicep --parameters roleDefinitionID=9980e02c-c2be-4d73-94e8-173b1dc7cf3c principalId=<principal-id>
49+
```
50+
51+
# [PowerShell](#tab/PowerShell)
52+
53+
```azurepowershell
54+
New-AzResourceGroup -Name exampleRG -Location eastus
55+
New-AzResourceGroupDeployment -ResourceGroupName exampleRG -TemplateFile ./main.bicep -roleDefinitionID "9980e02c-c2be-4d73-94e8-173b1dc7cf3c" -principalId "<principal-id>"
56+
```
57+
58+
---
59+
60+
> [!NOTE]
61+
> Replace **\<principal-id\>** with the principal ID assigned to the role.
62+
63+
When the deployment finishes, you should see a message indicating the deployment succeeded.
64+
65+
## Review deployed resources
66+
67+
Use the Azure portal, Azure CLI, or Azure PowerShell to list the deployed resources in the resource group.
68+
69+
# [CLI](#tab/CLI)
70+
71+
```azurecli-interactive
72+
az role assignment list --resource-group exampleRG
73+
```
74+
75+
# [PowerShell](#tab/PowerShell)
76+
77+
```azurepowershell-interactive
78+
Get-AzRoleAssignment -ResourceGroupName exampleRG
79+
```
80+
81+
---
82+
83+
## Clean up resources
84+
85+
When no longer needed, use the Azure portal, Azure CLI, or Azure PowerShell to remove the role assignment. For more information, see [Remove Azure role assignments](role-assignments-remove.md).
86+
87+
Use the Azure portal, Azure CLI, or Azure PowerShell to delete the resource group.
88+
89+
# [CLI](#tab/CLI)
90+
91+
```azurecli-interactive
92+
az group delete --name exampleRG
93+
```
94+
95+
# [PowerShell](#tab/PowerShell)
96+
97+
```azurepowershell-interactive
98+
Remove-AzResourceGroup -Name exampleRG
99+
```
100+
101+
---
102+
103+
## Next steps
104+
105+
> [!div class="nextstepaction"]
106+
> [Tutorial: Grant a user access to Azure resources using Azure PowerShell](tutorial-role-assignments-user-powershell.md)

0 commit comments

Comments
 (0)