Skip to content

Instantly share code, notes, and snippets.

@seesharprun
Last active March 23, 2022 16:26
Show Gist options
  • Save seesharprun/3c690773a76de869b8c444268fa880f0 to your computer and use it in GitHub Desktop.
Save seesharprun/3c690773a76de869b8c444268fa880f0 to your computer and use it in GitHub Desktop.
Azure Resource Manager demos (CLI, JSON, and Bicep)

Demos

https://docs.microsoft.com/azure/templates/

Getting started

az login

az group create \
    --name <resource-group-name> \
    --location <location>

Azure CLI (standard storage)

https://docs.microsoft.com/cli/azure/storage/account#az-storage-account-create

az storage account create \
    --name <unique-name> \
    --resource-group <resource-group-name> \
    --location <location> \
    --sku Standard_LRS

Azure CLI (resource creation)

https://docs.microsoft.com/azure/templates/microsoft.storage/storageaccounts

{
    "location": "<location>",
    "kind": "StorageV2",
    "sku": {
        "name": "Standard_LRS"
    }
}

https://docs.microsoft.com/cli/azure/resource#az-resource-create

az resource create \
    --name <unique-name> \
    --resource-group <resource-group-name> \
    --resource-type 'Microsoft.Storage/storageAccounts' \
    --api-version '2021-08-01' \
    --is-full-object \
    --properties '@<filename>.json'

JSON ARM template

https://docs.microsoft.com/azure/azure-resource-manager/templates/syntax

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": []
}

https://resources.azure.com

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
    {
        "name": "<unique-name>",
        "type": "Microsoft.Storage/storageAccounts",
        "apiVersion": "2021-08-01",
        "location": "<location>",
        "kind": "StorageV2",
        "sku": {
            "name": "Standard_LRS"
        }
    }
  ]
}
az deployment group create
    --resource-group <resource-group-name> \
    --template-file <filename>.armdeploy.json
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
      "storageAccountName": {
          "type": "string"
      }
  },
  "variables": {
      "defaultLocation": "[resourceGroup().location]"
  },
  "resources": [
    {
        "name": "[parameters('storageAccountName')]",
        "type": "Microsoft.Storage/storageAccounts",
        "apiVersion": "2021-08-01",
        "location": "[variables('defaultLocation')]",
        "kind": "StorageV2",
        "sku": {
            "name": "Standard_LRS"
        }
    }
  ]
}
az deployment group create
    --resource-group <resource-group-name> \
    --template-file <filename>.armdeploy.json \
    --name <deployment-name> \
    --parameters storageAccountName=<unique-name>
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "storageAccountName": {
            "value": "<unique-name>"
        }
    }
}
az deployment group create \
    --resource-group <resource-group-name> \
    --template-file <filename>.armdeploy.json \
    --name <deployment-name> \
    --parameters '@<filename>.parameters.armdeploy.json'

Bicep ARM template

https://docs.microsoft.com/azure/azure-resource-manager/bicep/file https://docs.microsoft.com/azure/azure-resource-manager/bicep/resource-declaration

resource storageAccount 'Microsoft.Storage/storageAccounts@2021-08-01' = {
  name: '<unique-name>'
  location: '<location>'
  kind: 'StorageV2'
  sku: {
    name: 'Standard_LRS'
  }
}
az deployment group create \
    --resource-group <resource-group-name> \
    --template-file <filename>.bicep

https://docs.microsoft.com/azure/azure-resource-manager/bicep/parameters

param defaultLocation string = resourceGroup().location

resource storageAccount 'Microsoft.Storage/storageAccounts@2021-08-01' = {
  name: '<unique-name>'
  location: defaultLocation
  kind: 'StorageV2'
  sku: {
    name:'Standard_LRS'
  }
}
az deployment group create \
    --resource-group <resource-group-name> \
    --template-file <filename>.bicep \
    --name <deployment-name>

https://docs.microsoft.com/azure/azure-resource-manager/bicep/variables

@minLength(3)
@maxLength(24)
param storageAccountName string
param defaultLocation string = resourceGroup().location
var sku = 'Standard_LRS'
var kind = 'StorageV2'

resource storageAccount 'Microsoft.Storage/storageAccounts@2021-08-01' = {
  name: storageAccountName
  location: defaultLocation
  kind: kind
  sku: {
    name: sku
  }
}
az deployment group create \
    --resource-group <resource-group-name> \
    --template-file <filename>.bicep \
    --name <deployment-name> \
    --parameters storageAccountName=<unique-name>
az deployment group create \
    --resource-group <resource-group-name> \
    --template-file <filename>.bicep \
    --name <deployment-name> \
    --parameters '@<filename>.parameters.armdeploy.json'
@minLength(3)
@maxLength(24)
param storageAccountName string = 'stor${uniqueString(resourceGroup().id)}'
param defaultLocation string = resourceGroup().location
var sku = 'Standard_LRS'
var kind = 'StorageV2'

resource storageAccount 'Microsoft.Storage/storageAccounts@2021-08-01' = {
  name: storageAccountName
  location: defaultLocation
  kind: kind
  sku: {
    name: sku
  }
}
az deployment group create \
    --resource-group <resource-group-name> \
    --template-file <filename>.bicep \
    --name <deployment-name>

https://docs.microsoft.com/azure/azure-resource-manager/bicep/outputs

az storage account show \
    --name <unique-name> \
    --resource-group <resource-group-name>
@minLength(3)
@maxLength(24)
param storageAccountName string = 'stor${uniqueString(resourceGroup().id)}'
param defaultLocation string = resourceGroup().location
var sku = 'Standard_LRS'
var kind = 'StorageV2'

resource storageAccount 'Microsoft.Storage/storageAccounts@2021-08-01' = {
  name: storageAccountName
  location: defaultLocation
  kind: kind
  sku: {
    name: sku
  }
}

output storageBlobUri string = storageAccount.properties.primaryEndpoints.blob
az deployment group create \
    --resource-group <resource-group-name> \
    --template-file <filename>.bicep \
    --name <deployment-name> \
    --parameters storageAccountName=<unique-name> \
    --parameters defaultLocation=<location>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment