头图

Hello, everyone, I am a researcher in this issue-Yun Gan. Today I will explain to you how to install Bicep and deploy Azure resources with Bicep through examples. Bicep is a domain-specific language for declarative deployment of Azure resources. It has a clearer grammar and can completely simplify the writing experience. Next, let us start exploring together in the laboratory!

Microsoft MVP Lab Researcher

image.png

Analysis of Thinking

Everyone who has used IAC tools knows. In Azure ARM JSON, all parameters, variables, and output must be declared in the corresponding part of the template, and there are certain restrictions.

In this experiment, we can use Azure Bicep to deploy Azure resources smartly. It is simpler than JSON syntax and does not need to write too many parameter settings. Bicep is a domain-specific language for declarative deployment of Azure resources. Its goal is to radically simplify the writing experience through clearer syntax, improved type safety, and better support for modularity and code reuse.

Bicep is actually a transparent abstraction of the ARM template. The Bicep code is parsed into a standard JSON file, which effectively treats the ARM template as an intermediate language (IL). Bicep is not a general programming language for writing applications, but a language for declaring Azure resources and resource attributes. Simply put, it is used to develop Azure ARM templates.

The general idea is this, first we need to install Azure CLI and Biecp CLI in the development environment. Then, use the Bicep plug-in in VS Code to implement the Biecp file that declares Azure resources. Finally, we use Azure CLI in conjunction with Bicep files to deploy resources to Azure.

Install Bicep tool

(1) VS Code editor installs the Bicep plug-in
image.png

(2) Install Bicep CLI

1) Manual installation using Azure CLI
az bicep install
image.png

2) Manually install using Chocolatey

choco install bicep
image.png

Create Bicep file

Create a main file with the suffix bicep in the Bicep project directory. At this time, the .NET runtime will be downloaded. Wait a moment.
image.png

The declaration of Azure resources starts with the most familiar resource group. Enter "res-rg" in the "main.bicep" file and press Tab to complete the code. Add the scope of Scope, as shown in the figure below.

targetScope='subscription'

resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = {
  name: 'Web_Test_Bicep_RG'
  location: 'EastAsia'
  tags:{
    'tag': 'create by bicep'   
  }
}

The values marked in red in the current code are custom values.

Click the arrow in the figure to view the resource dependencies in a visual manner.

image.png

Pre-submission inspection Bicep

Before deploying the Bicep file, you can predict upcoming resource changes. At this point, we need to add what-if to the CLI command so that we can view the changes of different types of resources.

az deployment sub  what-if --location "eastasia" --template-file "main.bicep"
Image

image.png

Subordinate Bicep

Bicep can define the deployment of resources to the set targets including "resource group", "subscription", "management group", and "tenant".

The demonstration in this article is to deploy "Web_Test_Rg" to "Subscription".

az deployment sub create --confirm-with-what-if --location "eastasia" --template-file "main.bicep"

image.png
Check the deployment status of the resource group, and the Azure resource group is successfully deployed.

image.png

Summarize

In this experiment, we learned how to use the Azure Bicep pre-deployment detection resource group, and also added a new solution to our choice of infrastructure as a code solution.

For the various technologies and services involved in the above experiments, you can learn more about them through the following links.

Azure Bicep Technical Document:

https://docs.microsoft.com/zh-cn/azure/azure-resource-manager/bicep/overview

*Bicep document:

https://github.com/Azure/bicep


Microsoft MVP project introduction

Microsoft's Most Valuable Expert is a global award granted by Microsoft to third-party technology professionals. For 28 years, technology community leaders around the world have won this award for sharing their expertise and experience in online and offline technology communities.

MVP is a rigorously selected team of experts. They represent the most skilled and intelligent people. They are experts who are passionate and helpful to the community. MVP is committed to helping others through speeches, forum questions and answers, creating websites, writing blogs, sharing videos, open source projects, organizing conferences, etc., and to help users in the Microsoft technology community use Microsoft technology to the greatest extent.
For more details, please visit the official website:
https://mvp.microsoft.com/zh-cn


Scan the QR code to follow Microsoft MSDN to get more first-hand technical information and official learning materials from Microsoft!
image.png


微软技术栈
423 声望996 粉丝

微软技术生态官方平台。予力众生,成就不凡!微软致力于用技术改变世界,助力企业实现数字化转型。