Tuesday, March 21, 2017

Deploy Microsoft Azure IaaS resources using ARM templates

Deploy Microsoft Azure IaaS resources using ARM templates

Objective

Scenario

Virtual Machines

  1. AZRCamp-Admin
  2. AZRCamp-Edge
  3. AZRCamp-DC
  4. AZRCamp-Sync

Exercise 1 : Azure Subscriptions

This IT Camp lab requires a valid Azure subscription. While you may use an existing subscription such as a

subscription associated MSDN account or existing corporate account, it is strongly recommended to use a

an Azure Free Trial account or an Azure Pass. By using a Free Trial or an Azure Pass, you will avoid any

charges against your MSDN or corporate subscription that would result from doing the exercises in this

camp.

Your instructor may be able to provide you with a code that will allow you to redeem an Azure Pass. Or,

you may use a CLEAN and UNUSED Azure Trial account.
  1. Create a Free Trial Account
    Navigate to www.live.com and click Sign up now.
  2. Follow the on-screen instructions
    Follow the on-screen instructions to create a new Microsoft Account.
  3. Navigate to www.azure.com and click Free Trial
    Navigate to www.azure.com and click Free Trial.
  4. Follow the on-screen instructions
    Follow the on-screen instructions to activate a new Windows Azure Trial.
  5. Navigate to Manage.windowsazure.com and sign in
    Navigate to Manage.windowsazure.com and sign in.
  6. In Microsoft Azure portal
    In Microsoft Azure portal, in the upper left, click your user name, and then click View my bill.
  7. Click your current trial subscription
    Click your current trial subscription, and then click Edit subscription details.
  8. Type a name you will recognize
    Type a name you will recognize in SUBSCRIPTION NAME, such as ITCamps, and then click the

    Done icon.
 Click Continue to advance to the next exercise.

Exercise 2 : Configure an Azure Pass

Your instructor may be able to provide you with a pre-provisioned Microsoft Account that already has an

Azure Pass subscription associated with it. Alternatively, your instructor may be able to provide you with

an Azure promotional code.
  1. If you are not using the lab virtual machine
    If you are not using the lab virtual machine to activate your Azure Pass promotional code, ensure

    you open an InPrivate browser session before performing these steps.
    It is critically important that you do not accidently associate the promotional code with any account that has previously been associated with or linked to an Azure subscription. Use an InPrivate browser session to ensure that no credentials are unintentionally forwarded during the process to activate and
    redeem the promotional code. If you fail to activate the code because you logged in with the wrong account, you will render the code useless and will not be able to use it again.
  2. Navigate to www.live.com and click Sign up now
    Navigate to www.live.com and click Sign up now.
  3. Follow the on-screen instructions
    Follow the on-screen instructions to create a new Microsoft Account.
    Please ensure, you create an outlook.com, live.com or Hotmail.com account. Do not use accounts that have country code suffixes, such as .dk, ca, uk, etc. in their names.
  4. Navigate to http://www.microsoftazurepass.com
    Navigate to http://www.microsoftazurepass.com and follow the onscreen instructions to redeem
    the promotional code.
    Once you have submitted the promotional code, it will take a few minutes for the account to become activated. Only one promo code can be redeemed per the life of the Microsoft ID.
  5. Follow the on-screen instructions to activate
    Follow the on-screen instructions to activate a new Windows Azure Trial.
  6. Navigate to Manage.windowsazure.com and sign in
    Navigate to Manage.windowsazure.com and sign in.
  7. In Microsoft Azure portal
    In Microsoft Azure portal, in the upper left, click your user name, and then click View my bill.
  8. Click your current trial subscription
    Click your current trial subscription, and then click Edit subscription details.
  9. Type a name you will recognize
    Type a name you will recognize in SUBSCRIPTION NAME, such as ITCamps, and then click the
    Done icon.
Click Continue to advance to the next exercise.

Exercise 3 : Prepare the Azure Infrastructure

In this exercise, you will use the Lab01Start.ps1 script to log on to your Azure subscription and create an

Azure resource group that you will use for the remaining lab exercises. The script will also determine a

globally unique name that you can use to create a storage account in subsequent lab exercises.
  1. Run the Lab01Start.ps1 script
    Perform the following tasks on AZRCAMP-ADMIN:

    Open File Explorer and navigate to C:\LabFiles\AZRITPROCamp\Lab01-Deploy Azure resources using templates.  You may also download files used for this lab from the GitHub repository for the course at https://github.com/AZITCAMP/Labfiles.
    To perform the subsequent lab exercises, you need to create an Azure Resource Group and determine a globally unique name you can use to create a storage account.
  2. Right-click Lab01Start.ps1, and click Edit
    Right-click Lab01Start.ps1, and click Edit.  The Windows PowerShell ISE console opens.
  3. In Windows PowerShell ISE
    In Windows PowerShell ISE, on the upper Ribbon, click Run Script (green arrow).
  4. When prompted, enter a lower-case string
    When prompted, enter a lower-case string that represents your initial, and press ENTER.  The storage account name must contain only lower case letters and numbers and must be globally unique.
  5. In the Sign in to Windows Azure PowerShell dialog
    In the Sign in to Windows Azure PowerShell dialog box, enter the email address of the account associated with your Azure subscription, and click Continue.
  6. On the sign in page, enter your password
    On the sign in page, enter your password, and click Sign in.  The script starts running and then pauses to display a name verified as unique for use a storage account name.
  7. Record the unique storage account name
    Record the unique storage account name, and press ENTER to continue.  You will need to know the unique name for the storage account in a subsequent lab exercise.
  8. Leave the Windows PowerShell ISE console open
    Leave the Windows PowerShell ISE console open for subsequent lab exercises.
Click Continue to advance to the next exercise.

Exercise 4 : Understand Azure Quickstart templates

JSON templates simply provide a different way of defining the same types of resources that you may be
familiar with using the classic Azure model. For example, to create a new VM using the Azure Service
Management mode, you would specify the image name, the virtual machine name, the size, the
administrative account, the password credential, and other values. When deploying resources using JSON
templates, you specify the same information, but in a different format.

It is rarely necessary to create a JSON template from scratch. Microsoft maintains a large and growing
library of community contributed Azure templates on GitHub that you can leverage to learn about JSON
templates and to deploy your own applications.

In this task, you will view the quickstart templates that are available on GitHub and examine one of them
in depth.
  1. Navigate to
    Open Microsoft Edge (or Internet Explorer) and navigate to https://github.com/Azure/azure-quickstart-
    templates
    .
    Perform the following tasks on AZRCAMP-ADMIN logged on as Contoso\Administrator using Passw0rd! as the password:
    GitHub is a repository service, based on Git that provides source control management (SCM) and revision control. GitHub expands on the functionality of the command-line based Git by providing a GUI

    and collaboration features.
  2. On the Azure Quickstart Templates page
    On the Azure Quickstart Templates page, spend a few moments examining the titles and scroll
    down the page
  3. Templates that have a prefix of 101
    Templates that have a prefix of 101 are simple templates; templates that have a prefix of 201 are
    more advanced and complex templates.  A searchable index of the quickstart templates is available at https://azure.microsoft.com/enus/documentation/templates.
  4. Scroll down the page
    Scroll down the page, locate, and then double-click  101-vm-simple-windows.

    Note that the folder contains 4 files: 1) The README.md is an html file that contains the description and
    the button that you can click to deploy the template to an Azure subscription, 2) the azuredeploy.json
    file is the main file used to deploy the cloud resources, 3) the azuredeploy.parameters.json is the file
    where you can provide values for the parameters defined in the azuredeploy.json file and pass them in
    at execution time, and 4) the metadata.json file provides additional data about the deploy template.

  5. Click azuredeploy.json
    Click azuredeploy.json.
  6. The JSON file opens as shown below
    The JSON file opens as shown below:

    Please click on the camera icon on the lower left hand side to view the screenshot.
    A JSON file is constructed of key/value pairs. For example, in the image above, “ContentVersion" is thekey and "1.0.0.0" is the value. A key is always a string enclosed in quotation marks. A value can be a string, securestring, number, boolean expression, array, or object. A JSON object is enclosed in curly braces, "{ }". In a key/value pair the key is always followed by a colon. Key/pairs are separated by commas.

    A JSON template may also contain functions and expressions. Expression are enclosed in square
    brackets, “[ ]', and can appear anywhere in a JSON string. Functions calls have the format functionName(arg1,arg2,arg3). Properties are referenced using the dot and index operators.

    A JSON template may have as many as six sections: 1) $schema (a required element that provides the
    location of the file that describes the version of the template language, 2) (a required element that
    provides the version of the template), 3) parameters (an optional element that defines values that are passed in when the template is executed), 4) variables (an optional element that defines the values that are used when template is executed), 5) resources (a required element that defines the resources that are deployed or updated in a resource group), and 6) outputs (an option element that defines values that are returned after a deployment.)
  7. At the top of the file
    At the top of the file, note the first line that references a JSON schema. The schema reference is used by intelligent JSON clients to determine the schema that is applicable to the JSON file and to provide additional functionality such as autocomplete and intellisense.
  8. Note the Parameters key
    Note the Parameters key.
    The value for the Parameters key is an array of parameter objects that represent the dynamic input for the JSON template. Each of the parameter objects has a name that is used to pass values in at runtime and is referenced within the JSON itself in other sections. For example, "NewStorageAccount" is the name of the parameter that is supplied as an input and used to provide the name of the storage account resource specified in the JSON file.
  9. In the parameters section
    In the parameters section, note the "adminPassword" parameter, and note that the "type" value.
    Each parameter has a type, such as string, securestring, number, etc. Securestring is a special data type that is used to ensure that the value is not persisted anywhere in the Azure platform. This ensures that sensitive information such as passwords are not displayed.
  10. Scroll down to view the WindowsOSVersion
    Scroll down to view the WindowsOSVersion parameter object.
    Note that a parameter can include a default value. When you execute the JSON template, you will be prompted for any parameter values that are missing from the input, unless you have specified a default value. Note also that a parameter can include an array of allowed values, which is useful if you want to constrain the input to a set of specific values, for example specific regions, etc. Finally, note the metadata key, where you can include a description of the parameter.
  11. Scroll down to the variables section
    Scroll down to the variables section that begins at around line 42.
    Variables, in general, represent static values that are already present in the template, in contrast to parameter values which are passed in at execution time. Variables can also be used to simplify template language expression by using expression and functions, such as "[resourceId…]" and "[concat…]", as highlighted above. In the case of the concat function, variables can be composed of other variables or parameter values that are input at run time. ResourceId is a helper function that is used to get unique IDs of resources.
  12. Scroll down to the resources section
    Scroll down to the resources section that begins at around line 61.
    In the resources array section, you define the resources that you wish to deploy or update. Each resource must include a type, name, and apiVersion. The type value is the namespace of the resource provider and the supported resource type. The value for the type is a substring of the URL you would use if you wanted to create a resources, such as a storage account, against the Azure REST (representational state transfer) API (application programming interface). When the template is deployed, the template engine makes the same HTTP put calls that would be made if you were directly interacting with the API.

    If you wish to find out the values and the properties associated with a resource, you can find the documentation on the Azure REST APIs here: https://msdn.microsoft.com/enus/library/azure/mt420159.aspx. For example, to find out more information about the Microsoft.Storage/storageaccounts resource, you can consult the Azure Storage Provider REST API reference at https://msdn.microsoft.com/en-us/library/azure/mt163683.aspx.

    Optional key/value pairs for resource objects include location (where you define the geo-location for the resource), properties (where you define resource-specific settings), tags (that provide metadata associated with resource), resources (child resources that depend on the resource being defined), and dependsOn (resources that the resource being defined depends on).
  13. Scroll down to the beginning of the VM
    Scroll down to the beginning of the virtual machine resource definition, which begins at around line 131.
    Note the "dependsOn" key/value pair. Before the virtual machine can be created, the storage account and the network interface, which in turn has dependencies of its own (see lines 105 -111), must exist. The script is evaluated for dependencies to create objects in the appropriate order. If no dependencies are specified, Azure Resource Manager attempts to create them in parallel. This can result in much faster deployments for large and complex infrastructures over the Azure Service Manager mode.
  14. In the Microsoft Edge Browser
    In the Microsoft Edge Browser, click back to return to the previous page.
  15. On the 101-simple-windows-vm page
    On the 101-simple-windows-vm page, click Deploy to Azure.
  16. On the Microsoft Azure sign in page
    On the Microsoft Azure sign in page, enter the email address and password associated with your subscription, and sign in.  The Azure Portal opens showing the Custom deployment and Parameters blades.

    Note that the Parameters blade provides fields for text input. In the case of the WINDOWSOSVERSION parameter, note the presence of a default value and a drop-list of allowed values.
  17. On the Custom deployment blade
    On the Custom deployment blade, click Edit template.  You can edit the template before deploying it, for example, to change variable names or modify resources that the template describes for deployment.
  18. Close the Edit template blade
    Close the Edit template blade.
  19. In the Custom deployment blade
    In the Custom deployment blade, in Resource group, click Use Existing Or create new.
  20. In the Create a new resource group text box
    In the Create a new resource group text box, type test.
  21. Click Resource group location
    Click Resource group location.

    Note that once you enter a name for a new resource group, you can also specify a location.
  22. Review the locations
    Review the locations, and the close the Location blade.
  23. Close the Custom deployment blade
    Close the Custom deployment blade. You are not going to deploy the template at this time. Rather, you will modify the template in a subsequent task and then explore other ways of deploying the template.
  24. If prompted by a warning
    If prompted by a warning indicating your unsaved edits will be discarded, click OK.
  25. Leave the Azure Portal open
    Leave the Azure Portal open for a subsequent lab exercise.
Click Continue to advance to the next exercise.

Exercise 5 : Configure Git repository and Visual Studio Code (Optional)

As you saw in the previous exercises, GitHub is used to store ARM templates and other code-related
objects. GitHub is a web-based Git repository to ensure availability and provide a version control system
for files.

Version control systems record changes to files or a set of files so that they can retrieved at a later time.
There are different kinds of version control systems, the simplest being the manual use of multiple folders
to store different versions of your files.

More sophisticated and fault tolerant version control systems use central or distributed databases to
store the files and their changes.

Git is a distributed version control system in which clients clone entire repositories to ensure that there is
no single point of failure. If a particular repository fails, the contents can be restored from a cloned copy
that exist elsewhere.

In this exercise, you will learn more about GitHub and Git repositories. You will also learn how to configure
Visual Studio Code to use Git.
  1. Create GitHub account and public repository
    Perform the following tasks on AZRCAMP-ADMIN logged on as Contoso\Administrator using Passw0rd! as the password:  On AZRCAMP-ADMIN, open Microsoft Edge.
    The remaining lab exercises require that you have a GitHub account and repository named Templates.
    In this task, you create a GitHub account and then configure a public repository named Templates.

    This lab exercise is optional if you already have a GitHub account.

    Note that, if you do have a GitHub account and you have enabled 2-factor authentication for it, you may have difficulties authenticating to your account when using Visual Studio Code. If you have 2-factor authentication enabled on your Git repository, consider creating a Git account for this lab.
  2. Navigate to https://github.com
    Navigate to https://github.com
  3. On the home page, click Sign up
    On the home page, click Sign up.
  4. On Join GitHub page
    On Join GitHub page, enter a username, email address, and password.  Please note that when you perform certain operations on GitHub, such as commits, your email address is publically viewable. For more information, please see https://help.github.com/articles/keepingyour-email-address-private/.
  5. Click Create an account
    Click Create an account.
  6. On the Welcome to GitHub page
    On the Welcome to GitHub page, click Finish sign up.
  7. On the GitHub Bootcamp page
    On the GitHub Bootcamp page, click Create a repository.
  8. Open your email client
    Open your email client and open the verification email sent to you by the GitHub web site.
  9. Click Verify email address
    Click Verify email address.
  10. Switch to the GitHub page
    Switch to the GitHub page.
  11. Click Create a repository
    Click Create a repository (alternatively, in the upper right corner, click +, and then click New
    repository).
  12. In Repository name, type Templates
    In Repository name, type Templates, select Initialize this repository with a README, and then
    click Create repository.  You will clone the repository in the next task.
  13. Leave the Microsoft Edge browser open
    Leave the Microsoft Edge browser open for the next task.
Click Continue to advance to the next exercise.

Exercise 6 : Configure GitHub desktop and clone repository

In this task, you will launch GitHub, configure settings for the application, and then clone the Templates

repository you configured
  1. Switch to the desktop of the AZRCAMP-ADMIN
    Switch to the desktop of the AZRCAMP-ADMIN
    Perform the following tasks on AZRCAMP-ADMIN logged on as Contoso\Administrator using Passw0rd! as the password:
  2. On the desktop, double-click GitHub
    On the desktop, double-click GitHub.  The GitHub desktop application was installed as part of the lab setup.
  3. On the Welcome page
    On the Welcome page enter your GitHub username and password, and the click Log in.
  4. Click Continue
    Click Continue.
  5. Under No local repositories found, click dashboard
    Under No local repositories found, click dashboard. The GitHub desktop application opens showing a pre-configured Git repository named Tutorial that contains a .gitattributes and .gitignore files. Before proceeding with the next steps, feel free to launch the tutorial by clicking Got it!. Otherwise, close the tutorial.
  6. In the upper right corner
    In the upper right corner, click Settings (the gear icon).
  7. Click Options.
    Click Options.
  8. On the Options page
    On the Options page, in Clone path, enter C:\GitHub, and then click Save.
  9. On the GitHub home page
    On the GitHub home page, in the upper left corner, click Add (plus sign).
  10. Click Clone
    Click Clone.
  11. Click Templates
    Click Templates, and then click Clone Templates., and then click Clone Templates.
  12. In the Browse for Folder dialog box
    In the Browse for Folder dialog box, ensure that C:\GitHub is selected, and then click OK.  If you receive an error, ensure that the Tutorial repository is closed/removed and perform step 12 again.
  13. On the desktop, double-click Git-Shell
    On the desktop, double-click Git-Shell.  A PowerShell window opens. The option to integrate the Git commands with PowerShell is configured in the GitHub client.
  14. At the PowerShell prompt
    At the PowerShell prompt, type the following command and press ENTER.

    ↪ Git config --global credential.helper wincred

    This command is necessary to ensure that Visual Studio code can authenticate against the GitHub web site. The command is case-sensitive.
  15. At the PowerShell prompt
    At the PowerShell prompt, type the following command and press ENTER.

    ↪ Git config --list

    This command shows the settings that are configured for Git. Note the bottom of the output displays
    your GitHub user name and email address. These settings were configured when you logged into the
    GitHub Windows client. Normally, you would configure Git using commands from a shell, such as Bit
    Lab created by HynesITe, Inc. For questions or comments, send an email message to content@hynesite.biz Page | 26
    Bash or the integrated PowerShell prompt you see in the lab. For more information on configuring and
    using Git, please see http://git-scm.com/doc.
  16. Open File Explorer
    Open File Explorer, and browse to C:\LabFiles\AZITPROCamp\Lab01-Deploy Azure resources
    using templates.
  17. Select and right-click 101-simple-windows-vm
    Select and right-click 101-simple-windows-vm, and then click Copy.  For your convenience, the Azure Quickstart template you examined in the previous exercise was previously downloaded as part of the lab set up.
  18. In File Explorer
    In File Explorer, navigate to C:\GitHub\Templates.
  19. Press CTRL-V
    Press CTRL-V to paste the folder to C:\GitHub\Templates.
  20. In File Explorer, on the Ribbon
    In File Explorer, on the Ribbon, click View, and then select Hidden items.  The hidden .git folder appears. This folder is created upon initialization of Git repository. The .git folder includes Git database and other files necessary for staging and committing changes to files for source version control.
  21. Close File Explorer
    Close File Explorer.
Click Continue to advance to the next exercise.

Exercise 7 : Examine Visual Studio Code integration with Git and push commits to remote repository

Visual Studio Code has integrated support for the most common Git commands, for example, to stage
and commit changes.

In this task, you will see a demonstration of Visual Studio Code integration with Git and push commits
(changes you wish to be permanent) to the remote repository on GitHub.
  1. Open Visual Studio Code
    On the Desktop or from the taskbar, open Visual Studio Code.
    Perform the following tasks on AZRCAMP-ADMIN logged on as Contoso\Administrator using assw0rd! as the password:
  2. If you see a message
    If you see a message indicating that you need to install Visual Studio Code, please ignore the
    message (or click Later) and complete the steps below.
  3. In Visual Studio Code
    In Visual Studio Code, click File, and click Open Folder.
  4. In the Select Folder dialog box
    In the Select Folder dialog box, navigate to C:\GitHub, click Templates, and then click Select
    Folder. 

    The folder opens and Visual Studio Code provides a visual indication that Git detects uncommitted files in the folder. These are the files you copied to the folder earlier.  You may have to close and reopen the folder to see the uncommitted indication as per the screen shot  below. To close the folder, click File, and then click Close Folder.

  5. Click the Git icon on the left
    Click the Git icon on the left.
  6. Press the CTRL key down, and select both files
    Press the CTRL key down, and select both files.
  7. Click the ellipsis
    Click the ellipsis, and then click Commit All.
    Git files have three states: modified, staged, and committed. Modified means that the files are in a workspace and have been changed but have not yet been committed to the database in the repository. Staged means the files have been moved to a staging area prior to being committed, for example, as a holding area pending review. Committed means that a snapshot of the file is committed to the database.
  8. In Message, type Initial Version
    In Message, type Initial Version, and press CTRL+ENTER.

    These files will represent a starting point for changes you will make in a subsequent exercise.  The changes are committed to the local repository. The files disappear from view in the Git node. In the next step, you will push the committed files to the remote repository.
  9. Click the ellipses, and then click Push
    Click the ellipses, and then click Push.
  10. When prompted by Visual Studio Code dialog box
    When prompted by Visual Studio Code dialog box, enter your Git username and password, and click OK.
    The authentication fails. This is expected.
  11. When prompted with an error message
    When prompted with an error message indicating that Authentication failed on the git remote,
    click Close.
  12. Open File Explorer
    Open File Explorer, and browse to C:\LabFiles\Utils and double-click git-credentialwinstore.exe.
  13. When prompted, click Yes
    When prompted, click Yes.

    This small executable downloaded from Codeplex.com resolves an issue with authentication to GitHub
    using VSCode.  If you have enabled multi-factor authentication on your GitHub repository, this workaround may not be effective.
  14. Switch to Visual Studio Code
    Switch to Visual Studio Code, click the ellipses, and then click Push.
  15. When prompted by the Git Credentials dialog box
    When prompted by the Git Credentials dialog box, enter your Git username and password, and
    click OK.  The committed files in the local repository are pushed to the repository on GitHub.
  16. Leave Visual Studio Code open
    Leave Visual Studio Code open for subsequent lab steps, and switch to the instance of Microsoft
    Edge that you left open in a previous task.
  17. Ensure that you are viewing the Templates page
    Ensure that you are viewing the Templates page for your repository, and then press F5 to refresh the page.  You should see the 101-simple-windows-vm folder from your local repository.
  18. Click 101-simple-windows-vm
    Click 101-simple-windows-vm.  You should see the two JSON files in the folder.
  19. Leave the browser open
    Leave the browser open for subsequent steps in the next exercise.
Click Continue to advance to the next exercise.

Exercise 8 : Modify and Deploy Azure Quickstart Templates

As you learned in the previous exercise, it is rarely necessary to construct a JSON-based Azure Resource Manager template from scratch. In many instances, you will be able to find a sample template to use as a starting point for your own template. A basic understanding of how templates are constructed, combined with an appropriate sample template to use as a starting point, will allow you to create your own custom templates with relative ease.

For additional information on authoring and modifying template files, please see Authoring Azure Resource Manager templates at https://azure.microsoft.com/en-us/documentation/articles/resourcegroup-authoring-templates/.

In this exercise, you will build on the understanding that you acquired in a previous exercise to customize a sample template and then deploy it.
  1. If not already open
    If not already open, open Visual Studio Code, and navigate to the C:\GitHub\Templates\101-simple-windows-vm folder.
    In a previous exercise, you examined the 101-simple-windows-vm template that is available on GitHub.  You subsequently added this template to your own Git repository. In this task, you will customize this template and its related parameters JSON file using Visual Studio Code to meet your specific and additional requirements. Also, you will stage and commit your changes to the local and remote Git repository.

    Perform the following tasks on AZRCAMP-ADMIN logged on as Contoso\Administrator using Passw0rd! as the password:
  2. In the tree pane, click azuredeploy.json
    In the tree pane, click azuredeploy.json
  3. Type the following code below line 28
    Type the following code below line 28.

    Note that intellisense and autocomplete make the task of entering JSON easier.  Recall the parameters are passed to the template at runtime and allow users the ability to specify values.  In this case, you are creating a default value and restricting choice to locations where Premium storage is available. For a list of datacenters showing the services offered by each, please see http://azure.microsoft.com/en-us/regions/#services.
  4. Scroll down to the variables section
    Scroll down to the variables section, and delete the "location": "West US" key/value pair.
  5. Click Edit and then click Replace.
    Click Edit and then click Replace.
  6. In Find, type variables('location')
    In Find, type variables('location'); in Replace, type parameters('location'), and then click Replace All, as shown below.
  7. Scroll to the end of the parameters section
    Scroll to the end of the parameters section and the start of the variables section.
  8. At the end of
    At the end of the second-last closing brace before the variables section, add a comma, as shown below.
  9. Add the following lines of code
    Then, add the following lines of code to create a parameter for size of the data disk.

    Tip: You can find the completed solution in the C:\LabFiles\AZIT{ROCamp\Solutions folder. If you like, you can copy and paste code from the solution into your JSON script.
  10. Scroll to the end of the variables section
    Scroll to the end of the variables section, and add a comma at the end of the subnetRef key/value pair:
  11. Then, type the following
    Then, type the following on a single line at the end of the variables section:

    ↪ "dataDisk1VhdName":
        "[concat('http://',parameters('newStorageAccountName'),'.blob.core.w
        indows.net/',variables('vmStorageAccountContainerName'),'/',variable
        s('vmName'),'dataDisk1.vhd')]"

    You can find the completed solution in the C:\LabFiles\AITPROCamp\Solutions folder.
  12. Scroll down to the resources section
    Scroll down to the resources section and locate "osDisk" section.
  13. Between the "osDisk" and "networkProfile" section
    Between the "osDisk" and "networkProfile" section, add the following resource:

    Please click on the camera icon on the lower left hand side to view the screenshot.
    Be very careful where you place this code section. Before proceeding to the next step, scroll to the end of the file and double-check for any red squiggles that might indicate improper placement of this snippet.
  14. Click File and then click Save
    Click File and then click Save.
  15. Click the Git icon on the left
    Click the Git icon on the left.
  16. Under CHANGES, click azuredeploy.json
    Under CHANGES, click azuredeploy.json.  Two screens appear. The left screen shows the original file; the right screen shows the changes.
  17. Review your changes, right-click azuredeploy.json
    Review your changes, right-click azuredeploy.json, and then click Stage.
  18. On the left, click the Explore icon
    On the left, click the Explore icon.
  19. Click azuredeploy.parameters.json
    Click azuredeploy.parameters.json.
  20. In azuredeploy.parameters.json
    In azuredeploy.parameters.json, add key/value pairs for the location, WindowsOSVersion, and sizeOfDiskInGB parameters and provide unique names for the storage account and DNS name, as follows:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  21. Save the azuredeploy.parameter.json file
    Save the azuredeploy.parameter.json file.
  22. Click the Git icon in the navigation pane
    Click the Git icon in the navigation pane, right-click azuredeploy.parameters.json, and click Stage.
  23. Click the ellipses, and the click Commit Staged
    Click the ellipses, and the click Commit Staged.
  24. In the Message box, type Update1
    In the Message box, type Update1, and press CTRL+ENTER.  A snapshot of the files is now committed to the local repository.
  25. Click the ellipses, and then click Push
    Click the ellipses, and then click Push.

    Note that you are not prompted for credentials. You configured credential caching earlier with the
    git config --global credential.helper wincred command.
  26. Switch to the Microsoft Edge browser
    Switch to the Microsoft Edge browser you left open in the previous exercise and press F5 to
    refresh the page.  You should see that the two JSON files have been pushed to the remote repository.
  27. Leave the browser open for the next task
    Leave the browser open for the next task.
Click Continue to advance to the next exercise.

Exercise 9 : Deploy custom JSON files

In the previous task, you modified the sample JSON to meet specific requirements and subsequently committed your changes to both a local and remote Git repository. In this task, you will examine deploying the custom template using the Azure portal and Windows PowerShell.
  1. If not already open
    If not already open, open Visual Studio Code, and navigate to the C:\GitHub\Templates\101-simple-windows-vm folder.
    Perform the following tasks on AZRCAMP-ADMIN logged on as Contoso\Administrator using Passw0rd! as the password:
  2. In the tree pane, click azuredeploy.json
    In the tree pane, click azuredeploy.json.
  3. Click anywhere in the details pane
    Click anywhere in the details pane, press CTRL+A and then press CTRL+C to copy the contents of
    the file to the clipboard.
  4. Switch to Microsoft Edge
    Switch to Microsoft Edge.
  5. Open a new tab
    If not already logged on to the Microsoft Azure portal, open a new tab, navigate to
    https://portal.azure.com, and log on the account you are using for your Azure subscription.
  6. In the Microsoft Azure portal
    In the Microsoft Azure portal, in the navigation pane, click New.
  7. In the New blade, click Marketplace
    In the New blade, click Marketplace
  8. In Search everything text box
    In Search everything text box, type Template, click Template deployment from the drop-down list, and press ENTER.
  9. Double-click Template deployment in the results
    Double-click Template deployment in the results.
  10. In the Template deployment blade, click Create.
    In the Template deployment blade, click Create.
  11. The Custom deployment blade appears
    The Custom deployment blade appears.
  12. In the Custom deployment blade
    In the Custom deployment blade, click Edit template.
  13. In the Edit template blade
    In the Edit template blade, delete all the lines of JSON script.
  14. Place the cursor in the template area
    Place the cursor in the template area, and press CTRL+V to paste the JSON script that you copied to the clipboard earlier.
  15. Click Save
    Click Save.
  16. Click Edit parameters
    Click Edit parameters.

    The Parameters blade should appear immediately. If it does not, this means that there is something wrong with your JSON script, most likely a mismatch between opening and closing braces or brackets.

    If the template has the proper formatting, you will see small green rectangle in the upper right side of the template; otherwise, you will see small red squares on the right side that provide an approximate location of the source of the problem.
  17. In the parameters blade
    In the parameters blade, note the presence of the LOCATION (string) and SIZEOFDISKINGB (string) parameters that you added to the original JSON script.
  18. Close Parameters and the Custom deployment blades
    Close the Parameters and the Custom deployment blades without creating the deployment.  You are going to deploy your custom template using a PowerShell command in a later step. You examined how to deploy a custom template in the Azure portal as a demonstration and to do a final verification on your template.
  19. When prompted, click OK to discard unsaved edits
    When prompted, click OK to discard unsaved edits.
  20. Close all open blades
    Close all open blades in the portal to return to the Start page.
  21. Leave Microsoft Edge open for subsequent steps
    Leave Microsoft Edge open for subsequent steps.
  22. Switch to the Windows PowerShell ISE console
    Switch to the Windows PowerShell ISE console you left open in a previous exercise.  If you closed the console, please open it and run the C:\LabFiles\AZITPROCamp\Lab01..\Lab01Start.ps1 script again.
  23. In the command pane
    In the command pane, type the following command on a single line, and press ENTER.

    ↪ New-AzureResourceGroupDeployment -DeploymentName "Simple-VM"
        -ResourceGroupName RG-AZITCAMP -TemplateFile
        "C:\GitHub\Templates\101-simple-windows-vm\azuredeploy.json”

    You will be prompted for the storage account name, as shown below. If you do not wish to be prompted for required parameters, you can add a template parameter file to the command. You will do this in the next steps. However, you will use the version of the JSON scripts that are available in your remote repository.
  24. In the PowerShell command pane
    In the PowerShell command pane, press CTRL+C to break out of the command.
  25. Switch to Microsoft Edge
    Switch to Microsoft Edge.
  26. In the tab that displays the contents
    In the tab that displays the contents of your GitHub Templates repository, click azuredeploy.json.
  27. On the azuredeploy.json page, click Raw
    On the azuredeploy.json page, click Raw.
  28. Copy the URL displayed for the raw version
    Copy the URL displayed for the raw version of the azuredeploy.json file to the value of the $templatefileURI on line 57 of the Lab01Start.ps1 script.
  29. Repeat steps 27 - 29 to copy the URL
    Repeat steps 27 - 29 to copy the URL for the azuredeploy.parameters.json file to the value for the $parameterfileURI variable on line 59 of the Lab01Start.ps1 script.
  30. The resulting section of the script
    The resulting section of the script should look like something this:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  31. Select the entire block of variables
    Select the entire block of variables and click Run Selection.
  32. Scroll to the bottom of the script
    Scroll to the bottom of the script, and remove the # at the beginning of the second command to perform a resource group deployment.
  33. Select the entire line
    Select the entire line, and then click Run Selection.  After a few minutes, the command should return a successful result. You can verify the results by viewing the new resources in the Azure portal.
  34. Please leave the Windows PowerShell ISE console
    Please leave the Windows PowerShell ISE console open for the next exercise.
 Click Continue to advance to the next exercise.

Exercise 10 : Remove resource group used for lab

Because each lab in this series begins with an empty resource and because Azure resources are potentially billable, it is necessary to remove the resource group you created and used in this lab. Also, because Azure trial accounts are limited to 4 compute cores, it is important that you remove the resource group to ensure you do not run out of resources, if you have an Azure trial account.
  1. Remove Azure resource group
    If not already open, open Windows PowerShell ISE.
    In this task you will run a Windows PowerShell script to remove the resource group you created and used in this lab.

    Perform the following tasks on AZRCAMP-ADMIN logged on as Contoso\Administrator using Passw0rd! as the password:
  2. Click File
    Click File, click Open, browse to C:\LabFiles\AZITPROCamp\Scripts, select RGCleanup.ps1, and click Open.
  3. On the menu, click Run
    On the menu, click Run.
  4. When prompted
    When prompted, log into your Azure subscription.
  5. When prompted to delete RG-AZITCAMP-LAB01
    When prompted to delete RG-AZITCAMP-LAB01, click Yes.
  6. If you used a different resource group for the lab
    If you used a different resource group for the lab, you can modify the PowerShell script to delete that resource group.
Congratulations!

Click Continue to close and finalize this lab.

3 comments:

soumya said...

I got a good answer from the above description,but it still requires some more update to be made. Please share more content on Devops Online Course Bangalore

Tejuteju said...

Thank you. Well it was a nice post and very helpful information on
Azure Online Training

Azure DevOps said...

It is really a great work and the way in which you are sharing the knowledge is excellent.
Microsoft Azure Online Training