What is Insert Resource feature?

Recently Bicep v0.4.1124 was released and it contains very interesting "Insert Resource" feature. This feature allows you to create Bicep configuration from existing Azure resource 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 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 Insert Resource feature?

1. Open terminal in VS Code

2. Login to your Azure subscription

az login

3. Select right subscription

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

4. Open Azure Portal and select wanted resource

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


5. Create 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: {}