145
CHAPTER 5 | Azure Virtual Networks
Figure 5-8 Search for template deployment.
2.
In
the search results, click Template Deployment. This shows the Template Deployment blade that
gives a brief explanation of what it is. Click Create. This shows the Custom Deployment blade
shown in Figure 5-9.
Figure 5-9 The Custom Deployment blade.
146
CHAPTER 5 | Azure Virtual Networks
3.
Click Edit Template. This shows the template editor. Copy the template JSON that you want to use
from a text editor and paste it
into the template editor, replacing everything that’s there. You see
something like Figure 5-10.
Figure 5-10 The Edit Template blade.
4.
Click Save. If there are no parsing errors in your template, it returns to the Custom Deployment
blade. If you have parameters, the Azure portal marks that option with an error symbol. You must
click Edit Parameters and verify the values of the parameters. You can change them from the
defaults here if desired.
5.
On the Custom Deployment blade, verify the subscription selected is correct
and then select
Create New under Resource Group and provide a name. As you can see back in Figure 5-9, our
example uses AzureBookVnetRG.
6.
Set the location of the Resource Group. Although not required, it’s best to specify the same Azure
region that will be used for the resources when they are created.
7.
Next, click Review Legal Terms. After reading the legal terms as carefully as you read all legal
terms, click Purchase to indicate that you understand you are creating resources in Azure and will
have to pay for them.
8.
Click Create. The Azure portal will now verify the template, create your new resource group, and
then create your virtual network in that resource group.
9.
When it’s finished, select it from the Dashboard if it’s there, or select All
Resources and then select
your new VNet. It will open the Virtual Network blade. If you click Subnets in the Settings blade,
you see your two subnets.
That’s grand, but what if you want to add another subnet or change something about this
deployment? You can edit the template and deploy it again. By default, the Azure Resource Manager
treats deployments as incremental updates to the resource group. Here are the rules:
147
CHAPTER 5 | Azure Virtual Networks
If you remove a resource from the template that is not in the resource group, that resource will be
unchanged. It won’t be removed simply because it’s gone from the template. (If you want to
remove a resource, you have to specifically remove
it using the Azure portal, PowerShell, the
Azure CLI, etc.)
If you add a resource to the template that is not in the resource group, it will create that resource
for you when you redeploy the template.
Resources that are unchanged but are still in the template will be ignored.
Resources that are changed and still in the template will be updated. For example, if we change
the address prefixes of our virtual network and redeploy the template,
it will change them in the
deployed VNet.
This means you can repeatedly edit a template and add or change a section, and when you redeploy
it, it applies the changes and ignores the current (unchanged) specs for the other resources.
If you use PowerShell, you can also do a complete deployment, which
does delete resources that are
in the resource group but not in the template when you redeploy. You can’t
do complete
deployments through the Azure portal. It’s safer to delete the resource group yourself (and verify that
that’s what you want to do) than to request a complete deployment. What if you accidentally remove
a section from your template? It will remove that resource, and you can’t recover it. If you’re not
convinced that it’s dangerous, think about the consequences if you accidentally remove a storage
account in which you’ve already stored data. Ouch.
Now you can try out this theory of adding something and seeing it be deployed with the existing
resources. Let’s add a third subnet to the template and redeploy it.
1.
Edit the template. Assuming you used the template given before, copy the sections for subnet2
and paste them after subnet2 and change the “subnet2” to “subnet3.”
Also change the address
prefix and the name of the subnet. You should have something like this right after subnet2Name
in the template I posted above:
"subnet3Prefix": {
"type": "string",
"defaultValue": "192.168.40.0/24",
"metadata": {
"description": "Subnet 3 Prefix"
}
},
"subnet3Name": {
"type": "string",
"defaultValue": "SubnetThree",
"metadata": {
"description": "Subnet 3 Name"
}
}
And in the bottom half, under resources, add a resource for subnet3.
{
"name": "[parameters('subnet3Name')]",
"properties": {
148
CHAPTER 5 | Azure Virtual Networks
"addressPrefix": "[parameters('subnet3Prefix')]"
}
}
(Don’t forget the commas after the entry just above these as you add them.)
Do'stlaringiz bilan baham: