Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

Hoofdstuk 6Naam in de cursus: Automate deployment of resources by using ARM templates or Bicep files

Deploy resources from ARM templates and Bicep

Clicking in the portal does not scale. Azure's own Infrastructure as Code is ARM templates (JSON) and Bicep (a short language that compiles to ARM). The exam asks you to read, change, deploy and export them. Terraform, the multi-cloud tool, follows in the Terraform summary.

  • 5 Lessen
  • 2 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

Vaardigheden in dit hoofdstuk

  • Uitrol automatiseren met ARM-templates en Bicep

6.1

Read an ARM template

An ARM template is JSON with fixed sections. Azure reads it and creates the resources in the right order.

storage.json
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "name": { "type": "string" },
    "sku":  { "type": "string", "defaultValue": "Standard_LRS", "allowedValues": ["Standard_LRS", "Standard_ZRS"] }
  },
  "resources": [{
    "type": "Microsoft.Storage/storageAccounts",
    "apiVersion": "2023-05-01",
    "name": "[parameters('name')]",
    "location": "[resourceGroup().location]",
    "sku": { "name": "[parameters('sku')]" },
    "kind": "StorageV2",
    "properties": { "minimumTlsVersion": "TLS1_2", "allowBlobPublicAccess": false }
  }],
  "outputs": { "id": { "type": "string", "value": "[resourceId('Microsoft.Storage/storageAccounts', parameters('name'))]" } }
}
SectionMeaning
parametersValues you give at deploy time
variablesValues computed inside the template
resourcesWhat to create
outputsValues returned after the deployment
[ … ]An expression: parameters(), resourceGroup(), concat(), resourceId()

Commando's in deze les

6.2

Write the same in Bicep

Bicep is shorter, has types and autocomplete (VS Code extension), and compiles to the same ARM JSON.

storage.bicep
param name string
@allowed(['Standard_LRS', 'Standard_ZRS'])
param sku string = 'Standard_LRS'
 
resource st 'Microsoft.Storage/storageAccounts@2023-05-01' = {
  name: name
  location: resourceGroup().location
  sku: { name: sku }
  kind: 'StorageV2'
  properties: { minimumTlsVersion: 'TLS1_2', allowBlobPublicAccess: false }
}
 
output id string = st.id
az bicep install
az bicep build --file storage.bicep
az bicep decompile --file storage.json

Commando's in deze les

6.3

Deploy a template

Deploy to a resource group (most common), a subscription, a management group or the tenant. Check first with what-if.

az deployment group what-if -g rg-data --template-file storage.bicep --parameters name=stshop2026
az deployment group create -g rg-data --template-file storage.bicep --parameters name=stshop2026 sku=Standard_ZRS
az deployment group create -g rg-data --template-file storage.json --parameters @storage.parameters.json
az deployment group list -g rg-data -o table
az deployment group show -g rg-data -n storage --query properties.outputs
ModeBehaviour
Incremental (default)Adds and changes resources; others in the group stay
CompleteDeletes resources in the group that are not in the template

Let op

--mode Complete on the wrong resource group deletes everything else in it. Use what-if first.

Commando's in deze les

6.4

Export a template from existing resources

Build once in the portal, then export the template and keep it in Git.

az group export --name rg-data > rg-data.json
  • In the portal: resource group → Export template, or Download a template for automation on any create page.
  • Exported templates often need clean-up (hard-coded names, unneeded properties).

Commando's in deze les

6.5

Use parameter files

Keep one template and one parameter file per environment.

storage.parameters.json
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": { "name": { "value": "stshopprod" }, "sku": { "value": "Standard_ZRS" } }
}

Bicep can also use .bicepparam files: using 'storage.bicep' then param name = 'stshopprod'.

Alle commando's in dit hoofdstuk