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 |
11/13/2018 |
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.
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 learn how to edit a template using Visual Studio Code, you add one more element into the outputs
section.
-
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. In this quickstart, you use the Azure Cloud shell. Cloud Shell supports both Azure CLI and Azure PowerShell.
-
Sign in to the Azure Cloud shell
-
On the upper left corner of the Cloud shell, it shows either PowerShell or Bash. To use CLI, you need to open a Bash session. To run PowerShell, you need to open a PowerShell session. Select the down arrow to toggle between the Bash and PowerShell. See the previous screenshot. Restarting the shell is required when you switch.
-
Select Upload/download files, and then select Upload.
You must upload the template file before you can deploy it from the shell.
-
Select the file you saved in the previous section. The default name is azuredeploy.json.
-
From the Cloud shell, run the ls command to verify the file is uploaded successfully. You can also use the cat command to verify the template content. The following image shows running the command from Bash. You use the same commands from a PowerShell session.
-
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 name for this deployment:" && read deploymentName && echo "Enter the location (i.e. centralus):" && read location && az group create --name $resourceGroupName --location $location && az group deployment create --name $deploymentName --resource-group $resourceGroupName --template-file "azuredeploy.json"
$resourceGroupName = Read-Host -Prompt "Enter the Resource Group name" $deploymentName = Read-Host -Prompt "Enter the name for this deployment" $location = Read-Host -Prompt "Enter the location (i.e. centralus)" New-AzureRmResourceGroup -Name $resourceGroupName -Location $location New-AzureRmResourceGroupDeployment -Name $deploymentName -ResourceGroupName $resourceGroupName -TemplateFile "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-AzureRmStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName
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 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