adaptive.run TECH BLOG

Cloud can be tricky sometimes. Find out what scenarios we've ran into that are worth being mentioned and explained.

From Azure Bicep Template to a Deployed Azure Resource

Level: 200
Publishing date: 10-Jan-2025
Author: Catalin Popa

When deploying cloud infrastructure with Azure Bicep, understanding the stages a template goes through before becoming an Azure resource is crucial. The Azure Resource Manager (ARM) handles this process, ensuring that templates are properly compiled, validated, and executed.

This guide outlines the four key stages of deployment, explaining what happens at each step:

    1. Orchestration – Initiating the deployment
    2. Compilation – Converting Bicep to ARM JSON
    3. Execution – Deploying resources to Azure
    4. Output – Returning deployment results

By understanding these stages, you can optimize deployments, troubleshoot errors more effectively, and gain deeper insight into how Infrastructure-as-Code (IaC) works in Azure.

1. Orchestration – Initiating the Deployment

The deployment process begins when a Bicep template is created and executed. This can be done in several ways:

Locally for testing using Azure CLI or PowerShell

Automated CI/CD pipelines in Azure DevOps or GitHub Actions (recommended for production)
Azure Bicep deployments are orchestrated through commands such as:

      • Defines how infrastructure is provisioned
      • Allows local or pipeline-based deployment
      • Ensures templates follow a structured approach
      • Once the deployment is triggered, Azure Bicep moves to the compilation stage.


2. Compilation – Converting Bicep to ARM JSON

At this stage, Azure Bicep is automatically compiled into an ARM (Azure Resource Manager) template, which is written in JSON format.

Even though you don’t need to manually convert Bicep to JSON, you can inspect the compiled template using:
Key aspects of the compilation process:

Syntax validation – Ensures there are no errors in the Bicep template
Execution of compile-time functions – Functions like readEnvironmentVariable() are processed
External module retrieval – If your template references Azure Verified Modules (AVM), they are fetched and cached

Handling network restrictions

If you are using a private build agent (e.g., in a restricted Azure DevOps environment), ensure that external module sources like mcr.microsoft.com are allowlisted to prevent deployment failures.

Why is compilation important?

      • Ensures Bicep templates are correctly translated
      • Validates syntax before deployment begins
      • Handles module dependencies automatically
After successful compilation, the runtime stage begins.

3. Execution – Deploying Resources to Azure

Once the Bicep template has been converted into an ARM JSON template, Azure Resource Manager (ARM) takes over the deployment process. This involves:

     1. Validating the compiled template to ensure correctness
     2. Deploying resources based on defined dependencies
     3. Managing concurrency for efficient execution

How ARM Handles Dependencies

Azure Resource Manager ensures resources are deployed in the correct order using explicit or implicit dependencies.

Example: Implicit Dependency Management

In the following example, an Azure Key Vault is deployed first, followed by a storage account that references the Key Vault’s ID. Even though there is no explicit dependsOn statement, Azure Resource Manager (ARM) automatically detects the dependency based on the reference to resKeyVault.id.
      • The storage account references resKeyVault.properties.vaultUri, which means it relies on               the Key Vault being created first.
      • ARM automatically determines the correct deployment order, ensuring the Key Vault exists              before assigning its URI to the storage account.
      • No explicit dependsOn statement is needed, making the template cleaner and easier to                    maintain.

This approach is particularly useful in large-scale deployments where multiple resources have dependencies, allowing Azure to optimize the execution order while ensuring all dependencies are resolved correctly.

Parallel Deployment for Performance

If no dependencies are configured, ARM deploys resources in parallel to speed up execution.

Why is this stage important?

      • Ensures resource dependencies are respected
      • Optimizes deployment performance with parallel execution
      • Validates configurations before applying changes
      • Once all resources are deployed, ARM generates output data.

4. Output – Returning Deployment Results

The final stage of the deployment process involves returning outputs. These can be used for:

• Automation scripts – Using outputs in follow-up scripts
• Integration with other services – Passing values to dependent deployments
• Validation – Checking if the deployment was successful

Defining Outputs in a Bicep Template
Retrieving Outputs in Azure CLI

Enables seamless automation across deployments
Provides validation for successful deployments
• Helps in dynamic infrastructure scaling
• By leveraging deployment outputs, you can build flexible, interconnected cloud environments.

Conclusion

Deploying Azure Bicep templates involves a multi-step process that ensures resources are properly structured, validated, and executed.

Key Takeaways

✔ Understanding these stages helps optimize deployments
✔ Validating templates before deployment prevents failures
✔ ARM automatically manages dependencies and concurrency
✔ Outputs provide valuable information for automation

By mastering these concepts, you can streamline your Azure infrastructure deployments, minimize errors, and improve overall efficiency in your Infrastructure-as-Code (IaC) workflows.