Skip to content

Commit e4c17d3

Browse files
authored
Merge pull request #229465 from tfitzmac/0303paste
add paste as Bicep
2 parents fbf286d + 9a1c193 commit e4c17d3

File tree

4 files changed

+88
-9
lines changed

4 files changed

+88
-9
lines changed

articles/azure-resource-manager/bicep/decompile.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
title: Decompile ARM template JSON to Bicep
33
description: Describes commands for decompiling Azure Resource Manager templates to Bicep files.
44
ms.topic: conceptual
5-
ms.date: 11/11/2022
5+
ms.date: 03/03/2023
6+
ms.custom: devx-track-azurepowershell
67
---
78

89
# Decompiling ARM template JSON to Bicep
@@ -11,6 +12,8 @@ This article describes how to decompile Azure Resource Manager templates (ARM te
1112

1213
> [!NOTE]
1314
> From Visual Studio Code, you can directly create resource declarations by importing from existing resources. For more information, see [Bicep commands](./visual-studio-code.md#bicep-commands).
15+
>
16+
> Visual Studio Code enables you to paste JSON as Bicep. It automatically runs the decompile command. For more information, see [Paste JSON as Bicep](./visual-studio-code.md#paste-as-bicep-preview).
1417
1518
Decompiling an ARM template helps you get started with Bicep development. If you have a library of ARM templates and want to use Bicep for future development, you can decompile them to Bicep. However, the Bicep file might need revisions to implement best practices for Bicep.
1619

269 KB
Loading

articles/azure-resource-manager/bicep/migrate.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Describes the recommended workflow when migrating Azure resources a
44
author: joshuawaddell
55
ms.author: jowaddel
66
ms.topic: conceptual
7-
ms.date: 11/11/2022
7+
ms.date: 03/03/2023
88
---
99
# Migrate to Bicep
1010

@@ -32,6 +32,8 @@ The convert phase consists of two steps, which you complete in sequence:
3232

3333
> [!NOTE]
3434
> You can import a resource by opening the Visual Studio Code command palette. Use <kbd>Ctrl+Shift+P</kbd> on Windows and Linux and <kbd>⌘+Shift+P</kbd> on macOS.
35+
>
36+
> Visual Studio Code enables you to paste JSON as Bicep. For more information, see [Paste JSON as Bicep](./visual-studio-code.md#paste-as-bicep-preview).
3537
3638
## Phase 2: Migrate
3739

@@ -43,7 +45,7 @@ The migrate phase consists of three steps, which you complete in sequence:
4345

4446
1. **Copy each resource from your decompiled template.** Copy each resource individually from the converted Bicep file to the new Bicep file. This process helps you resolve any issues on a per-resource basis and to avoid any confusion as your template grows in size.
4547

46-
1. **Identify and recreate any missing resources.** Not all Azure resource types can be exported through the Azure portal, Azure CLI, or Azure PowerShell. For example, virtual machine extensions such as the DependencyAgentWindows and MMAExtension (Microsoft Monitoring Agent) aren't supported resource types for export. For any resource that wasn't exported, such as virtual machine extensions, you'll need to recreate those resources in your new Bicep file. You can recreate resources using a variety of tools and approaches, including [Azure Resource Explorer](../templates/export-template-portal.md?azure-portal=true), the [Bicep and ARM template reference documentation](/azure/templates/?azure-portal=true), and the [Azure Quickstart Templates](https://azure.microsoft.com/resources/templates?azure-portal=true) site.
48+
1. **Identify and recreate any missing resources.** Not all Azure resource types can be exported through the Azure portal, Azure CLI, or Azure PowerShell. For example, virtual machine extensions such as the DependencyAgentWindows and MMAExtension (Microsoft Monitoring Agent) aren't supported resource types for export. For any resource that wasn't exported, such as virtual machine extensions, you need to recreate those resources in your new Bicep file. You can recreate resources using various tools and approaches, including [Azure Resource Explorer](../templates/export-template-portal.md?azure-portal=true), the [Bicep and ARM template reference documentation](/azure/templates/?azure-portal=true), and the [Azure Quickstart Templates](https://azure.microsoft.com/resources/templates?azure-portal=true) site.
4749

4850
## Phase 3: Refactor
4951

@@ -55,7 +57,7 @@ The deploy phase consists of eight steps, which you complete in any order:
5557

5658
1. **Review the linter suggestions in your new Bicep file.** When you use the [Bicep extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-bicep&azure-portal=true) to create Bicep files, the [Bicep linter](linter.md) runs automatically and highlights suggestions and errors in your code. Many of the suggestions and errors include an option to apply a quick fix of the issue. Review these recommendations and adjust your Bicep file.
5759

58-
1. **Revise parameters, variables, and symbolic names.** It's possible the names of parameters, variables, and symbolic names generated by the decompiler won't match your standard naming convention. Review the generated names and make adjustments as necessary.
60+
1. **Revise parameters, variables, and symbolic names.** It's possible the names of parameters, variables, and symbolic names generated by the decompiler don't match your standard naming convention. Review the generated names and make adjustments as necessary.
5961

6062
1. **Simplify expressions.** The decompile process may not always take advantage of some of Bicep's features. Review any expressions generated in the conversion and simplify them. For example, the decompiled template may include a `concat()` or `format()` function that could be simplified by using [string interpolation](bicep-functions-string.md#concat). Review any suggestions from the linter and make adjustments as necessary.
6163

@@ -86,13 +88,13 @@ In the _deploy_ phase of migrating your resources to Bicep, the goal is to deplo
8688

8789
The deploy phase consists of four steps, which you complete in sequence:
8890

89-
1. **Prepare a rollback plan.** The ability to recover from a failed deployment is crucial. Create a rollback strategy in the event that any breaking changes are introduced into your environments. Take inventory of the types of resources that are deployed, such as virtual machines, web apps, and databases. Each resource's data plane should be considered as well. Do you have a way to recover a virtual machine and its data? Do you have a way to recover a database after deletion? A well-developed rollback plan will help to keep your downtime to a minimum if any issues arise from a deployment.
91+
1. **Prepare a rollback plan.** The ability to recover from a failed deployment is crucial. Create a rollback strategy if any breaking changes are introduced into your environments. Take inventory of the types of resources that are deployed, such as virtual machines, web apps, and databases. Each resource's data plane should be considered as well. Do you have a way to recover a virtual machine and its data? Do you have a way to recover a database after deletion? A well-developed rollback plan helps to keep your downtime to a minimum if any issues arise from a deployment.
9092

9193
1. **Run the what-if operation against production.** Before deploying your final Bicep file to production, run the what-if operation against your production environment, making sure to use production parameter values, and consider documenting the results.
9294

9395
1. **Deploy manually.** If you're going to use the converted template in a pipeline, such as [Azure DevOps](add-template-to-azure-pipelines.md) or [GitHub Actions](deploy-github-actions.md), consider running the deployment from your local machine first. It's preferable to test the template's functionality before incorporating it into your production pipeline. That way, you can respond quickly if there's a problem.
9496

95-
1. **Run smoke tests.** After your deployment is complete, you should run a series of *smoke tests* to ensure that your application or workload is working properly. For example, test to see if your web app is accessible through normal access channels, such as the public Internet or across a corporate VPN. For databases, attempt to make a database connection and execute a series of queries. With virtual machines, log in to the virtual machine and make sure that all services are up and running.
97+
1. **Run smoke tests.** After your deployment is complete, you should run a series of *smoke tests* to ensure that your application or workload is working properly. For example, test to see if your web app is accessible through normal access channels, such as the public Internet or across a corporate VPN. For databases, attempt to make a database connection and execute a series of queries. With virtual machines, sign in to the virtual machine and make sure that all services are up and running.
9698

9799
## Next steps
98100

articles/azure-resource-manager/bicep/visual-studio-code.md

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Create Bicep files by using Visual Studio Code
33
description: Describes how to create Bicep files by using Visual Studio Code
44
ms.topic: conceptual
5-
ms.date: 02/21/2023
5+
ms.date: 03/03/2023
66
---
77

88
# Create Bicep files by using Visual Studio Code
@@ -17,7 +17,7 @@ To set up your environment for Bicep development, see [Install Bicep tools](inst
1717

1818
Visual Studio Code comes with several Bicep commands.
1919

20-
Open or create a Bicep file in VS Code, select the **View** menu and then select **Command Palette**. You can also use the key combination **[CTRL]+[SHIFT]+P** to bring up the command palette. Type **Bicep** to list the Bicep commands.
20+
Open or create a Bicep file in VS Code, select the **View** menu and then select **Command Palette**. You can also use **F1** or the key combination <kbd>Ctrl+Shift+P</kbd> to bring up the command palette. Type **Bicep** to list the Bicep commands.
2121

2222
:::image type="content" source="./media/visual-studio-code/visual-studio-code-bicep-commands.png" alt-text="Screenshot of Visual Studio Code Bicep commands in the command palette.":::
2323

@@ -53,7 +53,7 @@ The [Bicep configuration file (bicepconfig.json)](./bicep-config.md) can be used
5353
To create a Bicep configuration file:
5454

5555
1. Open Visual Studio Code.
56-
1. From the **View** menu, select **Command Palette** (or press **[CTRL/CMD]**+**[SHIFT]**+**P**), and then select **Bicep: Create Bicep Configuration File**.
56+
1. From the **View** menu, select **Command Palette** (or press <kbd>Ctrl/Cmd+Shift+P</kbd>), and then select **Bicep: Create Bicep Configuration File**.
5757
1. Select the file directory where you want to place the file.
5858
1. Save the configuration file when you're done.
5959

@@ -124,6 +124,80 @@ From Visual Studio Code, you can easily open the template reference for the reso
124124

125125
:::image type="content" source="./media/visual-studio-code/visual-studio-code-bicep-view-type-document.png" alt-text="Screenshot of Visual Studio Code Bicep view type document.":::
126126

127+
## Paste as Bicep (Preview)
128+
129+
You can paste a JSON snippet from an ARM template to Bicep file. Visual Studio Code automatically decompiles the JSON to Bicep. This feature is only available with the Bicep extension version 0.14.0 or newer.
130+
131+
To enable the feature:
132+
133+
1. In Visual Studio Code, select **Manage** (gear icon) in the side menu. Select **Settings**. You can also use <kbd>Ctrl+,</kbd> to open settings.
134+
1. Expand **Extensions** and then select **Bicep**.
135+
1. Select **Decompile on Paste**.
136+
137+
:::image type="content" source="./media/visual-studio-code/enable-paste-json.png" alt-text="Screenshot of Visual Studio Code Paste as Bicep.":::
138+
139+
By using this feature, you can paste:
140+
141+
- Full ARM JSON templates.
142+
- Single resource or multiple resources.
143+
- JSON values, such as objects, arrays, and strings. A string with double-quotes is converted to single-quotes.
144+
145+
For example, you can start with the following Bicep file:
146+
147+
```bicep
148+
@description('Storage Account type')
149+
@allowed([
150+
'Standard_LRS'
151+
'Standard_GRS'
152+
'Standard_ZRS'
153+
'Premium_LRS'
154+
])
155+
param storageAccountsku string = 'Standard_LRS'
156+
157+
@description('Location for all resources.')
158+
param location string = resourceGroup().location
159+
160+
var storageAccountName = '${uniqueString(resourceGroup().id)}storage'
161+
162+
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-08-01' = {
163+
name: storageAccountName
164+
location: location
165+
sku: {
166+
name: storageAccountsku
167+
}
168+
kind: 'StorageV2'
169+
tags: {
170+
ObjectName: storageAccountName
171+
}
172+
properties: {}
173+
}
174+
175+
output storageAccountName string = storageAccountName
176+
```
177+
178+
And, paste the following JSON:
179+
180+
```json
181+
{
182+
"type": "Microsoft.Batch/batchAccounts",
183+
"apiVersion": "2021-06-01",
184+
"name": "[parameters('batchAccountName')]",
185+
"location": "[parameters('location')]",
186+
"tags": {
187+
"ObjectName": "[parameters('batchAccountName')]"
188+
},
189+
"properties": {
190+
"autoStorage": {
191+
"storageAccountId": "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
192+
}
193+
}
194+
}
195+
```
196+
197+
Visual Studio Code automatically converts the JSON to Bicep. Notice that you also need to add the parameter named `batchAccountName`.
198+
199+
You can undo the decompilation by using <kbd>Ctrl+Z</kbd>. The original JSON appears in the file.
200+
127201
## Next steps
128202

129203
To walk through a quickstart, see [Quickstart: Create Bicep files with Visual Studio Code](./quickstart-create-bicep-use-visual-studio-code.md).

0 commit comments

Comments
 (0)