Leveraging Bicep to deploy Azure resources - Part 2

In this post, we articulate the definition of infrastructure as code and elucidate the compelling reasons behind embracing this highly advantageous mindset.

What is infrastructure as code (IaC) ?

Infrastructure as code (IaC) is a methodology that involves managing and provisioning computing infrastructure through machine-readable script files, rather than through physical hardware configuration or interactive configuration tools. In essence, it treats infrastructure —such as servers, networks, and databases— as code, allowing it to be versioned, tested, and deployed with the same practices used for application code.

With infrastructure as code, configurations are expressed in a declarative or imperative scripting language, specifying the desired state of the infrastructure. This script, often referred to as a "template" or "manifest", can be used to automate the provisioning and configuration of infrastructure components.

Streamlining the automation

IaC allows for the automated provisioning and management of infrastructure, reducing manual intervention and the risk of human error.

Ensuring version control

Infrastructure configurations can be versioned using version control systems, enabling tracking changes over time, rollback to previous states, and collaboration among team members.

Ensuring reproductibility

Infrastructure can be consistently reproduced across different environments (development, testing, production) by using the same codebase, minimizing discrepancies and improving reliability.

Why now ?

The challenges mentioned earlier are not novel; they have persisted since the inception of computer science. However, the fundamental shift lies in the historical provisioning of servers on premises, where tools for automating deployments were either unavailable or challenging to implement. With the widespread adoption of cloud computing, cloud platforms have introduced methodologies and mechanisms to streamline these processes. Consequently, applying automation has become imperative, especially in the early stages of a project's lifecycle.

IaC has rapidly evolved from a pioneering concept to a foundational element of the software development process.

What are the common tools for implementing infrastructure as code ?

Presently, there are numerous providers for IaC, with Terraform and Ansible standing out as the most renowned. Notably, Microsoft has introduced Bicep, a tool specifically designed for the Azure platform, adding to the array of choices available for IaC implementation.

What is Terraform ?

Terraform is actively developed by HashiCorp and enables users to define and provision infrastructure in a declarative configuration language. With Terraform, we describe the components and resources needed for our infrastructure in a high-level configuration file, and then Terraform automates the process of provisioning and managing those resources.

  • Terraform uses a declarative language to define the desired state of infrastructure. Users specify what resources they need and their configurations, and Terraform handles the process of figuring out how to make the current infrastructure match the desired state.

    Information

    We will observe that Bicep also utilizes a declarative syntax for provisioning infrastructure, where we articulate the intended outcome without specifying the individual steps to achieve that result.

  • Terraform keeps track of the state of the infrastructure in a state file. This file records the relationships between resources and their current configurations, allowing Terraform to make informed decisions during subsequent runs.

    Information

    The state file, essential for Terraform to monitor changes, needs to be stored in a designated location. This can be accomplished through Azure Storage or Terraform Cloud. Notably, Azure simplifies this process for Bicep by autonomously managing the storage of the state file.

What is Ansible ?

Ansible is an open-source automation tool developed by Red Hat. It simplifies complex tasks and facilitates the management of IT infrastructure by allowing users to describe their infrastructure as code.

Ansible serves as a notable illustration of an imperative IaC tool, employing YAML-based playbooks to articulate a series of tasks.

Information

Imperative IaC is an approach where the user specifies the step-by-step sequence of actions that need to be taken to achieve the desired infrastructure state. In imperative IaC, the focus is on detailing the specific tasks and operations that should be executed, often resembling a procedural or script-like style.

While imperative IaC provides a high level of control over the deployment process and greater flexibility, it can sometimes be more complex to maintain and may require more manual intervention to handle changes or updates.

Our objective here is to introduce Bicep, showcase its practical application, and explore how it may present unique capabilities or advantages that could pose challenges to its competitors in the IaC landscape.

Leveraging Bicep to deploy Azure resources - Part 3