top of page
Writer's pictureSumit Raj

LetsDevOps: Azure Bicep -> Getting Started, A Step-by-Step Tutorial for Beginners.

Introduction

In this blog we will learn the basic of bicep, further we will setup it from scratch and deploy your first bicep template.


Prerequisites

  • Visual Studio Code

  • Azure CLI/ Az Module

What is Bicep

  • Bicep is azure native declarative, domain-specific language to deploy azure resources.

  • It helps to create resource manager template.

  • It is easy to understand and learn.

  • It simplifies the complexity of ARM json template.

Benefit of Bicep

  1. Simpler Syntax

  2. Module-specific

  3. Automatic Dependency Management

  4. Type validation and IntelliSense

Bicep Workflow






Setup Bicep


For creating bicep template you should have the Visual studio code Installed.


1. Download and Install VS Code from --> https://code.visualstudio.com/download


After Installation --> Open VS Code -->1. go to Extension -->2. search for Bicep -->3. Install



2. Check if the bicep cli installed if not you can follow the link below to install


bicep --version




3. Install Azure CLI or Powershell AZ if not installed.

az --version

Azure CLI


PowerShell AZ


Bicep basic keywords

  1. param

  2. var

  3. resource

  4. output

Description

Bicep Syntax

Bicep is declarative which means the elements can appear in any order.


param <parameter-name> <parameter-data-type> = <default-value>  
var <variable-name> = <variable-value>  

resource <resource-symbolic-name> '<resource-type>@<api-version>' =
 {   
    <resource-properties> 
}  
output <output-name> <output-data-type> = <output-value>


Create first bicep

Creating storage account


param staccount1 string = 'staccount0103'
param location string = 'East US'
resource staccount 'Microsoft.Storage/storageAccounts@2022-09-01'={
  name: staccount1
  kind: 'BlobStorage'
  location: location
  sku: {
    name: 'Standard_LRS'
  }
  properties:{
    accessTier: 'Cool'
  }
}

Run the bicep


Using AZ Module

# Set the variables
$resourceGroupName = "srsdemo"
$templateFilePath = "path/to/your/template.bicep"
$parametersFilePath = "path/to/your/parameters.json"
$deploymentName = "demodeploy"

# Authenticate to Azure
Connect-AzAccount

# Select the subscription (if necessary)
Set-AzContext -SubscriptionId "your-subscription-id"

# Deploy the Bicep template
New-AzResourceGroupDeployment `
  -DeploymentName $deploymentName `
  -ResourceGroupName $resourceGroupName `
  -TemplateFile $templateFilePath `
  -TemplateParameterFile $parametersFilePath

Using Azure CLI

$resourceGroupName = "test"
$deploymentName = "your11"
$bicepFile = "path/to/your/template.bicep"
$parametersFile = "path/to/your/parameters.json"

# Log in to Azure using the Azure CLI
az login

# Set the active subscription
az account set --subscription "your-subscription-id"

# Create the resource group if it doesn't exist
#az group create --name $resourceGroupName --location "your-location"

# Deploy the Bicep file
az deployment group create --name $deploymentName `
                           --resource-group $resourceGroupName `
                           --template-file $bicepFile `
                           --parameters $parametersFile


GitHub Repo


Demo










Comments


bottom of page