Skip to content

Commit 46c4f51

Browse files
authored
Merge pull request #48346 from tfitzmac/0806onerror
added rollback
2 parents 22d261e + 346a91a commit 46c4f51

File tree

1 file changed

+60
-38
lines changed

1 file changed

+60
-38
lines changed

articles/azure-resource-manager/resource-group-template-deploy-cli.md

Lines changed: 60 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,46 @@ description: Use Azure Resource Manager and Azure CLI to deploy a resources to A
44
services: azure-resource-manager
55
documentationcenter: na
66
author: tfitzmac
7-
manager: timlt
8-
editor: tysonn
97

108
ms.assetid: 493b7932-8d1e-4499-912c-26098282ec95
119
ms.service: azure-resource-manager
1210
ms.devlang: azurecli
1311
ms.topic: conceptual
1412
ms.tgt_pltfrm: na
1513
ms.workload: na
16-
ms.date: 07/31/2017
14+
ms.date: 08/06/2018
1715
ms.author: tomfitz
1816

1917
---
2018
# Deploy resources with Resource Manager templates and Azure CLI
2119

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).
2321

2422
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).
2523

2624
[!INCLUDE [sample-cli-install](../../includes/sample-cli-install.md)]
2725

28-
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).
2927

3028
## Deploy local template
3129

3230
When deploying resources to Azure, you:
3331

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.
3634
3. Deploy to the resource group the template that defines the resources to create
3735

3836
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.
3937

4038
The following example creates a resource group, and deploys a template from your local machine:
4139

42-
```azurecli
43-
az login
44-
40+
```azurecli-interactive
4541
az group create --name ExampleGroup --location "Central US"
4642
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
5147
```
5248

5349
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
6258

6359
To deploy an external template, use the **template-uri** parameter. Use the URI in the example to deploy the sample template from GitHub.
6460

65-
```azurecli
66-
az login
67-
61+
```azurecli-interactive
6862
az group create --name ExampleGroup --location "Central US"
6963
az group deployment create \
70-
--name ExampleDeployment \
71-
--resource-group ExampleGroup \
72-
--template-uri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-storage-account-create/azuredeploy.json" \
73-
--parameters storageAccountType=Standard_GRS
64+
--name ExampleDeployment \
65+
--resource-group ExampleGroup \
66+
--template-uri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-storage-account-create/azuredeploy.json" \
67+
--parameters storageAccountType=Standard_GRS
7468
```
7569

76-
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).
7771

7872
[!INCLUDE [resource-manager-cloud-shell-deploy.md](../../includes/resource-manager-cloud-shell-deploy.md)]
7973

@@ -90,6 +84,34 @@ az group deployment create --resource-group examplegroup \
9084

9185
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).
9286

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+
93115
## Parameter files
94116

95117
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`
112134

113135
To pass a local parameter file, use `@` to specify a local file named storage.parameters.json.
114136

115-
```azurecli
137+
```azurecli-interactive
116138
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
121143
```
122144

123145
## Test a template deployment
124146

125147
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).
126148

127-
```azurecli
149+
```azurecli-interactive
128150
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
132154
```
133155

134156
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
156178
}
157179
```
158180

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.
160182

161183
```azurecli
162184
{
@@ -175,13 +197,13 @@ If your template has a syntax error, the command returns an error indicating it
175197

176198
To use complete mode, use the `mode` parameter:
177199

178-
```azurecli
200+
```azurecli-interactive
179201
az group deployment create \
180-
--name ExampleDeployment \
181-
--mode Complete \
182-
--resource-group ExampleGroup \
183-
--template-file storage.json \
184-
--parameters storageAccountType=Standard_GRS
202+
--name ExampleDeployment \
203+
--mode Complete \
204+
--resource-group ExampleGroup \
205+
--template-file storage.json \
206+
--parameters storageAccountType=Standard_GRS
185207
```
186208

187209
## Sample template

0 commit comments

Comments
 (0)