Deploying Azure Templates with Visual Studio Code

1 hour
  • 7 Learning Objectives

About this Hands-on Lab

In this lab, we use a Windows 2019 Server with Visual Studio Code to deploy an Azure QuickStart template. We have been asked to deploy a Ubuntu virtual machine for the developer team to test a new application. The developers have requested a standard B2S virtual machine with TCP ports 443 open to the internet both on inbound and outbound channels.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Provision Visual Studio 2019 Community Virtual Machine
  1. Click Home > + Create a resource.

  2. Search for "Visual Studio 2019 Community (latest release) on Windows 2019 Server (x64)".

  3. Click Create.

  4. Select the provided Resource Group.

  5. Enter Virtual machine name "VS-Studio-01".

  6. For Region, select (US) West US.

  7. For Availability Options, No infrastructure redundancy required.

  8. For Azure Spot Instance, No.

  9. For Size, Change Size, then select B2s.

  10. For Administrator Account, enter "Admin1234567" without the quotes for Username and Password.

  11. For Public inbound ports, Allow selected ports.

  12. Select the inbound ports RDP (3389).

  13. For Already have a Windows Server License?, select No.

  14. Click Next: Disks.

  15. Click Create and attach a new disk.

  16. Accept the defaults and click OK.

  17. Click Review and Create and then Create.

Connect to Visual Studio Virtual Machine and Add Plugins
  1. Connect to VS-Studio-01 via RDP. Log in with Admin1234567 as the username and password.

  2. Open Visual Studio Code.

  3. Open Marketplace and install Azure CLI Tools.

  4. Install Azure Powershell Tools.

  5. Open the following website and click Install:
    https://marketplace.visualstudio.com/items?itemName=msazurermtools.azurerm-vscode-tools

Note: All plugins are from Microsoft.

Download and Modify “101-vm-simple-linux” Template from GitHub
  1. Open the 101-vm-simple-linux template from GitHub.
  1. Open raw view, then copy all.

  2. In Visual Studio Code, create a new local JSON file in VS Code called azuredeployment.json.

  3. Paste the copied template contents into azuredeployment.json.

  4. Create a file azuredeployment.parameters.json.

  5. Paste the template parameters from the RAW view.

  6. Save the parmeters file azuredeployment.parameters.json.

  7. Modify the azuredeployment.json file to add the SSL Inbound Allow.

    • Copy from line 148 to line 159.
    • Change Line 159 to }, then hit Return.
    • On Line 160, paste the copied lines.
    • Change name to "SSL".
    • Change priority to 1001,.
    • Change destinationPortRange to "443".
  8. Change Line 20 Authentication Type to "password"

  9. Save the tenplate azuredeployment.json.

Configure Azure Cloud Shell

Click the [>_] Icon on the blue Azure bar.

  1. Click PowerShell, then Show advanced settings.
  2. Change Cloud Shell Region to West US.
  3. Set Resource group to Use existing.
  4. Use build a unique Storage account and File share by using the following:
    • lalab446mmddyyyy (use the 8-digit date or mmddyyyy, e.g. la44601212020)
  5. Click Create Storage.

If successful, you should see something similar to:

Your cloud drive has been created in:

Subscription Id: 4cedc5dd-e3ad-468d-bf66-32e31bdb9148
Resource group:  212-e743b5-deploying-azure-templates-with-cloud-shell-6gd
Storage account: la44601212020
File share:      la44601212020

Initializing your account for Cloud Shell...
Requesting a Cloud Shell.Succeeded.
Connecting terminal...

Welcome to Azure Cloud Shell

Type "az" to use Azure CLI
Type "help" to learn about Cloud Shell

linuxacademy@Azure:~$
Configure Template Storage and Upload

Select the unique Storage account created with the following:
lalab446mmddyyyy

  1. Under Settings in the left-hand menu, click Configuration.
  2. Set Allow Blob public access to Enabled.
  3. Under Blob service in the left-hand menu, click Containers.
  4. Click + Container to add a new container.
  5. Enter "templates" into the Name box.
  6. Set Public access level to Blob (anonymous read access for blobs only).
  7. Click Create.
  8. Double-click the templates folder.
  9. Upload both azuredeployment and azuredeployment.parameters.
  10. Double-click the link for azuredeployment.json.
  11. Copy the URL to the clipboard.
Deploy Azure Template via Azure Cloud Shell
  1. In the Cloud Shell window, run the following command:

    Get-AzResourceGroup

    This should return a response similar to the following:

    PS Azure:> Get-AzResourceGroup
    
       ResourceGroupName : 210-c1eed6-deploying-azure-templates-with-visual-studio-xti
        Location          : westus
    Tags              :
    ResourceId        : /subscriptions/4cedc5dd-e3ad-468d-bf66-32e31bdb9148/resourceGroups/210-c1eed6-deploying-azure-templates-with-visual-studio-xti 
  2. Create the deployment. Remember to replace the RESOURCE_GROUP_NAME and the URL_COPIED_IN_THE_PREVIOUS_TASK with the appropriate values.

    az group deployment create -g RESOURCE_GROUP_NAME --template-uri URL_COPIED_IN_THE_PREVIOUS_TASK

If successful, we will get a success message.

Deployment Validation
  1. Once the deployment is complete, click All resources in the Azure portal.
  2. Click simpleLinuxVM.
  3. Under Settings, click Networking.
  4. Verify the existence of the SSL rule.

Additional Resources

Our developers need a Linux VM with port 443 allowed inbound. They tested with a VM built from the Azure Quickstart template 01-vm-simple-linux, which has everything except the port 443 allowance. We will use Visual Studio Code to modify the template prior to deployment.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?