title | description | services | documentationcenter | author | manager | editor | ms.service | ms.workload | ms.tgt_pltfrm | ms.devlang | ms.date | ms.topic | ms.author |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Azure Resource Manager template with VS Code extension | Microsoft Docs |
Use the Azure Resource Manager tools extension to work on Resource Manager templates. |
azure-resource-manager |
tfitzmac |
timlt |
tysonn |
azure-resource-manager |
multiple |
na |
na |
09/06/2017 |
get-started-article |
tomfitz |
This article shows you the benefits of installing and using the Azure Resource Manager Tools extension in Visual Studio Code. You can create Resource Manager templates in VS Code without the extension, but the extension provides autocomplete options that simplify template development. It suggests template functions, parameters, and variables that are available in the template.
To complete this article, you need Visual Studio Code.
To understand the concepts associated with deploying and managing your Azure solutions, see Azure Resource Manager overview.
This article builds on the template you created in Create and deploy your first Azure Resource Manager template. If you already have that template, you can skip this section.
-
If you need to create the template, start VS Code. Select File > New File.
-
Copy and paste the following JSON syntax into your file:
{ "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "storageSKU": { "type": "string", "allowedValues": [ "Standard_LRS", "Standard_ZRS", "Standard_GRS", "Standard_RAGRS", "Premium_LRS" ], "defaultValue": "Standard_LRS", "metadata": { "description": "The type of replication to use for the storage account." } }, "storageNamePrefix": { "type": "string", "maxLength": 11, "defaultValue": "storage", "metadata": { "description": "The value to use for starting the storage account name. Use only lowercase letters and numbers." } } }, "variables": { "storageName": "[concat(toLower(parameters('storageNamePrefix')), uniqueString(resourceGroup().id))]" }, "resources": [ { "name": "[variables('storageName')]", "type": "Microsoft.Storage/storageAccounts", "apiVersion": "2016-01-01", "sku": { "name": "[parameters('storageSKU')]" }, "kind": "Storage", "location": "[resourceGroup().location]", "tags": {}, "properties": { "encryption":{ "services":{ "blob":{ "enabled":true } }, "keySource":"Microsoft.Storage" } } } ], "outputs": { } }
-
Save this file as azuredeploy.json to a local folder.
-
In VS Code, select Extensions.
-
Search for Azure Resource Manager Tools and select Install.
-
To finish the extension installation, select Reload.
-
Open your azuredeploy.json file.
-
The extension retrieves all available template functions. It also reads the parameters and variables that you defined in the template. To see this functionality, you add two values to the output section. In the template, replace the outputs section with:
"outputs": { "groupLocation": { "type": "string", "value": "" }, "storageUri": { "type": "string", "value": "" } }
-
Place the cursor inside the quotation marks for value in groupLocation. Type the left bracket (
[
). Notice that the extension immediately suggests available template functions. -
Start typing resourceGroup. When the
resourceGroup()
function is displayed, press Tab or Enter. -
The extension fills in the function syntax. The resourceGroup function does not accept parameters. Add a period after the right parenthesis. The extension provides the properties that are available for the object returned by the
resourceGroup()
function. Selectlocation
. -
After location, add the closing right bracket.
"outputs": { "groupLocation": { "type": "string", "value": "[resourceGroup().location]" }, "storageUri": { "type": "string", "value": "" } }
-
Now, place the cursor inside the quotation marks for storageUri. Again, type the left bracket. Start typing reference. When that function is selected, press Tab or Enter.
-
The reference accepts the resource ID or resource name as a parameter. You already have the name of the storage account in a variable. Type var and then select Ctrl+space. The extension suggests the variables function.
Press Tab or Enter.
-
The variables function requires the name of the variable. Inside the parentheses, add a single quotation mark. The extension provides the names of variables you defined in the template.
-
Select the storageName variable. Add the right bracket. The following example shows the outputs section:
"outputs": {
"groupLocation": {
"type": "string",
"value": "[resourceGroup().location]"
},
"storageUri": {
"type": "object",
"value": "[reference(concat('Microsoft.Storage/storageAccounts/',variables('storageName')))]"
}
}
The final template is:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageSKU": {
"type": "string",
"allowedValues": [
"Standard_LRS",
"Standard_ZRS",
"Standard_GRS",
"Standard_RAGRS",
"Premium_LRS"
],
"defaultValue": "Standard_LRS",
"metadata": {
"description": "The type of replication to use for the storage account."
}
},
"storageNamePrefix": {
"type": "string",
"maxLength": 11,
"defaultValue": "storage",
"metadata": {
"description": "The value to use for starting the storage account name. Use only lowercase letters and numbers."
}
}
},
"variables": {
"storageName": "[concat(toLower(parameters('storageNamePrefix')), uniqueString(resourceGroup().id))]"
},
"resources": [
{
"name": "[variables('storageName')]",
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2016-01-01",
"sku": {
"name": "[parameters('storageSKU')]"
},
"kind": "Storage",
"location": "[resourceGroup().location]",
"tags": {},
"properties": {
"encryption":{
"services":{
"blob":{
"enabled":true
}
},
"keySource":"Microsoft.Storage"
}
}
}
],
"outputs": {
"groupLocation": {
"type": "string",
"value": "[resourceGroup().location]"
},
"storageUri": {
"type": "object",
"value": "[reference(concat('Microsoft.Storage/storageAccounts/',variables('storageName')))]"
}
}
}
You are ready to deploy this template. You use either PowerShell or Azure CLI to create a resource group. Then, you deploy a storage account to that resource group.
-
For PowerShell, use the following commands from the folder containing the template:
Login-AzureRmAccount New-AzureRmResourceGroup -Name examplegroup -Location "South Central US" New-AzureRmResourceGroupDeployment -ResourceGroupName examplegroup -TemplateFile azuredeploy.json
-
For a local installation of Azure CLI, use the following commands from the folder containing the template:
az login az group create --name examplegroup --location "South Central US" az group deployment create --resource-group examplegroup --template-file azuredeploy.json
When deployment finishes, the output values are returned.
When no longer needed, clean up the resources you deployed by deleting the resource group.
For PowerShell, use:
Remove-AzureRmResourceGroup -Name examplegroup
For Azure CLI, use:
az group delete --name examplegroup
- To learn more about the structure of a template, see Authoring Azure Resource Manager templates.
- To learn about the properties for a storage account, see storage accounts template reference.
- To view complete templates for many different types of solutions, see the Azure Quickstart Templates.