Deploy Web App Around the World Using #ARM

From today’s blog post I’ll walk through how to deploy an azure web application in different azure data center using an ARM (Azure Resource Manager) template.Azure ARM is the new deployment model introduce by Microsoft for resource deployment. It uses JSON to store the resource data and configuration.

How we do it?

  • Create ARM template.
    For create an ARM template we can use any text editor as your prefer here I used VS 2015 because it has more features than other text editors.
  • Create a Web Service Plan.
  • Create a Web App in each Web Service Plan.
  • Create Azure Traffic Manager to maintain high availability of web apps.
  • Use a PowerShell Script to deploy it.

Create a new JSON file in VS.

Open the Visual Studio or any prefered code editor, in this I’ll show how to create JSON file using VS.

File–> New–> File 

Animation

Then it opens another window then search for JSON click open.

Capture

Next you have to add the ARM schema that requires to create ARM template.

 Create a Web Service Plan

In VS we can use JSON Outline to add resources by doing this VS do the hard part by adding relevant code snippets. We just want to change the relevant code parts as per our environment.

create app service plan

Following is the code for creating Web Service Plan.

<br />
    {<br />
      &quot;name&quot;: &quot;[concat(parameters('webAppNamePrefix'),'-farm',copyIndex())]&quot;,<br />
      &quot;type&quot;: &quot;Microsoft.Web/serverfarms&quot;,<br />
      &quot;location&quot;: &quot;[parameters('webAppLocations')[copyIndex()]]&quot;,<br />
      &quot;apiVersion&quot;: &quot;2014-06-01&quot;,<br />
      &quot;dependsOn&quot;: [ ],<br />
      &quot;copy&quot;: {<br />
        &quot;count&quot;: &quot;[length(parameters('webAppLocations'))]&quot;,<br />
        &quot;name&quot;: &quot;farmCopy&quot;<br />
      },<br />
      &quot;tags&quot;: {<br />
        &quot;displayName&quot;: &quot;[concat(parameters('webAppNamePrefix'),'-farm',copyIndex())]&quot;<br />
      },<br />
      &quot;properties&quot;: {<br />
        &quot;name&quot;: &quot;[concat(parameters('webAppNamePrefix'),'-farm',copyIndex())]&quot;,<br />
        &quot;sku&quot;: &quot;[parameters('farmSKU')]&quot;,<br />
        &quot;workerSize&quot;: &quot;[parameters('farmWorkerSize')]&quot;,<br />
        &quot;numberOfWorkers&quot;: 1<br />
      }<br />
    },</p>
<p>

Create a Web Apps

To create the web site I added following code snippets to end of the web app plan code. IF you use VS JSON Outline to add web site resource it will add a variable to variables section in the template.

