Files
azure_tutorial/01_Beginner_JSON_templates/03_Add_parameters
Tuan-Dat Tran b88d2a6806 initial commit
Signed-off-by: Tuan-Dat Tran <tuan-dat.tran@tudattr.dev>
2025-01-24 23:48:14 +01:00
..
2025-01-24 23:48:14 +01:00

Add Parameters

https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/template-tutorial-add-parameters?tabs=azure-cli

Re-Create Resource Group

az group create --name tudattr_playground --location 'Germany West Central'

Result:

{
  "id": "/subscriptions/1b7ef43e-9f52-41ad-a21f-52b38fc9c292/resourceGroups/tudattr_playground",
  "location": "germanywestcentral",
  "managedBy": null,
  "name": "tudattr_playground",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": null,
  "type": "Microsoft.Resources/resourceGroups"
}

Run deployment

az deployment group create --name addnameparameter --resource-group tudattr_playground --template-file ./01_parameterized_create_storage_account.json --parameters storageName=tudattrstorageaccount

Result:

{
  "id": "/subscriptions/1b7ef43e-9f52-41ad-a21f-52b38fc9c292/resourceGroups/tudattr_playground/providers/Microsoft.Resources/deployments/addnameparameter",
  "location": null,
  "name": "addnameparameter",
  "properties": {
    "correlationId": "46ac3cb0-227e-4770-bb0c-875d48c484fb",
    "debugSetting": null,
    "dependencies": [],
    "duration": "PT22.7084386S",
    "error": null,
    "mode": "Incremental",
    "onErrorDeployment": null,
    "outputResources": [
      {
        "id": "/subscriptions/1b7ef43e-9f52-41ad-a21f-52b38fc9c292/resourceGroups/tudattr_playground/providers/Microsoft.Storage/storageAccounts/tudattrstorageaccount",
        "resourceGroup": "tudattr_playground"
      }
    ],
    "outputs": null,
    "parameters": {
      "storageName": {
        "type": "String",
        "value": "tudattrstorageaccount"
      }
    },
    "parametersLink": null,
    "providers": [
      {
        "id": null,
        "namespace": "Microsoft.Storage",
        "providerAuthorizationConsentState": null,
        "registrationPolicy": null,
        "registrationState": null,
        "resourceTypes": [
          {
            "aliases": null,
            "apiProfiles": null,
            "apiVersions": null,
            "capabilities": null,
            "defaultApiVersion": null,
            "locationMappings": null,
            "locations": ["germanywestcentral"],
            "properties": null,
            "resourceType": "storageAccounts",
            "zoneMappings": null
          }
        ]
      }
    ],
    "provisioningState": "Succeeded",
    "templateHash": "8372196208235658100",
    "templateLink": null,
    "timestamp": "2025-01-24T22:40:40.588825+00:00",
    "validatedResources": null
  },
  "resourceGroup": "tudattr_playground",
  "tags": null,
  "type": "Microsoft.Resources/deployments"
}

Prove of fail

az deployment group create --name testskuparameter --resource-group tudattr_playground --template-file ./02_limited_parameterized_create_storage_account.json --parameters storageSKU=basic storageName=tudattrstorageaccount

Result:

{
  "code": "InvalidTemplate",
  "message": "Deployment template validation failed: 'The provided value for the template parameter 'storageSKU' is not valid. The value 'basic' is not part of the allowed value(s): 'Standard_LRS,Standard_GRS,Standard_RAGRS,Standard_ZRS,Premium_LRS,Premium_ZRS,Standard_GZRS,Standard_RAGZRS'.'.",
  "additionalInfo": [
    {
      "type": "TemplateViolation",
      "info": {
        "lineNumber": 13,
        "linePosition": 24,
        "path": "properties.template.parameters.storageSKU.allowedValues"
      }
    }
  ]
}