Opscraft
Azure for AWS engineers · Lesson 7 of 9 · 3 min read

Infrastructure as code and pipelines

ARM templates and Bicep

Enlarge diagramBicepclean DSLARM JSONcompiled outputAzure ResourceManagerdeploys itOr: Terraform azurerm provider → same Resource Manager API.
Figure 1. Infrastructure as code on Azure: Bicep is the native choice; Terraform works the same way it does on AWS.
Swipe sideways to see all of it, or tap to open it full screen.

ARM templates are JSON (≈ CloudFormation). Bicep is a cleaner DSL that compiles to ARM — Microsoft's recommended native IaC:

param location string = resourceGroup().location
resource sa 'Microsoft.Storage/storageAccounts@2023-05-01' = {
  name: 'stshopprodlogs'
  location: location
  sku: { name: 'Standard_ZRS' }
  kind: 'StorageV2'
  properties: {
    minimumTlsVersion: 'TLS1_2'
    allowBlobPublicAccess: false
  }
}
az deployment group create -g rg-shop-prod --template-file main.bicep
az deployment group what-if -g rg-shop-prod --template-file main.bicep   # ≈ change sets / plan

Terraform on Azure

Your Terraform skills transfer; only the provider and resources change:

terraform {
  required_providers { azurerm = { source = "hashicorp/azurerm", version = "~> 4.0" } }
  backend "azurerm" {
    resource_group_name  = "rg-tfstate"
    storage_account_name = "sttfstateacme"
    container_name       = "tfstate"
    key                  = "prod/aks.tfstate"
    use_azuread_auth     = true
  }
}
provider "azurerm" {
  features {}
  subscription_id = var.subscription_id
}
resource "azurerm_resource_group" "aks" {
  name     = "rg-shop-prod"
  location = "centralindia"
}
resource "azurerm_kubernetes_cluster" "shop" {
  name                = "aks-shop-prod"
  location            = azurerm_resource_group.aks.location
  resource_group_name = azurerm_resource_group.aks.name
  dns_prefix          = "shop-prod"
  sku_tier            = "Standard"
  oidc_issuer_enabled       = true
  workload_identity_enabled = true
  default_node_pool {
    name       = "system"
    vm_size    = "Standard_D4s_v5"
    node_count = 3
    zones      = ["1", "2", "3"]
  }
  identity { type = "SystemAssigned" }
  network_profile {
    network_plugin      = "azure"
    network_plugin_mode = "overlay"
  }
}
  • State in an Azure Storage blob container, locked with blob leases (≈ S3 + lockfile/DynamoDB).
  • Authenticate CI with OIDC/workload identity federation — no client secrets.
  • Secrets for Terraform from Key Vault via data sources or pipeline variable groups.
  • For multi-cloud repos: provider-specific modules, shared conventions (naming, tagging), and separate state per cloud and environment.

Azure DevOps Pipelines

# azure-pipelines.yml
trigger: { branches: { include: [main] } }
pool: { vmImage: ubuntu-latest }
variables:
- group: shop-prod-secrets          # variable group linked to Key Vault, values marked secret
stages:
- stage: Build
  jobs:
  - job: build
    steps:
    - task: Maven@4
      inputs: { mavenPomFile: pom.xml, goals: package }
    - task: Docker@2
      inputs:
        containerRegistry: acr-shop-prod          # service connection
        repository: orders
        command: buildAndPush
        tags: $(Build.SourceVersion)
- stage: Deploy
  dependsOn: Build
  jobs:
  - deployment: prod
    environment: shop-prod                         # approvals and checks configured on the environment
    strategy:
      runOnce:
        deploy:
          steps:
          - task: AzureCLI@2
            inputs:
              azureSubscription: sc-shop-prod      # service connection using workload identity federation
              scriptType: bash
              scriptLocation: inlineScript
              inlineScript: az aks get-credentials -g rg-shop-prod -n aks-shop-prod && kubectl get ns
  • Service connections authenticate to Azure — prefer workload identity federation over secrets.
  • Variable groups linked to Key Vault supply secrets, marked secret (masked in logs).
  • Environments with approvals and checks ≈ GitHub environment protection / Jenkins input.
  • GitHub Actions to Azure: azure/login with OIDC (federated credential on an app registration or managed identity).