Skip to content

Commit f88d701

Browse files
authored
Merge pull request #104239 from mumian/0210-deployment-tutorial
add a new tutorial
2 parents b06eac6 + 69e7d9e commit f88d701

17 files changed

+607
-16
lines changed

.openpublishing.redirection.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13638,7 +13638,7 @@
1363813638
"source_path": "articles/event-hubs/event-hubs-tutorial-virtual-networks-firewalls.md",
1363913639
"redirect_url": "/azure/event-hubs/event-hubs-service-endpoints",
1364013640
"redirect_document_id": false
13641-
},
13641+
},
1364213642
{
1364313643
"source_path": "articles/active-directory/active-directory-saml-protocol-reference.md",
1364413644
"redirect_url": "/azure/active-directory/develop/active-directory-saml-protocol-reference",
@@ -17078,7 +17078,7 @@
1707817078
"source_path": "articles/sql-data-warehouse/create-data-warehouse-powershell.md",
1707917079
"redirect_url": "/azure/synapse-analytics/sql-data-warehouse/create-data-warehouse-powershell",
1708017080
"redirect_document_id": true
17081-
},
17081+
},
1708217082
{
1708317083
"source_path": "articles/sql-data-warehouse/viewing-maintenance-schedule.md",
1708417084
"redirect_url": "/azure/sql-data-warehouse/maintenance-scheduling#view-a-maintenance-schedule",
@@ -17173,7 +17173,7 @@
1717317173
"source_path": "articles/sql-data-warehouse/release-notes-10-0-10106-0.md",
1717417174
"redirect_url": "/azure/synapse-analytics/sql-data-warehouse/release-notes-10-0-10106-0",
1717517175
"redirect_document_id": true
17176-
},
17176+
},
1717717177
{
1717817178
"source_path": "articles/sql-data-warehouse/sql-data-warehouse-concept-recommendations.md",
1717917179
"redirect_url": "/azure/synapse-analytics/sql-data-warehouse/sql-data-warehouse-concept-recommendations",
@@ -35209,7 +35209,7 @@
3520935209
"source_path": "articles/multi-factor-authentication/end-user/index.md",
3521035210
"redirect_url": "/azure/multi-factor-authentication/end-user/multi-factor-authentication-end-user",
3521135211
"redirect_document_id": false
35212-
},
35212+
},
3521335213
{
3521435214
"source_path": "articles/notification-hubs/configure-android-device-messaging.md",
3521535215
"redirect_url": "/azure//notification-hubs/configure-google-firebase-cloud-messaging",
@@ -49493,7 +49493,7 @@
4949349493
{
4949449494
"source_path": "articles/cli/index.yml",
4949549495
"redirect_url": "/cli/azure",
49496-
"redirect_document_id": false
49496+
"redirect_document_id": false
4949749497
},
4949849498
{
4949949499
"source_path": "articles/virtual-machines/linux/tutorial-build-deploy-jenkins.md",
@@ -49611,8 +49611,8 @@
4961149611
"redirect_document_id": false
4961249612
},
4961349613
{
49614-
"source_path": "articles/lab-services/classroom-labs/class-type-deep-learning-natural-processing.md",
49615-
"redirect_url": "/azure/lab-services/classroom-labs/class-type-deep-learning-natural-language-processing",
49614+
"source_path": "articles/lab-services/classroom-labs/class-type-deep-learning-natural-processing.md",
49615+
"redirect_url": "/azure/lab-services/classroom-labs/class-type-deep-learning-natural-language-processing",
4961649616
"redirect_document_id": false
4961749617
}
4961849618
]
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
---
2+
title: Tutorial - Deploy a linked template
3+
description: Learn how to deploy a linked template
4+
ms.date: 03/13/2020
5+
ms.topic: tutorial
6+
ms.author: jgao
7+
---
8+
9+
# Tutorial: Deploy a linked template
10+
11+
In the [previous tutorials](./deployment-tutorial-local-template.md), you learned how to deploy a template that is stored in your local computer. To deploy complex solutions, you can break a template into many templates, and deploy these templates through a main template. In this tutorial, you learn how to deploy a main template that contains the reference to a linked template. When the main template gets deployed, it triggers the deployment of the linked template. You also learn how to store and secure the linked template by using SAS token. It takes about **12 minutes** to complete.
12+
13+
## Prerequisites
14+
15+
We recommend that you complete the previous tutorial, but it's not required.
16+
17+
## Review template
18+
19+
In the previous tutorials, you deploy a template that creates a storage account, App Service plan, and web app. The template used was:
20+
21+
:::code language="json" source="~/resourcemanager-templates/get-started-deployment/local-template/azuredeploy.json":::
22+
23+
## Create a linked template
24+
25+
You can separate the storage account resource into a linked template:
26+
27+
:::code language="json" source="~/resourcemanager-templates/get-started-deployment/linked-template/linkedStorageAccount.json":::
28+
29+
The following template is the main template. The highlighted **Microsoft.Resources/deployments** object shows how to call a linked template. The linked template cannot be stored as a local file or a file that is only available on your local network. You can only provide a URI value that includes either *http* or *https*. Resource Manager must be able to access the template. One option is to place your linked template in a storage account, and use the URI for that item. The URI is passed to template using a parameter. See the highlighted parameter definition.
30+
31+
:::code language="json" source="~/resourcemanager-templates/get-started-deployment/linked-template/azuredeploy.json" highlight="27-32,40-58":::
32+
33+
Save a copy of the main template to your local computer with the .json extension, for example, azuredeploy.json. You don't need to save a copy of the linked template. The linked template will be copied from a GitHub repository to a storage account.
34+
35+
## Store the linked template
36+
37+
The following PowerShell script creates a storage account, creates a container, and copies the linked template from a GitHub repository to the container. A copy of the linked template is stored in [GitHub](https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/get-started-deployment/linked-template/linkedStorageAccount.json).
38+
39+
Select **Try-it** to open the Cloud Shell, select **Copy** to copy the PowerShell script, and right-click the shell pane to paste the script:
40+
41+
> [!IMPORTANT]
42+
> Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. The name must be unique. In the template, the storage account name is the project name with "store" appended, and the project name must be between 3 and 11 characters. So the project name must meet the storage account name requirements and has less than 11 characters.
43+
44+
```azurepowershell-interactive
45+
$projectName = Read-Host -Prompt "Enter a project name:" # This name is used to generate names for Azure resources, such as storage account name.
46+
$location = Read-Host -Prompt "Enter a location (i.e. centralus)"
47+
48+
$resourceGroupName = $projectName + "rg"
49+
$storageAccountName = $projectName + "store"
50+
$containerName = "templates" # The name of the Blob container to be created.
51+
52+
$linkedTemplateURL = "https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/get-started-deployment/linked-template/linkedStorageAccount.json" # A completed linked template used in this tutorial.
53+
$fileName = "linkedStorageAccount.json" # A file name used for downloading and uploading the linked template.
54+
55+
# Download the template
56+
Invoke-WebRequest -Uri $linkedTemplateURL -OutFile "$home/$fileName"
57+
58+
# Create a resource group
59+
New-AzResourceGroup -Name $resourceGroupName -Location $location
60+
61+
# Create a storage account
62+
$storageAccount = New-AzStorageAccount `
63+
-ResourceGroupName $resourceGroupName `
64+
-Name $storageAccountName `
65+
-Location $location `
66+
-SkuName "Standard_LRS"
67+
68+
$context = $storageAccount.Context
69+
70+
# Create a container
71+
New-AzStorageContainer -Name $containerName -Context $context -Permission Container
72+
73+
# Upload the template
74+
Set-AzStorageBlobContent `
75+
-Container $containerName `
76+
-File "$home/$fileName" `
77+
-Blob $fileName `
78+
-Context $context
79+
80+
Write-Host "Press [ENTER] to continue ..."
81+
```
82+
83+
## Deploy template
84+
85+
To deploy a private template in a storage account, generate a SAS token and include it in the URI for the template. Set the expiry time to allow enough time to complete the deployment. The blob containing the template is accessible to only the account owner. However, when you create a SAS token for the blob, the blob is accessible to anyone with that URI. If another user intercepts the URI, that user is able to access the template. A SAS token is a good way of limiting access to your templates, but you should not include sensitive data like passwords directly in the template.
86+
87+
If you haven't created the resource group, see [Create resource group](./deployment-tutorial-local-template.md#create-resource-group).
88+
89+
# [PowerShell](#tab/azure-powershell)
90+
91+
```azurepowershell
92+
93+
$projectName = Read-Host -Prompt "Enter a project name:" # This name is used to generate names for Azure resources, such as storage account name.
94+
$templateFile = Read-Host -Prompt "Enter the main template file and path"
95+
96+
$resourceGroupName="${projectName}rg"
97+
$storageAccountName="${projectName}store"
98+
$containerName = "templates"
99+
$fileName = "linkedStorageAccount.json" # A file name used for downloading and uploading the linked template.
100+
101+
$key = (Get-AzStorageAccountKey -ResourceGroupName $resourceGroupName -Name $storageAccountName).Value[0]
102+
$context = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $key
103+
104+
# Generate a SAS token
105+
$linkedTemplateUri = New-AzStorageBlobSASToken `
106+
-Context $context `
107+
-Container $containerName `
108+
-Blob $fileName `
109+
-Permission r `
110+
-ExpiryTime (Get-Date).AddHours(2.0) `
111+
-FullUri
112+
113+
# Deploy the template
114+
New-AzResourceGroupDeployment `
115+
-Name DeployLinkedTemplate `
116+
-ResourceGroupName $resourceGroupName `
117+
-TemplateFile $templateFile `
118+
-projectName $projectName `
119+
-linkedTemplateUri $linkedTemplateUri `
120+
-verbose
121+
```
122+
123+
# [Azure CLI](#tab/azure-cli)
124+
125+
```azurecli
126+
127+
echo "Enter a project name that is used to generate resource names:"
128+
read projectName
129+
echo "Enter the main template file:"
130+
read templateFile
131+
132+
resourceGroupName="${projectName}rg"
133+
storageAccountName="${projectName}store"
134+
containerName="templates"
135+
fileName="linkedStorageAccount.json"
136+
137+
key=$(az storage account keys list -g $resourceGroupName -n $storageAccountName --query [0].value -o tsv)
138+
139+
linkedTemplateUri=$(az storage blob generate-sas \
140+
--account-name $storageAccountName \
141+
--account-key $key \
142+
--container-name $containerName \
143+
--name $fileName \
144+
--permissions r \
145+
--expiry `date -u -d "120 minutes" '+%Y-%m-%dT%H:%MZ'` \
146+
--full-uri)
147+
148+
linkedTemplateUri=$(echo $linkedTemplateUri | sed 's/"//g')
149+
az deployment group create \
150+
--name DeployLinkedTemplate \
151+
--resource-group $resourceGroupName \
152+
--template-file $templateFile \
153+
--parameters projectName=$projectName linkedTemplateUri=$linkedTemplateUri \
154+
--verbose
155+
```
156+
157+
---
158+
159+
## Clean up resources
160+
161+
Clean up the resources you deployed by deleting the resource group.
162+
163+
1. From the Azure portal, select **Resource group** from the left menu.
164+
2. Enter the resource group name in the **Filter by name** field.
165+
3. Select the resource group name.
166+
4. Select **Delete resource group** from the top menu.
167+
168+
## Next steps
169+
170+
You learned how to deploy a linked template. In the next tutorial, you learn how to create a DevOp pipeline to deploy a template.
171+
172+
> [!div class="nextstepaction"]
173+
> [Create a pipeline](./deployment-tutorial-pipeline.md)
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
---
2+
title: Tutorial - Deploy a local Azure Resource Manager template
3+
description: Learn how to deploy an Azure Resource Manager template from your local computer
4+
ms.date: 03/13/2020
5+
ms.topic: tutorial
6+
ms.author: jgao
7+
---
8+
9+
# Tutorial: Deploy a local Azure Resource Manager template
10+
11+
Learn how to deploy an Azure Resource Manager template from your local machine. It takes about **8 minutes** to complete.
12+
13+
This tutorial is the first of a series. As you progress through the series, you modularize the template by creating a linked template, you store the linked template in a storage account, and secure the linked template by using SAS token, and you learn how to create a DevOp pipeline to deploy templates. This series focuses on template deployment. If you want to learn template development, see the [beginner tutorials](./template-tutorial-create-first-template.md).
14+
15+
## Get tools
16+
17+
Let's start by making sure you have the tools you need to deploy templates.
18+
19+
### Command-line deployment
20+
21+
You need either Azure PowerShell or Azure CLI to deploy the template. For the installation instructions, see:
22+
23+
- [Install Azure PowerShell](/powershell/azure/install-az-ps)
24+
- [Install Azure CLI on Windows](/cli/azure/install-azure-cli-windows)
25+
- [Install Azure CLI on Linux](/cli/azure/install-azure-cli-linux)
26+
27+
After installing either Azure PowerShell or Azure CLI, make sure you sign in for the first time. For help, see [Sign in - PowerShell](/powershell/azure/install-az-ps#sign-in) or [Sign in - Azure CLI](/cli/azure/get-started-with-azure-cli#sign-in).
28+
29+
### Editor (Optional)
30+
31+
Templates are JSON files. To review/edit templates, you need a good JSON editor. We recommend Visual Studio Code with the Resource Manager Tools extension. If you need to install these tools, see [Use Visual Studio Code to create Azure Resource Manager templates](use-vs-code-to-create-template.md).
32+
33+
## Review template
34+
35+
The template used in this tutorial is similar to the template used in the [tutorial about Quickstart templates](template-tutorial-quickstart-template.md). If you are interested in creating the template, you can go through that tutorial. However it's not required for completing this tutorial.
36+
37+
The template deploys a storage account, app service plan, and web app.
38+
39+
:::code language="json" source="~/resourcemanager-templates/get-started-deployment/local-template/azuredeploy.json":::
40+
41+
> [!IMPORTANT]
42+
> Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. The name must be unique. In the template, the storage account name is the project name with "store" appended, and the project name must be between 3 and 11 characters. So the project name must meet the storage account name requirements and has less than 11 characters.
43+
44+
Save a copy of the template to your local computer with the .json extension, for example, azuredeploy.json. You deploy this template later in the tutorial.
45+
46+
## Sign in to Azure
47+
48+
To start working with Azure PowerShell/Azure CLI to deploy a template, sign in with your Azure credentials.
49+
50+
# [PowerShell](#tab/azure-powershell)
51+
52+
```azurepowershell
53+
Connect-AzAccount
54+
```
55+
56+
# [Azure CLI](#tab/azure-cli)
57+
58+
```azurecli
59+
az login
60+
```
61+
62+
---
63+
64+
If you have multiple Azure subscriptions, select the subscription you want to use:
65+
66+
# [PowerShell](#tab/azure-powershell)
67+
68+
```azurepowershell
69+
Select-AzSubscription [SubscriptionID/SubscriptionName]
70+
```
71+
72+
# [Azure CLI](#tab/azure-cli)
73+
74+
```azurecli
75+
az account set --subscription [SubscriptionID/SubscriptionName]
76+
```
77+
78+
---
79+
80+
## Create resource group
81+
82+
When you deploy a template, you specify a resource group that will contain the resources. Before running the deployment command, create the resource group with either Azure CLI or Azure PowerShell. Select the tabs in the following code section to choose between Azure PowerShell and Azure CLI. The CLI examples in this article are written for the Bash shell.
83+
84+
# [PowerShell](#tab/azure-powershell)
85+
86+
```azurepowershell
87+
$projectName = Read-Host -Prompt "Enter a project name that is used to generate resource and resource group names"
88+
$resourceGroupName = "${projectName}rg"
89+
90+
New-AzResourceGroup `
91+
-Name $resourceGroupName `
92+
-Location "Central US"
93+
```
94+
95+
# [Azure CLI](#tab/azure-cli)
96+
97+
```azurecli
98+
echo "Enter a project name that is used to generate resource and resource group names:"
99+
read projectName
100+
resourceGroupName="${projectName}rg"
101+
102+
az group create \
103+
--name $resourceGroupName \
104+
--location "Central US"
105+
```
106+
107+
---
108+
109+
## Deploy template
110+
111+
Use one or both deployment options to deploy the template.
112+
113+
# [PowerShell](#tab/azure-powershell)
114+
115+
```azurepowershell
116+
$projectName = Read-Host -Prompt "Enter the same project name"
117+
$templateFile = Read-Host -Prompt "Enter the template file path and file name"
118+
$resourceGroupName = "${projectName}rg"
119+
120+
New-AzResourceGroupDeployment `
121+
-Name DeployLocalTemplate `
122+
-ResourceGroupName $resourceGroupName `
123+
-TemplateFile $templateFile `
124+
-projectName $projectName `
125+
-verbose
126+
```
127+
128+
To learn more about deploying template by using Azure PowerShell, see [Deploy resources with Resource Manager templates and Azure PowerShell](./deploy-powershell.md).
129+
130+
# [Azure CLI](#tab/azure-cli)
131+
132+
```azurecli
133+
echo "Enter the same project name:"
134+
read projectName
135+
echo "Enter the template file path and file name:"
136+
read templateFile
137+
resourceGroupName="${projectName}rg"
138+
139+
az deployment group create \
140+
--name DeployLocalTemplate \
141+
--resource-group $resourceGroupName \
142+
--template-file $templateFile \
143+
--parameters projectName=$projectName \
144+
--verbose
145+
```
146+
147+
To learn more about deploying template by using Azure CLI, see [Deploy resources with Resource Manager templates and Azure CLI](./deploy-cli.md).
148+
149+
---
150+
151+
## Clean up resources
152+
153+
Clean up the resources you deployed by deleting the resource group.
154+
155+
1. From the Azure portal, select **Resource group** from the left menu.
156+
2. Enter the resource group name in the **Filter by name** field.
157+
3. Select the resource group name.
158+
4. Select **Delete resource group** from the top menu.
159+
160+
## Next steps
161+
162+
You learned how to deploy a local template. In the next tutorial, you separate the template into a main template and a linked template, and learn how to store and secure the linked template.
163+
164+
> [!div class="nextstepaction"]
165+
> [Deploy a linked template](./deployment-tutorial-linked-template.md)

0 commit comments

Comments
 (0)