You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-resource-manager/resource-group-template-deploy-cli.md
+60-38Lines changed: 60 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,50 +4,46 @@ description: Use Azure Resource Manager and Azure CLI to deploy a resources to A
4
4
services: azure-resource-manager
5
5
documentationcenter: na
6
6
author: tfitzmac
7
-
manager: timlt
8
-
editor: tysonn
9
7
10
8
ms.assetid: 493b7932-8d1e-4499-912c-26098282ec95
11
9
ms.service: azure-resource-manager
12
10
ms.devlang: azurecli
13
11
ms.topic: conceptual
14
12
ms.tgt_pltfrm: na
15
13
ms.workload: na
16
-
ms.date: 07/31/2017
14
+
ms.date: 08/06/2018
17
15
ms.author: tomfitz
18
16
19
17
---
20
18
# Deploy resources with Resource Manager templates and Azure CLI
21
19
22
-
This article explains how to use Azure CLI with Resource Manager templates to deploy your resources to Azure. If you are not familiar with the concepts of deploying and managing your Azure solutions, see [Azure Resource Manager overview](resource-group-overview.md).
20
+
This article explains how to use Azure CLI with Resource Manager templates to deploy your resources to Azure. If you aren't familiar with the concepts of deploying and managing your Azure solutions, see [Azure Resource Manager overview](resource-group-overview.md).
23
21
24
22
The Resource Manager template you deploy can either be a local file on your machine, or an external file that is located in a repository like GitHub. The template you deploy in this article is available in the [Sample template](#sample-template) section, or as a [storage account template in GitHub](https://github.com/Azure/azure-quickstart-templates/blob/master/101-storage-account-create/azuredeploy.json).
If you do not have Azure CLI installed, you can use the [Cloud Shell](#deploy-template-from-cloud-shell).
26
+
If you don't have Azure CLI installed, you can use the [Cloud Shell](#deploy-template-from-cloud-shell).
29
27
30
28
## Deploy local template
31
29
32
30
When deploying resources to Azure, you:
33
31
34
-
1.Log in to your Azure account
35
-
2. Create a resource group that serves as the container for the deployed resources. The name of the resource group can only include alphanumeric characters, periods, underscores, hyphens, and parenthesis. It can be up to 90 characters. It cannot end in a period.
32
+
1.Sign in to your Azure account
33
+
2. Create a resource group that serves as the container for the deployed resources. The name of the resource group can only include alphanumeric characters, periods, underscores, hyphens, and parenthesis. It can be up to 90 characters. It can't end in a period.
36
34
3. Deploy to the resource group the template that defines the resources to create
37
35
38
36
A template can include parameters that enable you to customize the deployment. For example, you can provide values that are tailored for a particular environment (such as dev, test, and production). The sample template defines a parameter for the storage account SKU.
39
37
40
38
The following example creates a resource group, and deploys a template from your local machine:
41
39
42
-
```azurecli
43
-
az login
44
-
40
+
```azurecli-interactive
45
41
az group create --name ExampleGroup --location "Central US"
46
42
az group deployment create \
47
-
--name ExampleDeployment \
48
-
--resource-group ExampleGroup \
49
-
--template-file storage.json \
50
-
--parameters storageAccountType=Standard_GRS
43
+
--name ExampleDeployment \
44
+
--resource-group ExampleGroup \
45
+
--template-file storage.json \
46
+
--parameters storageAccountType=Standard_GRS
51
47
```
52
48
53
49
The deployment can take a few minutes to complete. When it finishes, you see a message that includes the result:
@@ -62,18 +58,16 @@ Instead of storing Resource Manager templates on your local machine, you may pre
62
58
63
59
To deploy an external template, use the **template-uri** parameter. Use the URI in the example to deploy the sample template from GitHub.
64
60
65
-
```azurecli
66
-
az login
67
-
61
+
```azurecli-interactive
68
62
az group create --name ExampleGroup --location "Central US"
The preceding example requires a publicly accessible URI for the template, which works for most scenarios because your template should not include sensitive data. If you need to specify sensitive data (like an admin password), pass that value as a secure parameter. However, if you do not want your template to be publicly accessible, you can protect it by storing it in a private storage container. For information about deploying a template that requires a shared access signature (SAS) token, see [Deploy private template with SAS token](resource-manager-cli-sas-token.md).
70
+
The preceding example requires a publicly accessible URI for the template, which works for most scenarios because your template shouldn't include sensitive data. If you need to specify sensitive data (like an admin password), pass that value as a secure parameter. However, if you don't want your template to be publicly accessible, you can protect it by storing it in a private storage container. For information about deploying a template that requires a shared access signature (SAS) token, see [Deploy private template with SAS token](resource-manager-cli-sas-token.md).
@@ -90,6 +84,34 @@ az group deployment create --resource-group examplegroup \
90
84
91
85
Typically, you deploy all the resources in your template to a single resource group. However, there are scenarios where you want to deploy a set of resources together but place them in different resource groups or subscriptions. You can deploy to only five resource groups in a single deployment. For more information, see [Deploy Azure resources to more than one subscription or resource group](resource-manager-cross-resource-group-deployment.md).
92
86
87
+
## Redeploy when deployment fails
88
+
89
+
For deployments that fail, you can specify that an earlier deployment from your deployment history is automatically redeployed. To use this option, your deployments must have unique names so they can be identified in the history. If you don't have unique names, the current failed deployment might overwrite the previously successful deployment in the history. You can only use this option with root level deployments. Deployments from a nested template aren't available for redeployment.
90
+
91
+
To redeploy the last successful deployment, add the `--rollback-on-error` parameter as a flag.
92
+
93
+
```azurecli-interactive
94
+
az group deployment create \
95
+
--name ExampleDeployment \
96
+
--resource-group ExampleGroup \
97
+
--template-file storage.json \
98
+
--parameters storageAccountType=Standard_GRS \
99
+
--rollback-on-error
100
+
```
101
+
102
+
To redeploy a specific deployment, use the `--rollback-on-error` parameter and provide the name of the deployment.
103
+
104
+
```azurecli-interactive
105
+
az group deployment create \
106
+
--name ExampleDeployment02 \
107
+
--resource-group ExampleGroup \
108
+
--template-file storage.json \
109
+
--parameters storageAccountType=Standard_GRS \
110
+
--rollback-on-error ExampleDeployment01
111
+
```
112
+
113
+
The specified deployment must have succeeded.
114
+
93
115
## Parameter files
94
116
95
117
Rather than passing parameters as inline values in your script, you may find it easier to use a JSON file that contains the parameter values. The parameter file must be in the following format:
@@ -112,23 +134,23 @@ Copy the preceding example and save it as a file named `storage.parameters.json`
112
134
113
135
To pass a local parameter file, use `@` to specify a local file named storage.parameters.json.
114
136
115
-
```azurecli
137
+
```azurecli-interactive
116
138
az group deployment create \
117
-
--name ExampleDeployment \
118
-
--resource-group ExampleGroup \
119
-
--template-file storage.json \
120
-
--parameters @storage.parameters.json
139
+
--name ExampleDeployment \
140
+
--resource-group ExampleGroup \
141
+
--template-file storage.json \
142
+
--parameters @storage.parameters.json
121
143
```
122
144
123
145
## Test a template deployment
124
146
125
147
To test your template and parameter values without actually deploying any resources, use [az group deployment validate](/cli/azure/group/deployment#az-group-deployment-validate).
126
148
127
-
```azurecli
149
+
```azurecli-interactive
128
150
az group deployment validate \
129
-
--resource-group ExampleGroup \
130
-
--template-file storage.json \
131
-
--parameters @storage.parameters.json
151
+
--resource-group ExampleGroup \
152
+
--template-file storage.json \
153
+
--parameters @storage.parameters.json
132
154
```
133
155
134
156
If no errors are detected, the command returns information about the test deployment. In particular, notice that the **error** value is null.
@@ -156,7 +178,7 @@ If an error is detected, the command returns an error message. For example, atte
156
178
}
157
179
```
158
180
159
-
If your template has a syntax error, the command returns an error indicating it could not parse the template. The message indicates the line number and position of the parsing error.
181
+
If your template has a syntax error, the command returns an error indicating it couldn't parse the template. The message indicates the line number and position of the parsing error.
160
182
161
183
```azurecli
162
184
{
@@ -175,13 +197,13 @@ If your template has a syntax error, the command returns an error indicating it
0 commit comments