Azure Bicep - Insert Resource feature in VS Code

What is the Insert Resource feature?

Recently Bicep v0.4.1124 was released and it contains a very interesting "Insert Resource" feature. This feature allows you to create Bicep configuration from existing Azure resources in VS Code. This increases productivity if you're just now starting to invest infrastructure-as-a-code and most of the resources were deployed manually via Azure Portal.

You can also get an ARM template from the Azure Portal and decompile it to Bicep but this "Insert Resource" feature is more handy.

az bicep decompile --file main.json

How to use the Insert Resource feature?

1. Open the terminal in VS Code

2. Login to your Azure subscription

az login

3. Select the right subscription

az account set --subscription 00000000-0000-0000-0000-000000000000

4. Open Azure Portal and select a wanted resource

Check ResourceId from the properties page and copy it to the clipboard. ResourceId is something like this:

/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-webapp

5. Create a Bicep file in VS Code

6. Press F1 and write Bicep: Insert Resource

7. After that ResourceId is requested

Paste ResourceId here which was copied in Step 4

8. After that Bicep configuration of resource is created

@description('Generated from /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-webapp')
resource rgwebapp 'Microsoft.Resources/resourceGroups@2021-04-01' = {
  name: 'rg-webapp'
  location: 'westeurope'
  properties: {}
}

Comments