Adventures in Declarative – with Bicep
In Azure - codifying Infrastructure has remained either an artform of adaptation (via exporting directly from Azure or baking from the Azure Quickstart templates), or it was the domain of the esoteric. Now that Bicep has rolled on to the scene (really in the last year+) much of the complexity has been removed and has turned some Infrastructure folks into the cool programming kids (ok maybe not cool but they are no longer the Debby-downers that bring just the harsh realities of security, network, and Kubernetes complexity). This article will be the starting point for using and abusing Bicep to its fullest. Keep in mind this is not designed to be a series on Bicep development but a point of reference for more content.
1. What is Bicep?
Bicep is a domain-specific language that uses a declarative syntax to deploy Azure resources - (source: Bicep language for deploying Azure resources) - Explanation: Bicep is the strategic declarative syntax for deploying resources into Azure. It serves as a clear, poignant, and declarative interpreter that easily translates into and out of the Azure JSON syntax while remaining to be both future-proof and feature-aligned. Long-winded definition yes, but the examples will be worth the wait.
2. Why learn it?
Without a doubt, it is easy to get into the imperative vs declarative discussion. What do I mean - well learning BASH, Python, or Powershell as part of normal system operation makes it tempting to deploy infrastructure in an already familiar way (see Functional programming vs. imperative programming ) but Bicep is: easy to learn, extensible (via modules), and far more efficient (by means of coordinating resources and maintaining state (which is handled by the MS backplane versus state files)
3. Features
Simplified syntax - this a key attribute of Bicep. An example will be shared below. But this mitigates a lot of the complexity and poor readability found in ARM JSON templates
Future proof - as part of the resource building the API version is part of the declarative syntax - familiar to any JSON user but it is important to note that this capability is not going away.
Feature aligned - because it translates to (and from) native ARM templates - when a new resource, or resource feature is released it is also available through Bicep.
Intelli-genius - not actually a thing, but the Bicep team has really invested heavily to simplify the syntax adoption. The intellisense capability is fantastic, specifically in Visual Studio Code (https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-bicep), though my guess is that other IDEs have leveraged this capability
Modularity - repeatable snippets of IaaC capability, much needed functionality for enterprise scale implementation. (They are also working on the Bicep implementation of Enterprise Scale Landing Zones - https://github.com/Azure/ALZ-Bicep)
4. Examples - with a side of tips and tricks
I wanted to take the opportunity to demonstrate where Bicep really shines, and how it can easily integrate into any enterprise's Azure adoption. Some of these are features from Visual Studio Code with the Bicep extension, but most of these capabilities can be extended into any IDE.
a. Comparing Size and Readability
Beyond the additional variable declarations, this is a pretty stock implementation. Now compare the 43-line Bicep file against the 70-line ARM template. Aside from just the length, the ARM template adds complexity to the readability, at least from the human perspective (JSON is rendered behind the scenes of Bicep).
b. Code Shortcuts
c. Quick References
Visual Studio code with the Bicep extension brings a tremendous amount of functionality. In these two examples the IDE will auto populate (Intellisense) resource names and schema information, which if your like me get frustrated having to copy and paste out of the documentation.
What happens when you don't know the properties names for resource - the Bicep extension provides a quick link to the Microsoft documentation (by selecting the instance name and right clicking, "View Type Documentation" in your code).
Bicep is a vast improvement to building Infrastructure as Code for Azure over ARM templates. It has borrowed some features of Terraform (as in minimal code, and modularity) and added some (by maintaining state information directly in the Azure Backplane for consistency). For native Azure adoption take a look at Bicep and provide feedback directly to the developers.
5. More information
Bicep is a vast improvement to building Infrastructure as Code for Azure over ARM templates. It has borrowed some features of Terraform (as in minimal code, and modularity) and added some (by maintaining state information directly in the Azure Backplane for consistency). For native Azure adoption take a look at Bicep and provide feedback directly to the developers.
More information
- Bicep language for deploying Azure resources (windows.net)
- Fundamentals of Bicep - Learn | Microsoft Docs
- Intermediate Bicep - Learn | Microsoft Docs
- Advanced Bicep - Learn | Microsoft Docs
- Azure resource reference - Bicep & ARM template reference
- Azure/ALZ-Bicep
and thank you for reading and sharing.
Categories
Welcome
Fictal has been created for Musings, Open-Sourcery, Fiction and all permutations in between. The goal is to build upon inclusivity with technology and tomfoolery.
Recent Comments
Categories
#azureimagebuilder #certification #codifying #mushrooms #mycology Azure Azure Bicep Azure Policy bash Bicep codifying Infrastructure DNS IAC Integration JSON Kasm Linux Policy Private Link VDI
Comments
Leave a Comment