Use Azure cloud ARM Spin up a web application/Sql Server/SQL
Database and storage account in azure within 10 seconds
Early
web developers knows how painful is to set up a web application in IIS and make
it work because IIS behaves crazy when your day is bad. Azure has made the life
of every web application developer's life so easy by creating the web application in
just a few clicks and your website is public
and available to internet user, which is not easy in IIS in any sense. And we
don’t even have to talk about deploying the web application which has a load
balancer.
With
the Presence of ARM – Azure Resource manager,
setting up a Web application, SQL Server, SQL Database and storage manager is
only a configuration JSON and which can be created by the visual
studio as a template, and deployed using visual studio !
You can spin up a new web application (even
VM’s) with any resource (web-app, SQL server etc.) and you can also update the already ARM created resources.
Let us
look out how we can setup a Web application, a SQL Server, SQL Database
and azure storage Account in seconds.
You need to select the Azure Template with WebApp + Sql from
the next window that appear after clicking ok.
Once we click on OK, project is created will have
only three files as below.
Three files are
- Deploy-AzureResourceGroup.ps1
- WebSiteSQLDatabase.json
- WebSiteSQLDatabase.parameters.json
We will look in detail about each and every file and see how
these files helps us to create azure resources stack in matter of seconds.
Deploy-AzureResourceGroup.ps1
This file is used by the visual
studio to create the application in azure and it is nothing but a power shell
script. It runs the command needed to create the application using the JSON, provided
as input. It will be same for any azure resource group project, irrespective of
resource you choose to be deployed.
WebSiteSQLDatabase.parameters.json
This
files contains the parameter that can be used to configure the resources of the
azure, this can be configured to have default values. (Parameters section of WebSiteSQLDatabase.json
file will be configuring the type of parameter used, default values etc.)
Empty Template contains following elements, will look like below.
WebSiteSQLDatabase.json
This
file provides the resources information that needs to be installed in the
cloud, it has own variables that can be used declared and used inside
the JSON file where we don’t want to repeat the logic for creating a string or
any other object that can be reused. For more details about the every element you
refer here
. We will discuss the template further to understand the resources.
Empty Template contains following elements
{
"$schema":
"http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "",
"parameters": { },
"variables": { },
"resources": [ ],
"outputs": { }
}
Every resource will have entry in the resources section and
it will have its own configuration detail. For explanatory purpose, we will
only look into the web application alone. For more details, look into my code repository
in GitHub.
Above JSON explains the web app that will be created from
the above JSON, you can see the variables are set at runtime based on the
parameter value, which can be altered by us in the configuration.
The current template from the visual studio has only
WebApp+SQL, when we need to add one more resource, in our case it is storage
manager, we need to add through the another cool feature in Visual studio
called as JSON Outline.
You can open this window from other window in view menu.
Open the WebsiteSQLDatabase.JSON before opening the JSON Outline.
You can add the storage account by right clicking the
resources in the JSON Outline and selecting ‘Add new resource’. Select the Storage account and name it.
Once we click add the below JSON will be added to the WebSiteSQLDatabase.JSON.
Make sure you provide the name of the storage account in lower case letter.
You are all set with the configurations to create a web application, an SQL Server, an SQL
Database and Azure Storage Account. Will not take more than 2 minutes to
create a solution with these configuration using visual studio.
You can also get lots of pre-existing template that is
already available in GitHub. You
can download any template or refer them to create more resource such as redis
cache, mongo db, spin up a new Linux virtual machine.
You can now deploy the ARM to azure to create the specified
resources.
You will see the deploy to resource group window where we
can Edit Parameters that can be configured for our ARM, which can also be saved
to the WebSiteSQLDatabase.parameters.json
Once you click on the deploy button, you need to watch the
output window because the visual studio does everything at the background while running Power-Shell script.
You can see after couple of minutes when you login into
azure you can see the new resource group that was created as all the specified
resources created automatically.
ARM helps to create scripts to automate the resource creation process in azure cloud so we can do
automate testing, add new web application to the new client it can also deploy
the code automatically to the cloud. You should really try this in azure since
it is the coolest feature in azure.