Thursday, May 26, 2022

Azure Bicep + ARM vs Terraform vs Pulumi vs AWS CDK + CloudFormation

The "problem" of "Infrastructure as a Code" is that
most in most of current solutions the "code" is actually configuration, 
a simple while custom JSON and YAML.

That does not have expressiveness of a "proper" programming language:
they are not "Turing complete", even with extensions.

The new modern solutions like Pulumi are solving problem by embedding "infrastructure"
as libraries to existing programming languages, 
or like in case of Terraform by a new "DSL" : domain specific language.

AWS has opted to leverage existing programming languages, 
starting from TypeScript as a "base" for code generation,
and using CloudFormation (JSON/YML) as the target.

Azure has opted to create DSL "Bicep" pre-processor for generating JSON ARM,
using custom "purified" and extended syntax, i.e. by adding params, ifs, loops etc.
Bicep is open source, written in C#, the most common language of Microsoft Azure.

So both provide benefit of simplification of syntax, 
while in both cases essential knowledge of underlying platforms is still required.

And unfortunately in all mentioned cases, as well as with all modern programming languages
the transformations tooling is custom, and limited to one or few languages and planforms.

 Azure/bicep: Bicep is a declarative language for describing and deploying Azure resources

Azure Bicep March 2021: Learn everything about the next generation of ARM Templates - YouTube

Infrastructure as Code - An intro - Part 4 - Using Bicep

Infrastructure as code in 2021 - DEV Community

How Azure Bicep is Different. How emerging technologies solve classic… | by Yi Lu | Slalom Build | Medium

The Bicep DSL is an enhancement of JSON configuration language. It introduces some flow-control elements such as loops, ternary operators and one-line resource references, yet it stops short of classes or inheritance. The enhanced syntax greatly improves functionality and reduces code size, at the cost of mildly increased complexity. As an Azure-native technology, Bicep also has two advantages over approach one: day-zero support and no maintenance of state files.


Bicep (name is play on ARM)

param location string = resourceGroup().location param storageAccountName string = 'toylaunch${uniqueString(resourceGroup().id)}' resource storageAccount 'Microsoft.Storage/storageAccounts@2021-06-01' = { name: storageAccountName location: location sku: { name: 'Standard_LRS' } kind: 'StorageV2' properties: { accessTier: 'Hot' } }

Result: ARM JSON

{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "location": { "type": "string", "defaultValue": "[resourceGroup().location]" }, "storageAccountName": { "type": "string", "defaultValue": "[format('toylaunch{0}', uniqueString(resourceGroup().id))]" } }, "resources": [ { "type": "Microsoft.Storage/storageAccounts", "apiVersion": "2021-06-01", "name": "[parameters('storageAccountName')]", "location": "[parameters('location')]", "sku": { "name": "Standard_LRS" }, "kind": "StorageV2", "properties": { "accessTier": "Hot" } } ] }


param deployZone bool resource dnsZone 'Microsoft.Network/dnszones@2018-05-01' = if (deployZone) { name: 'myZone' location: 'global' }


param itemCount int = 5 var stringArray = [for i in range(0, itemCount): 'item${(i + 1)}'] output arrayResult array = stringArray






No comments: