Skip to content

Commit dad3f37

Browse files
committed
revise the linked template cli script
1 parent 7a85a95 commit dad3f37

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

articles/azure-resource-manager/templates/deployment-tutorial-linked-template.md

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ In the [previous tutorials](./deployment-tutorial-local-template.md), you learne
1212

1313
## Prerequisites
1414

15-
We recommend that you complete the first tutorial, but it's not required.
15+
We recommend that you complete the previous tutorial, but it's not required.
1616

1717
## Review template
1818

@@ -34,7 +34,7 @@ Save a copy of the main template to your local computer.
3434

3535
## Store the linked template
3636

37-
The following PowerShell script creates a storage account, creates a container, copies the linked template from a github repository to the container. At the end of the execution, the script returns the URI of the linked template. You will pass the value as a parameter when you deploy the main template.
37+
The following PowerShell script creates a storage account, creates a container, copies the linked template from a github repository to the container. \
3838

3939
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:
4040

@@ -74,35 +74,26 @@ Set-AzStorageBlobContent `
7474
-Blob $fileName `
7575
-Context $context
7676
77-
# Generate a SAS token
78-
$templateURI = New-AzStorageBlobSASToken `
79-
-Context $context `
77+
# List the template
78+
Get-AzStorageBlob `
8079
-Container $containerName `
81-
-Blob $fileName `
82-
-Permission r `
83-
-ExpiryTime (Get-Date).AddHours(8.0) `
84-
-FullUri
80+
-Blob $fileName
8581
86-
Write-Host "You need the following values later in the tutorial:"
87-
Write-Host "Resource Group Name: $resourceGroupName"
88-
Write-Host "Linked template URI with SAS token: $templateURI"
8982
Write-Host "Press [ENTER] to continue ..."
9083
```
9184

92-
Make a note of the linked template URI. The SAS token is embedded in the URL.
93-
9485
## Deploy template
9586

96-
Use either Azure CLI or Azure PowerShell to deploy the template.
87+
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.
9788

98-
If you haven't created the resource group, see [Create resource group](template-tutorial-create-first-template.md#create-resource-group). The example assumes you've set the **templateFile** variable to the path to the template file, as shown in the [first tutorial](./deployment-tutorial-local-template.md#deploy-template).
89+
If you haven't created the resource group, see [Create resource group](deployment-tutorial-linked-template.md#create-resource-group).
9990

10091
# [PowerShell](#tab/azure-powershell)
10192

10293
```azurepowershell
10394
10495
$projectName = Read-Host -Prompt "Enter a project name:" # This name is used to generate names for Azure resources, such as storage account name.
105-
$templateFile = Read-Host -Prompt "Enter the main template file"
96+
$templateFile = Read-Host -Prompt "Enter the main template file and path"
10697
10798
$resourceGroupName = $projectName + "rg"
10899
$storageAccountName = $projectName + "store"
@@ -121,14 +112,16 @@ $linkedTemplateUri = New-AzStorageBlobSASToken `
121112
-ExpiryTime (Get-Date).AddHours(2.0) `
122113
-FullUri
123114
124-
115+
# Deploy the template
125116
New-AzResourceGroupDeployment `
126117
-Name DeployLinkedTemplate `
127118
-ResourceGroupName $resourceGroupName `
128119
-TemplateUri $templateUri `
129120
-projectName $projectName `
130121
-linkedTemplateUri $linkedTemplateUri `
131122
-verbose
123+
124+
Write-Host "Press [ENTER] to continue ..."
132125
```
133126

134127
# [Azure CLI](#tab/azure-cli)
@@ -139,8 +132,23 @@ echo "Enter a project name that is used to generate resource names:"
139132
read projectName
140133
echo "Enter the main template file:"
141134
read templateFile
142-
echo "Enter the linked template URI:"
143-
read linkedTemplateUri
135+
136+
resourceGroupName="${projectName}rg"
137+
storageAccountName="${projectName}store"
138+
containerName = "templates"
139+
fileName="linkedStorageAccount.json"
140+
141+
key=$(az storage account keys list -g $resourceGroupName -n $storageAccountName --query [0].value -o tsv)
142+
143+
linkedTemplateUri=$(az storage blob generate-sas \
144+
--account-name $storageAccountName \
145+
--account-key $key \
146+
--container-name $containerName \
147+
--name $fileName \
148+
--permissions r \
149+
--expiry `date -u -d "120 minutes" '+%Y-%m-%dT%H:%MZ'` \
150+
--full-uri)
151+
144152
145153
az deployment group create \
146154
--name DeployLinkedTemplate \

0 commit comments

Comments
 (0)