Reading Time: 3 minutes

In this article, we will go through the steps to bring existing Azure resource configurations into a Bicep template using Visual Studio Code.

Getting started

Install the Azure Bicep extension for Visual Studio Code

The first step is to install the Azure Bicep extension for Visual Studio Code. You can do this by opening Visual Studio Code, navigating to the extensions tab, searching for “Azure Bicep,” and clicking on “Install.”

Finding the resource id

The easiest and most convenient way to acquire the resource Id of an Azure resource would be through the Azure Portal.

Other possible methods:

  • Azure resource extension for Visual Studio Code
  • Azure PowerShell
  • Azure CLI

Create a new Bicep file

Create an empty Bicep template or just use an existing one. You can do this by opening Visual Studio Code, selecting “File” from the menu, and then selecting “New File.” Name the file and save it with the “.bicep” extension.

Import existing resources

The Bicep insert feature of the Bicep extension for VSCode is a powerful tool that allows you to insert existing Azure resource configurations directly into your Bicep file. To use this feature, follow these steps:

  1. Open the Bicep file you created earlier in Visual Studio Code.
  2. Right-click on the Bicep file and select “Insert resource“.
  3. In the top search bar, paste the resource Id of the Azure resource you want to insert, wait for a few moments for resource configuration to be populated within the template.

Visual Studio Code will then insert the Bicep code for the selected Azure resource into your file. You can then modify the code to customize the resource for your needs.

Review and modify inserted code

After inserting the code for the Azure resource, review it to ensure that it meets your requirements. You may need to modify the code to specify additional parameters or customize the resource for your needs.

For example, if you are importing an Azure storage account, you may need to specify the storage account name, location, and other properties specific to your use case.

Deploy the Bicep Template

Once you have imported and modified the existing Azure resource configurations in your Bicep file, you can deploy the Bicep template to create new or modify existing resources on Azure. To do this, you can use the Azure CLI or other deployment tools such as Azure DevOps or GitHub Actions.

In conclusion, the Bicep insert feature in Visual Studio Code is a powerful tool that can save time and effort when creating Bicep templates for Azure resources. By importing and modifying existing resource configurations, you can easily create consistent and reproducible infrastructure on Azure.

Thanks for reading my blog!

Feel free to drop your comment or question below.