Skip to content

Latest commit

 

History

History
216 lines (141 loc) · 9.47 KB

resource-manager-quickstart-create-templates-use-visual-studio-code.md

File metadata and controls

216 lines (141 loc) · 9.47 KB
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

Quickstart: Create Azure Resource Manager templates by using Visual Studio Code

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:

resource manager template quickstart visual studio code diagram

If you don't have an Azure subscription, create a free account before you begin.

Prerequisites

To complete this article, you need:

  • Visual Studio Code.

  • Resource Manager Tools extension. To install, use these steps:

    1. Open Visual Studio Code.
    2. Press CTRL+SHIFT+X to open the Extensions pane
    3. Search for Azure Resource Manager Tools, and then select Install.
    4. Select Reload to finish the extension installation.

Open a Quickstart template

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.

  1. From Visual Studio Code, select File>Open File.

  2. In File name, paste the following URL:

    https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-storage-account-create/azuredeploy.json
  3. Select Open to open the file.

  4. Select File>Save As to save the file as azuredeploy.json to your local computer.

Edit the template

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.

  1. 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.

    Resource Manager template visual studio code IntelliSense

  2. Select File>Save to save the file.

Deploy the template

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]

  1. Sign in to the Azure Cloud shell

  2. Choose your preferred environment by selecting either PowerShell or Bash(CLI) on the upper left corner. Restarting the shell is required when you switch.

    Azure portal Cloud shell CLI

    Azure portal Cloud shell PowerShell


  3. Select Upload/download files, and then select Upload.

    Azure portal Cloud shell upload file

    Azure portal Cloud shell upload file


    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.

    Azure portal Cloud shell list file

    Azure portal Cloud shell list file


  4. 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:

    Azure portal Cloud shell deploy template

    Azure portal Cloud shell deploy template


    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.

  5. 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.

Clean up resources

When the Azure resources are no longer needed, clean up the resources you deployed by deleting the resource group.

  1. From the Azure portal, select Resource group from the left menu.
  2. Enter the resource group name in the Filter by name field.
  3. Select the resource group name. You shall see a total of six resources in the resource group.
  4. Select Delete resource group from the top menu.

Next steps

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