Create Parameters:
In order to change your template asĀ reusable, we can use parameter to place it in storage account name. it will save us time every time to change name directly to parameter value instead of finding resource and change its name
Below is a parameter example for our storage resource. We created parameter for storage with name, type, minlengt, maxlength. Then we will pass the storage parameter name to resource name. see below example.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageName": {
"type": "string",
"minLength": 3,
"maxLength": 24
}
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2019-04-01",
"name": "[parameters('storageName')]",
"location": "eastus",
"sku": {
"name": "Standard_LRS"
},
"kind": "StorageV2",
"properties": {
"supportsHttpsTrafficOnly": true
}
}
]
}
Deploy template
Let’s deploy the template.
New-AzResourceGroupDeployment `
-Name addnameparameter `
-ResourceGroupName myResourceGroup `
-TemplateFile $templateFile `
-storageName "{your-unique-name}"
The last example we deployed Standard_LRS azure storage account, now we can have option to deploy different storage SKUs based on our needs.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageName": {
"type": "string",
"minLength": 3,
"maxLength": 24
},
"storageSKU": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Standard_GRS",
"Standard_RAGRS",
"Standard_ZRS",
"Premium_LRS",
"Premium_ZRS",
"Standard_GZRS",
"Standard_RAGZRS"
]
}
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2019-04-01",
"name": "[parameters('storageName')]",
"location": "eastus",
"sku": {
"name": "[parameters('storageSKU')]"
},
"kind": "StorageV2",
"properties": {
"supportsHttpsTrafficOnly": true
}
}
]
}
As you see we use Parameter in Storage SKUs. That’s the beauty of parameters. we can use parameter for every resources properties value.
Redeploy template
Lets try to redeploy template this time with Storage SKUs.
New-AzResourceGroupDeployment `
-Name usedefaultsku `
-ResourceGroupName myResourceGroup `
-TemplateFile $templateFile `
-storageName "{your-unique-name}" `
-storageSKU Standard_GRS