|
| 1 | + |
| 2 | +--- |
| 3 | +title: Migrate blueprint to deployment stack |
| 4 | +description: Learn how to migrate blueprint to deployment stack |
| 5 | +ms.topic: conceptual |
| 6 | +ms.custom: devx-track-bicep |
| 7 | +ms.date: 08/30/2024 |
| 8 | +--- |
| 9 | + |
| 10 | +# Migrate blueprint to deployment stack |
| 11 | + |
| 12 | +## Introduction |
| 13 | + |
| 14 | +## Migration steps |
| 15 | + |
| 16 | +1. Export the blueprint definitions into the blueprint definition JSON files which include the artifacts of Azure policies, Azure role assignments, and templates. For more information see [Export your blueprint defintion](../../governance/blueprints/how-to/import-export-ps#export-your-blueprint-definition). |
| 17 | +2. Convert the blueprint definitio JSON files into a single ARM template or Bicep file to be deployed via deployment stacks with the following considerations: |
| 18 | + |
| 19 | + - **Role assingments**: Convert any [role assignments](/azure/templates/microsoft.authorization/policyassignments) (special user permissions ??? ) first. |
| 20 | + - **Policies**: Convert any [policy assignments](/azure/templates/microsoft.authorization/policyassignments) into the Bicep (or ARM JSON template) syntax, and then add them to your main template. You can also embedd the [`policyDefinitions`](/azure/templates/microsoft.authorization/policydefinitions) into the JSON template. |
| 21 | + - **Templates**: Convert any templates into a main template for submission to a deployment stack. You can use [modules](./modules.md) in Bicep, embed templates as nested templates or template links, and optionally use [template specs](./template-specs.md) to store your templates in Azure. Template Specs are not required to leverage deployment stacks. |
| 22 | + - **Locks**: Deployment stack [DenySettingsMode](./deployment-stacks.md#protect-managed-resources) gives you the ability to block unwanted changes via `DenyDelete` and `DenyWriteAndDelete` (similar to [Blueprint locks](../../governance/blueprints/concepts/resource-locking.md). You can configure these via deployment stack commands. In order to leverage this, you need to corresponding roles to be able to set deny settings. For more information, see [Deployment stacks](./deployment-stacks.md). |
| 23 | + |
| 24 | + Define deny settings behavior (locks) |
| 25 | + |
| 26 | + - Microsoft.Authorization/locks ~ Deny Settings via Stack, therefore NO BICEP/JSON needed |
| 27 | + - Blueprint Lock setting DontDelete ~ --deny-settings-mode DenyDelete in Deployment Stacks |
| 28 | + - Blueprint Lock setting DontDelete ~ --deny-settings-mode DenyWriteAndDelete in Deployment Stacks |
| 29 | + |
| 30 | + Note: You can optionally control the excluded actions and principals to the deny assignment created by the specified deny setting mode. |
| 31 | + |
| 32 | +## Sample |
| 33 | + |
| 34 | +### Exported blueprint definition file |
| 35 | + |
| 36 | +```json |
| 37 | + |
| 38 | +``` |
| 39 | + |
| 40 | +### Converted Bicep file to be deployed to a deployment stack |
| 41 | + |
| 42 | +```bicep |
| 43 | +targetScope = 'subscription' |
| 44 | +
|
| 45 | +param roleAssignmentName string = 'myTestRoleAssignment' |
| 46 | +param roleDefinitionId string = guid(roleAssignmentName) |
| 47 | +param principalId string = guid('myTestId') |
| 48 | +
|
| 49 | +param policyAssignmentName string = 'myTestPolicyAssignment' |
| 50 | +param policyDefinitionID string = '/providers/Microsoft.Authorization/policyDefinitions/06a78e20-9358-41c9-923c-fb736d382a4d' |
| 51 | +
|
| 52 | +param rgName string = 'myTestRg' |
| 53 | +param rgLocation string = deployment().location |
| 54 | +param templateSpecName string = 'myNetworkingTs' |
| 55 | +
|
| 56 | +// Step 1 - create role assignments |
| 57 | +resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = { |
| 58 | + name: guid(roleAssignmentName) |
| 59 | + properties: { |
| 60 | + principalId: principalId |
| 61 | + roleDefinitionId: roleDefinitionId |
| 62 | + } |
| 63 | +} |
| 64 | +
|
| 65 | +// Step 2 - create policy assignments |
| 66 | +resource policyAssignment 'Microsoft.Authorization/policyAssignments@2022-06-01' = { |
| 67 | + name: policyAssignmentName |
| 68 | + scope: subscriptionResourceId('Microsoft.Resources/resourceGroups', resourceGroup().name) |
| 69 | + properties: { |
| 70 | + policyDefinitionId: policyDefinitionID |
| 71 | + } |
| 72 | +} |
| 73 | +
|
| 74 | +// Step 3 - create template artifacts via modules (or template specs) |
| 75 | +resource rg1 'Microsoft.Resources/resourceGroups@2021-01-01' = { |
| 76 | + name: rgName |
| 77 | + location: rgLocation |
| 78 | +} |
| 79 | +
|
| 80 | +module vnet 'templates/bicep/vnet.bicep' = if (rgName == 'myTestRg') { |
| 81 | + name: uniqueString(rgName) |
| 82 | + scope: rg1 |
| 83 | + params: { location: rgLocation } |
| 84 | +} |
| 85 | +``` |
0 commit comments