<br />
        {<br />
      &quot;name&quot;: &quot;[concat(parameters('webAppNamePrefix'),'-webapp',copyIndex())]&quot;,<br />
      &quot;type&quot;: &quot;Microsoft.Web/sites&quot;,<br />
      &quot;location&quot;: &quot;[parameters('webAppLocations')[copyIndex()]]&quot;,<br />
      &quot;apiVersion&quot;: &quot;2015-08-01&quot;,<br />
      &quot;copy&quot;: {<br />
        &quot;count&quot;: &quot;[length(parameters('webAppLocations'))]&quot;,<br />
        &quot;name&quot;: &quot;siteCopy&quot;<br />
      },<br />
      &quot;dependsOn&quot;: [<br />
        &quot;farmCopy&quot;<br />
      ],<br />
      &quot;tags&quot;: {<br />
        &quot;[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', concat(parameters('webAppNamePrefix'),'-farm',0))]&quot;: &quot;Resource&quot;,<br />
        &quot;displayName&quot;: &quot;[concat(parameters('webAppNamePrefix'),'-farm',copyIndex())]&quot;<br />
      },<br />
      &quot;properties&quot;: {<br />
        &quot;name&quot;: &quot;[concat(parameters('webAppNamePrefix'),'-webapp',copyIndex())]&quot;,<br />
        &quot;serverFarmId&quot;: &quot;[resourceId('Microsoft.Web/serverfarms/', concat(parameters('webAppNamePrefix'),'-farm',copyIndex()))]&quot;<br />
      }</p>
<p>

Create Azure Traffic Manager

Added following code snippets to  create traffic manager. We can’t add the traffic manger using JSON Outline so because of that we had to code it.

<br />
    {<br />
      &quot;type&quot;: &quot;Microsoft.Network/trafficManagerProfiles&quot;,<br />
      &quot;name&quot;: &quot;[concat(parameters('webAppNamePrefix'),'-tm')]&quot;,<br />
      &quot;apiVersion&quot;: &quot;2015-11-01&quot;,<br />
      &quot;location&quot;: &quot;global&quot;,<br />
      &quot;dependsOn&quot;: [<br />
        &quot;siteCopy&quot;<br />
      ],</p>
<p>      &quot;properties&quot;: {<br />
        &quot;profileStatus&quot;: &quot;Enabled&quot;,<br />
        &quot;trafficRoutingMethod&quot;: &quot;Performance&quot;,<br />
        &quot;dnsConfig&quot;: {<br />
          &quot;relativeName&quot;: &quot;[concat(parameters('webAppNamePrefix'),'-tm')]&quot;,<br />
          &quot;ttl&quot;: 30<br />
        },<br />
        &quot;monitorConfig&quot;: {<br />
          &quot;protocol&quot;: &quot;HTTP&quot;,<br />
          &quot;port&quot;: 80,<br />
          &quot;path&quot;: &quot;/&quot;<br />
        },</p>
<p>        &quot;endpoints&quot;: [<br />
          {<br />
            &quot;name&quot;: &quot;[concat(parameters('webAppNamePrefix'),'-endpoint','0')]&quot;,<br />
            &quot;type&quot;: &quot;Microsoft.Network/trafficManagerProfiles/azureEndpoints&quot;,<br />
            &quot;properties&quot;: {<br />
              &quot;targetResourceId&quot;: &quot;[resourceId('Microsoft.Web/sites/',concat(parameters('webAppNamePrefix'),'-webapp','0'))]&quot;,<br />
              &quot;endpointStatus&quot;: &quot;Enabled&quot;<br />
            }<br />
          },<br />
          {<br />
            &quot;name&quot;: &quot;[concat(parameters('webAppNamePrefix'),'-endpoint','1')]&quot;,<br />
            &quot;type&quot;: &quot;Microsoft.Network/trafficManagerProfiles/azureEndpoints&quot;,<br />
            &quot;properties&quot;: {<br />
              &quot;targetResourceId&quot;: &quot;[resourceId('Microsoft.Web/sites/',concat(parameters('webAppNamePrefix'),'-webapp','1'))]&quot;,<br />
              &quot;endpointStatus&quot;: &quot;Enabled&quot;<br />
            }<br />
          },<br />
          {<br />
            &quot;name&quot;: &quot;[concat(parameters('webAppNamePrefix'),'-endpoint','2')]&quot;,<br />
            &quot;type&quot;: &quot;Microsoft.Network/trafficManagerProfiles/azureEndpoints&quot;,<br />
            &quot;properties&quot;: {<br />
              &quot;targetResourceId&quot;: &quot;[resourceId('Microsoft.Web/sites/',concat(parameters('webAppNamePrefix'),'-webapp','2'))]&quot;,<br />
              &quot;endpointStatus&quot;: &quot;Enabled&quot;<br />
            }<br />
          },<br />
          {<br />
            &quot;name&quot;: &quot;[concat(parameters('webAppNamePrefix'),'-endpoint','3')]&quot;,<br />
            &quot;type&quot;: &quot;Microsoft.Network/trafficManagerProfiles/azureEndpoints&quot;,<br />
            &quot;properties&quot;: {<br />
              &quot;targetResourceId&quot;: &quot;[resourceId('Microsoft.Web/sites/',concat(parameters('webAppNamePrefix'),'-webapp','3'))]&quot;,<br />
              &quot;endpointStatus&quot;: &quot;Enabled&quot;<br />
            }<br />
          }<br />
        ]<br />
      }</p>
<p>    }<br />

So we added all the components to the ARM template now lets deploy it using a PowerShell Script.

You can get the full code from here.

Deploy ARM template using PowerShell

To do this I created a PowerShell script. Following is the script.

</p>
<p># Define variables</p>
<p>$location = 'southeastasia'<br />
$resourceGroupName = 'webapps-arm'<br />
$resourceDeploymentName = 'webapps-arm-paas'<br />
$templatePath = 'F:EducationBITGitHubARM-TemplatesPaaSWeb App'<br />
$templateFile = 'pass-arm.json'<br />
$template = $templatePath + '' + $templateFile</p>
<p># Create Resource Group<br />
New-AzureRmResourceGroup `<br />
-Name $resourceGroupName `<br />
-Location $Location `<br />
-Verbose -Force</p>
<p># Deploy Resources<br />
New-AzureRmResourceGroupDeployment `<br />
-Name $resourceDeploymentName `<br />
-ResourceGroupName $resourceGroupName `<br />
-TemplateFile $template `<br />
-Verbose -Force</p>
<p>

after you run this PS script you will prompt a verbose as follows.

sucessed

 

When you look in to azure portal you will see the resources are deployed successfully.

Azure resources

Additional Resources

 Building Azure Resource Manager Templates – The Basics

Cloud Consistency with Azure Resource Manager

Azure Quickstart Templates

, , , ,

Post navigation