This quickstart guides you through the steps to create a Bicep file with Visual Studio. You'll create a storage account and a virtual network. You'll also learn how the Bicep extension simplifies development by providing type safety, syntax validation, and autocompletion.
Launch Visual Studio and create a new file named main.bicep.
Visual Studio with the Bicep extension simplifies development by providing pre-defined snippets. In this quickstart, you'll add a snippet that creates a virtual network.
In main.bicep, type vnet. Select res-vnet from the list, and then press [TAB] or [ENTER].
Tip
If you don't see those intellisense options in Visual Studio, make sure you've installed the Bicep extension as specified in Prerequisites. If you have installed the extension, give the Bicep language service some time to start after opening your Bicep file. It usually starts quickly, but you will not have intellisense options until it starts.
This snippet contains all of the values you need to define a virtual network. However, you can modify this code to meet your requirements. For example, name isn't a great name for the virtual network. Change the name property to exampleVnet.
Bicep
name: 'exampleVnet'
Notice location has a red curly underline. This indicates a problem. Hover your cursor over location. The error message is - The name "location" doesn't exist in the current context. We'll create a location parameter in the next section.
Add parameters
Now, we'll add two parameters for the storage account name and the location. At the top of file, add:
Bicep
paramstorageName
When you add a space after storageName, notice that intellisense offers the data types that are available for the parameter. Select string.
You have the following parameter:
Bicep
paramstorageNamestring
This parameter works fine, but storage accounts have limits on the length of the name. The name must have at least 3 characters and no more than 24 characters. You can specify those requirements by adding decorators to the parameter.
Add a line above the parameter, and type @. You see the available decorators. Notice there are decorators for both minLength and maxLength.
Add both decorators and specify the character limits, as shown below:
You can also add a description for the parameter. Include information that helps people deploying the Bicep file understand the value to provide.
Bicep
@minLength(3)
@maxLength(24)
@description('Provide a name for the storage account. Use only lower case letters and numbers. The name must be unique across Azure.')paramstorageNamestring
The storage account name parameter is ready to use.
Add another location parameter:
Bicep
paramlocationstring = resourceGroup().location
Add resource
Instead of using a snippet to define the storage account, we'll use intellisense to set the values. Intellisense makes this step much easier than having to manually type the values.
To define a resource, use the resource keyword. Below your virtual network, type resource exampleStorage:
Bicep
resourceexampleStorage
exampleStorage is a symbolic name for the resource you're deploying. You can use this name to reference the resource in other parts of your Bicep file.
When you add a space after the symbolic name, a list of resource types is displayed. Continue typing storage until you can select it from the available options.
After selecting Microsoft.Storage/storageAccounts, you're presented with the available API versions. Select 2021-09-01 or the latest API version. We recommend using the latest API version.
After the single quote for the resource type, add = and a space. You're presented with options for adding properties to the resource. Select required-properties.
This option adds all of the properties for the resource type that are required for deployment. After selecting this option, your storage account has the following properties:
There are four placeholders in the code. Use [TAB] to go through them and enter the values. Again, intellisense helps you. Set name to storageName, which is the parameter that contains a name for the storage account. For location, set it to location. When adding SKU name and kind, intellisense presents the valid options.
When you've finished, you have:
Bicep
@minLength(3)
@maxLength(24)
@description('Provide a name for the storage account. Use only lower case letters and numbers. The name must be unique across Azure.')paramstorageNamestringparamlocationstring = resourceGroup().locationresourcevirtualNetwork'Microsoft.Network/virtualNetworks@2023-11-01' = {
name: storageNamelocation: locationproperties: {
addressSpace: {
addressPrefixes: [
'10.0.0.0/16'
]
}
subnets: [
{
name: 'Subnet-1'properties: {
addressPrefix: '10.0.0.0/24'
}
}
{
name: 'Subnet-2'properties: {
addressPrefix: '10.0.1.0/24'
}
}
]
}
}
resourceexampleStorage'Microsoft.Storage/storageAccounts@2023-04-01' = {
name: storageNamelocation: locationsku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
}
For more information about the Bicep syntax, see Bicep structure.
Deploy the Bicep file
Bicep file deployment can't be done from Visual Studio yet. You can deploy the Bicep file by using Azure CLI or Azure PowerShell:
az group create --name exampleRG --location eastus
az deployment group create --resource-group exampleRG --template-file main.bicep --parametersstorageName=uniquename
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.