title | description | services | documentationcenter | author | manager | editor | ms.service | ms.workload | ms.tgt_pltfrm | ms.devlang | ms.date | ms.topic | ms.author |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Use Visual Studio Code to create Azure Resource Manager template | Microsoft Docs |
Use Visual Studio Code and the Azure Resource Manager tools extension to work on Resource Manager templates. |
azure-resource-manager |
mumian |
dougeby |
tysonn |
azure-resource-manager |
multiple |
na |
na |
03/04/2019 |
quickstart |
jgao |
Learn how to use Visual Studio code and the Azure Resource Manager Tools extension to create and edit Azure Resource Manager templates. You can create Resource Manager templates in Visual Studio Code without the extension, but the extension provides autocomplete options that simplify template development. To understand the concepts associated with deploying and managing your Azure solutions, see Azure Resource Manager overview.
In this tutorial, you deploy a storage account:
If you don't have an Azure subscription, create a free account before you begin.
To complete this article, you need:
-
Resource Manager Tools extension. To install, use these steps:
- Open Visual Studio Code.
- Press CTRL+SHIFT+X to open the Extensions pane
- Search for Azure Resource Manager Tools, and then select Install.
- Select Reload to finish the extension installation.
Instead of creating a template from scratch, you open a template from Azure Quickstart Templates. Azure QuickStart Templates is a repository for Resource Manager templates.
The template used in this quickstart is called Create a standard storage account. The template defines an Azure Storage account resource.
-
From Visual Studio Code, select File>Open File.
-
In File name, paste the following URL:
https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-storage-account-create/azuredeploy.json
-
Select Open to open the file.
-
Select File>Save As to save the file as azuredeploy.json to your local computer.
To experience how to edit a template using Visual Studio Code, you add one more element into the outputs
section to show the storage URI.
-
Add one more output to the exported template:
"storageUri": { "type": "string", "value": "[reference(variables('storageAccountName')).primaryEndpoints.blob]" }
When you are done, the outputs section looks like:
"outputs": { "storageAccountName": { "type": "string", "value": "[variables('storageAccountName')]" }, "storageUri": { "type": "string", "value": "[reference(variables('storageAccountName')).primaryEndpoints.blob]" } }
If you copied and pasted the code inside Visual Studio Code, try to retype the value element to experience the IntelliSense capability of the Resource Manager Tools extension.
-
Select File>Save to save the file.
There are many methods for deploying templates. Azure Cloud shell is used in this quickstart. The cloud shell supports both Azure CLI and Azure PowerShell. Use the tab selector to choose between CLI and PowerShell.
[!INCLUDE updated-for-az]
-
Sign in to the Azure Cloud shell
-
Choose your preferred environment by selecting either PowerShell or Bash(CLI) on the upper left corner. Restarting the shell is required when you switch.
-
Select Upload/download files, and then select Upload.
Select the file you saved in the previous section. The default name is azuredeploy.json. The template file must be accessible from the shell.
You can optionally use the ls command and the cat command to verify the file is uploaded successfully.
-
From the Cloud shell, run the following commands. Select the tab to show the PowerShell code or the CLI code.
echo "Enter the Resource Group name:" && read resourceGroupName && echo "Enter the location (i.e. centralus):" && read location && az group create --name $resourceGroupName --location "$location" && az group deployment create --resource-group $resourceGroupName --template-file "$HOME/azuredeploy.json"
$resourceGroupName = Read-Host -Prompt "Enter the Resource Group name" $location = Read-Host -Prompt "Enter the location (i.e. centralus)" New-AzResourceGroup -Name $resourceGroupName -Location "$location" New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateFile "$HOME/azuredeploy.json"
Update the template file name if you save the file to a name other than azuredeploy.json.
The following screenshot shows a sample deployment:
The storage account name and the storage URL in the outputs section are highlighted on the screenshot. You need the storage account name in the next step.
-
Run the following CLI or PowerShell command to list the newly created storage account:
echo "Enter the Resource Group name:" && read resourceGroupName && echo "Enter the Storage Account name:" && read storageAccountName && az storage account show --resource-group $resourceGroupName --name $storageAccountName
$resourceGroupName = Read-Host -Prompt "Enter the Resource Group name" $storageAccountName = Read-Host -Prompt "Enter the Storage Account name" Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName
To learn more about using Azure storage accounts, see Quickstart: Upload, download, and list blobs using the Azure portal.
When the Azure resources are no longer needed, clean up the resources you deployed by deleting the resource group.
- From the Azure portal, select Resource group from the left menu.
- Enter the resource group name in the Filter by name field.
- Select the resource group name. You shall see a total of six resources in the resource group.
- Select Delete resource group from the top menu.
The main focus of this quickstart is to use Visual Studio Code to edit an existing template from Azure Quickstart templates. You also learned how to deploy the template using either CLI or PowerShell from the Azure Cloud shell. The templates from Azure Quickstart templates might not give you everything you need. The next tutorial shows you how to find the information from template reference so you can create an encrypted Azure Storage account.
[!div class="nextstepaction"] Create an encrypted storage account