Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding msi and rbac template #1260

Merged
merged 6 commits into from Jan 7, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/examples/101/create-managedidentity-rbac/README.md
@@ -0,0 +1,14 @@
# Azure User Managed Identity

This Bicep template deploys a user assigned managed identity and associates RBAC role to the MSI.

## Deployment steps ##

* [Install the Bicep CLI](https://github.com/Azure/bicep/blob/main/docs/installing.md) by following the instruction.
* Build the `main.bicep` file by running the Bicep CLI command:

```bash
bicep build ./main.bicep

New-AzResourceGroupDeployment -TemplateFile ./main.json -ResourceGroupName <resource group name> -Verbose
```
18 changes: 18 additions & 0 deletions docs/examples/101/create-managedidentity-rbac/main.bicep
@@ -0,0 +1,18 @@
param managedIdentityName string
param location string
param roleDefinitionId string = 'b24988ac-6180-42a0-ab88-20f7382dd24c' //Default as contributor role

resource msi 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' = {
name: managedIdentityName
location: location
}

resource roleassignment 'Microsoft.Authorization/roleAssignments@2020-04-01-preview' = {
name: guid(roleDefinitionId, resourceGroup().id)

properties: {
principalType: 'ServicePrincipal'
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', roleDefinitionId)
principalId: msi.properties.principalId
}
}
38 changes: 38 additions & 0 deletions docs/examples/101/create-managedidentity-rbac/main.json
@@ -0,0 +1,38 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"managedIdentityName": {
"type": "string"
},
"location": {
"type": "string"
},
"roleDefinitionId": {
"type": "string",
"defaultValue": "b24988ac-6180-42a0-ab88-20f7382dd24c"
}
},
"functions": [],
"resources": [
{
"type": "Microsoft.ManagedIdentity/userAssignedIdentities",
"apiVersion": "2018-11-30",
"name": "[parameters('managedIdentityName')]",
"location": "[parameters('location')]"
},
{
"type": "Microsoft.Authorization/roleAssignments",
"apiVersion": "2020-04-01-preview",
"name": "[guid(parameters('roleDefinitionId'), resourceGroup().id)]",
"properties": {
"principalType": "ServicePrincipal",
"roleDefinitionId": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions', parameters('roleDefinitionId'))]",
"principalId": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', parameters('managedIdentityName'))).principalId]"
},
"dependsOn": [
"[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', parameters('managedIdentityName'))]"
]
}
]
}
4 changes: 4 additions & 0 deletions docs/examples/index.json
Expand Up @@ -59,6 +59,10 @@
"filePath": "101/azurefirewall-create-with-zones/main.bicep",
"description": "101/azurefirewall-create-with-zones"
},
{
"filePath": "101/create-managedidentity-rbac/main.bicep",
"description": "101/create-managedidentity-rbac"
},
{
"filePath": "101/basic-publicip/main.bicep",
"description": "101/basic-publicip"
Expand Down