Insight Tech APAC Blog Logo

Bicep: A New Language for Infrastructure as Code

stephentulp
December 1, 2023

5 minutes to read

Bicep Advent Calendar

Introduction

In the first blog post, lets first get an understanding of what Bicep is and what are some of the benefits it brings to Infrastructure as Code (IaC) deployments in Azure. Finally, we will look at how Bicep compares to Terraform.

What is Bicep?

Bicep is a DSL that uses declarative syntax to deploy Azure resources. In a Bicep file, you define the infrastructure you want to deploy to Azure, and then use that file throughout the development lifecycle to repeatedly deploy your infrastructure. Your resources are deployed in a consistent manner. Bicep provides concise syntax, reliable type safety, and support for code reuse. Bicep also offers a first-class authoring experience for your IaC solutions in Azure, with rich features such as intellisense, syntax validation, and refactoring.

Bicep is compatible with all resource types and API versions for Azure services. As soon as a resource provider introduces new resource types and API versions, you can use them in your Bicep file. You don’t have to wait for tools to be updated before using the new services. Bicep is also interoperable with existing ARM templates. You can de-compile any ARM template into a Bicep file, and vice versa, as well as use Bicep modules to reference and reuse existing ARM templates.

What benefits does Bicep bring to Infrastructure as Code?

Bicep brings several benefits to IaC, including:

  • Simple Syntax: When compared to the equivalent ARM template, Bicep files are more concise and easier to read. Bicep requires no previous knowledge of programming languages. The Bicep syntax is declarative and specifies which resources and resource properties you want to deploy.

The following examples show the difference between a Bicep file and the equivalent ARM template. Both examples below deploy a storage account amd achieve the same outcome.

Bicep Template

Bicep Template

ARM Template

ARM Template


As you can see, the Bicep file is much shorter and clearer than the ARM template. Bicep eliminates the need for brackets, quotes, commas, and other syntactic noise that can make ARM templates hard to read, maintain and understand.

  • Authoring Experience: When you use the Bicep Extension for VS Code or Visual Studio to create your Bicep files, you get a first-class authoring experience. The editor provides rich type-safety, intellisense, and syntax validation. You can also create Bicep files in Visual Studio with the Bicep extension for Visual Studio. These features help you write correct and consistent Bicep code, and avoid common errors and typos. You can also use the Bicep CLI to compile, de-compile, and validate your Bicep files from the command line.

  • Repeatable results: Repeatedly deploy your infrastructure throughout the development lifecycle and have confidence your resources are deployed in a consistent manner. Bicep files are idempotent, meaning that you can run the same Bicep file multiple times and get the same result. Bicep also supports what-if deployment, which allows you to preview the changes that will be made to your resources before deploying them.

  • Code reuse: Bicep supports modularization and parameterization, which enable you to reuse your Bicep code across different scenarios and environments. You can define Bicep modules to encapsulate a set of related resources, and then reference them from other Bicep files. You can also define parameters to customize your Bicep files for different inputs and values. Bicep modules can also reference existing ARM templates, so you can leverage your existing IaC investments.

Bicep vs Terraform

Like anything, this is a matter of personal preference, specific requirements and the cloud platforms that you are working with.

  • If you primarily work with Azure resources, Azure Bicep is a great choice.
  • If you need multi-cloud support or work with different cloud providers, then go Terraform.
  • My personal preference is Bicep, but that is because I like not having to worry about state.

Conclusion

Bicep is a language for IaC that simplifies the creation and deployment of Azure resources. Bicep offers a simple syntax, a rich authoring experience, repeatable results, and code reuse. Bicep is compatible with all Azure services and existing ARM templates. Bicep is easy to learn and use, and can help you accelerate your devOps journey in Azure.

Tomorrow, we will look at how to get started with Bicep, including the required tooling and some best practices that will help along the way.

Further Reading

Some further reading on the topics covered in this post: