Tuesday, March 21, 2017

Deploy services using Azure Resource Manager templates

Deploy services using Azure Resource Manager templates

Objective

Scenario

Virtual Machines

  1. TR22 Base Windows 10

Exercise 1 : Deploying Services using ARM Templates

In this task we are going to create a deployment using an ARM Template to deploy a single App Service Plan.
  1. Create a single App Service Plan (Hosting Plan)
    Log in to your Azure account at https://portal.azure.com
  2. In the top-left corner of the portal click + New
    In the top-left corner of the portal click + New.
  3. In the search box at the top
    In the search box at the top, start typing “Template deployment” and select the Template deployment option.
  4. Click the Template deployment item
    Click the Template deployment item and click Create.
  5. Click Edit Template
    Click Edit Template. A template is a description of all the resources that you want to deploy. When you deploy resources, most of the time you also need to supply parameters. For example, you need to specify the region a resource needs to be deployed into. Templates can also describe dependencies between resources, such as a set of ordered instructions.
  6. When you deploy services themselves in Azure
    When you deploy services themselves in Azure, for example a Virtual Machine or a Web App – a template is used under the covers to describe the service and an Azure service called the Azure Resource Manager is used to execute the templates instructions.
  7. On the Edit template blade
    On the Edit template blade locate the line containing his code:"parameters": {}. This should be line 4. Between the braces (“{ }”) put the following:

    "hostingPlanName": {

        "type": "string",

        "metadata": {

            "description": "The name of the App Service plan to use for hosting the web app."

        }

    },

    "siteLocation": {

        "type": "string",

        "metadata": {

            "description": "The location to use for creating the web app and hosting plan."

        }

    },

    "sku": {

        "type": "string",

        "allowedValues": [

        "Free",

        "Shared",

        "Basic",

        "Standard"

        ],

        "defaultValue": "Free",

        "metadata": {

            "description": "The pricing tier for the hosting plan."

        }

    },

    "workerSize": {

        "type": "string",

        "allowedValues": [

        "0",

        "1",

        "2"

        ],

        "defaultValue": "0",

        "metadata": {

            "description": "The instance size of the hosting plan (small, medium, or large)."

        }

    }
  8. The configuration above
    The configuration above defines the parameters that will be used for the template.
  9. Next, update the resources property
    Next, update the resources property (the area between the brackets “[ ]”) with the following.

    "resources": [{

        "apiVersion": "2015-04-01",

        "name": "[parameters('hostingPlanName')]",

        "type": "Microsoft.Web/serverFarms",

        "location": "[parameters('siteLocation')]",

        "properties": {

            "name": "[parameters('hostingPlanName')]",

            "sku": "[parameters('sku')]",

            "workerSize": "[parameters('workerSize')]",

            "numberOfWorkers": 1

        }

    }

    ]
  10. This configuration defines the services
    This configuration defines the services that need to be created, in this case an Application Plan.
  11. In order to make your life easier for next task
    In order to make your life easier for the next tasks, copy the whole configuration into a new instance of Notepad.
  12. Go back to the portal and press Save
    Go back to the portal and press Save.
  13. From the Resource group dropdown, select + New
    From the Resource group dropdown, select + New.
  14. Enter “templateRG”
    Enter “templateRG” as the New resource group location.
  15. Click on Resource group location
    Click on Resource group location and select any of the available regions.
  16. Click the Edit parameters link
    Click the Edit parameters link.
  17. For the HOSTINGPLANNAME, use “templateASP”
    For the HOSTINGPLANNAME, use “templateASP”.
  18. For the SITELOCATION
    For the SITELOCATION, use the same value you selected for the Resource group location which is displayed in the Resource group location link (“West US” in this example).
  19. Leave the other values alone and press OK
    Leave the other values alone and press OK
  20. Click on Legal Terms and press Purchase
    Click on Legal Terms and press Purchase to indicate that you agree with the Legal Terms.
  21. Make sure that Pin to dashboard is selected
    Make sure that Pin to dashboard is selected, and the press the Create.

    It will take a moment for your app service plan to become available.
Click Continue to advance to the next exercise.

Exercise 2 : Create a single App Service Plan and a Web App

  1. You are going to repeat creating the template
    You are going to repeat creating the template you did in the previous task, but you have all this copied in Notepad ready to go.
  2. Create a new template
    Create a new template (+New, search for “Template deployment”, all the way through the first Create to start creating the template).
  3. Click Edit template
    Click Edit template and delete everything that is there.
  4. Switch to Notepad
    Switch to Notepad where you old template definition is waiting. Copy it to the portal to replace the existing default template.
  5. In the parameters section
    In the parameters section, add the following parameter at the beginning of the list, right after the opening “{“.

    "siteName": {

        "type": "string",

        "metadata": {

            "description": "The name of the web app that you wish to create."

        }

    },
  6. In the resources section
    In the resources section add a comma after the existing resource, directly before the last “]” closing square bracket and then add the resource below.

    {

        "apiVersion": "2015-06-01",

        "name": "[parameters('siteName')]",

        "type": "Microsoft.Web/Sites",

        "location": "[parameters('siteLocation')]",

        "dependsOn": [

        "[concat('Microsoft.Web/serverFarms/', parameters('hostingPlanName'))]"

        ],

        "properties": {

            "name": "[parameters('siteName')]",

            "serverFarmId": "[parameters('hostingPlanName')]"

        }

    }

  7. Save the template
    Save the template.
  8. Click on Resource group
    Click on Resource group and choose “templateRG”, which will fix the location.
  9. Click the Edit parameters link
    Click the Edit parameters link.
  10. For SITENAME, enter
    For SITENAME, enter a globally unique name. Consider using your name plus “-webappARM”, such as “johndoe-webappARM”.
  11. For the HOSTINGPLANNAME
    For the HOSTINGPLANNAME, use “templateASP” – which will fix the location.
  12. For the SITELOCATION
    For the SITELOCATION use the same value you selected for the Resource Group Location which is displayed in the Resource group location link.
  13. Leave the other values alone and press OK
    Leave the other values alone and press OK.
  14. Click on Legal Terms
    Click on Legal Terms and press Purchase to indicate that you agree with the Legal Terms.
  15. Make sure that Pin to dashboard is selected
    Make sure that Pin to dashboard is selected, and the press the Create.It will take a moment for your app service plan to become available.
 Click Continue to advance to the next exercise.

Exercise 3 : Review what you have created

  1. Click the Resource groups
    Click the Resource groups item from the portal’s left menu.
  2. Click your “templateRG” item to open it
    Click your “templateRG” item to open it.
  3. In the Summary section
    The Summary blade lists your App Service Plan and your Web app (App Service). These were the resources that were described by the template. They were created using the values you supplied to the template based on the parameters the template needed.
  4. Click your Web site
    Click your Web site and click the Browse button on the toolbar. Your site opens. It all just works.
  5. What you just created
    What you just created is a template that’s similar to the template used (under the covers) if you had created it from +New | Web + Mobile | Web App.
Click Continue to advance to the next exercise.

Exercise 4 : Create a single App Service Plan, a Web App, a SQL Server, and a SQL Database

  1. Create a new template
    Create a new template (+New, search for “Template deployment”, all the way through the first Create to start creating the template).
  2. Click Edit Template
    Click Edit Template and delete everything that is there.
  3. In a new browser window
    In a new browser window go to https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/201-web-app-sql-database/azuredeploy.json.
  4. Copy the whole content
     Copy the whole content from there and paste it in the Edit template blade.
  5. Save the template
    Save the template and go to the Edit parameters blade.
  6. For ADMINISTRATORLOGIN
    For ADMINISTRATORLOGIN, use name + “admin”, such as “johndoeadmin”. Select a password you can remember.
  7. For DATABASENAME
     For DATABASENAME, we suggest you use name + “-sqldbARM”, such as “johndoe-sqldbARM”.
  8. Press OK
    Press OK.
  9. From the Resource group dropdown
    From the Resource group dropdown, select + New.
  10. Enter “FullArmRG”
    Enter “FullArmRG” as the New resource group location.
  11. Click on Resource group location
    Click on Resource group location and select the same region used in earlier steps.
  12. Click on Legal Terms and press Create
    Click on Legal Terms and press Create to indicate that you agree with the Legal Terms.
  13. Make sure that Pin to dashboard is selected
    Make sure that Pin to dashboard is selected, and the press the Create.
  14. Deployment is created
    After a while, depending on the load on Azure at the time, your deployment is created and a blade with your resource group will be open.
Click Continue to advance to the next exercise.

No comments: