Maximize the benefits of using Resource Manager
Microsoft
has several suggestions to help you maximize the use of the Resource Manager
model when working with your applications and components.
Use templates rather than using scripting like PowerShell or the Azure
Command-Line Interface (CLI). Using a template allows resources to be deployed
in parallel, making it much faster than using a script executed sequentially.
Automate as much as possible by leveraging templates. You can include
configurations for various extensions like PowerShell DSC and Web Deploy. This
way, you don’t need any manual steps to create and configure the resources.
Use
PowerShell or the Azure CLI to manage the resources, such as to start or stop a
virtual machine or application.
Put resources with
the same lifecycle in the same resource group. In our example above, what if
the database is used by multiple applications? If that’s true, or if the
database is going to live on even after the application is retired or removed,
you don’t want to re-create the database every time you redeploy the
application and its components. In that case, put the database in its own
resource group.
Resource
group tips
You can decide how to
allocate your resources to resource groups based on what makes sense for you
and your organization. A resource group is a logical container to hold related
resources for an application or group of applications. These tips should be
considered when making decisions about your resource group:
As noted before, all of the resources in a group should have the
same lifecycle.
A resource can only be assigned to one group at a time.
A resource can be
added to or removed from a resource group at any time. Note that every resource
must belong to a resource
group,
so if you remove it from one group, you have to add it to another.
Most types of resource can be moved to a different resource group at any time.
The resources in a resource group can be in different regions.
You can
use a resource group to control access for the resources therein.
Tips for
using Resource Manager templates
Resource
Manager templates define the deployment and configuration of your application.
They are used to deploy an application and all of its component resources
repeatedly.
You can
divide the deployments in a set of templates and create a master template that
links in all of the required templates.
Templates
can be modified and redeployed with updates. For example, you can add a new
resource or update configuration information about a resource in a template.
When deployed again, Resource Manager will create any newresources it finds and
perform updates for any that have been changed. You will see this in Chapter 5,
“Azure Virtual Networks,” where you deploy a template defining a VNet with two
subnets. Then, you add a third subnet and redeploy the template, and you can
see the third subnet appear in the Azure portal.
Templates
can be parameterized to allow you more flexibility in deployment. This is what
allows you to use the same template repeatedly but with different values, such
as VM name, virtual network name, storage account name, region, and so on.
You can
export the current state of the resources in a resource group to a template.
This can then be used as a pattern for other deployments, or it can be edited
and redeployed to make changes and additions to the current resource group’s
resources.
Here is an example of a JSON template. Deploying
this template will create a storage account in West US called mystorage. This
is parameterized; you can include a parameter file that provides the values for
newStorageAccountName and location. Otherwise, it will use the defaults.
{
"$schema":
"http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion":
"1.0.0.0",
"parameters":
{
"newStorageAccountName":
{
"type":
"string",
"defaultValue":
"mystorage",
"metadata":
{
"description":
"Unique DNS Name for the Storage Account where the Virtual Machine's disks
will be placed."
}
},
"location":
{
"type":
"string",
"defaultValue":
"West US",
"allowedValues":
[
"West US",
"East US"
],
"metadata":
{"description": "Restricts choices to where premium storage is
located in the US."
}
}
},
"resources":
[
{
"type":
"Microsoft.Storage/storageAccounts",
"name":
"[parameters('newStorageAccountName')]",
"apiVersion":
"2015-06-15",
"location":
"[parameters('location')]",
"properties":
{
"accountType":
"Standard_LRS"
}
}
]
}
