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
{{ message }}
This repository was archived by the owner on Jan 21, 2026. It is now read-only.
Copy file name to clipboardExpand all lines: Instructions/Labs/AZ400_M06_L12_Azure_Deployments_Using_Resource_Manager_Templates.md
+85-26Lines changed: 85 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,21 +41,21 @@ In this exercise, you will set up the prerequisites for the lab, which consist o
41
41
42
42
#### Task 1: (skip if done) Create and configure the team project
43
43
44
-
In this task, you will create an **eShopOnWeb_BicepYAML** Azure DevOps project to be used by several labs.
44
+
In this task, you will create an **eShopOnWeb** Azure DevOps project to be used by several labs.
45
45
46
-
1. On your lab computer, in a browser window open your Azure DevOps organization. Click on **New Project**. Give your project the name **eShopOnWeb_BicepYAML** and leave the other fields with defaults. Click on **Create**.
46
+
1. On your lab computer, in a browser window open your Azure DevOps organization. Click on **New Project**. Give your project the name **eShopOnWeb** and leave the other fields with defaults. Click on **Create**.
47
47
48
48

49
49
50
50
#### Task 2: (skip if done) Import eShopOnWeb Git Repository
51
51
52
52
In this task you will import the eShopOnWeb Git repository that will be used by several labs.
53
53
54
-
1. On your lab computer, in a browser window open your Azure DevOps organization and the previously created **eShopOnWeb_BicepYAML** project. Click on **Repos>Files** , **Import a Repository**. Select **Import**. On the **Import a Git Repository** window, paste the following URL https://github.com/MicrosoftLearning/eShopOnWeb.git and click **Import**:
54
+
1. On your lab computer, in a browser window open your Azure DevOps organization and the previously created **eShopOnWeb** project. Click on **Repos>Files** , **Import a Repository**. Select **Import**. On the **Import a Git Repository** window, paste the following URL https://github.com/MicrosoftLearning/eShopOnWeb.git and click **Import**:
2. Review the template to get a better understanding of its structure. There are some parameters with types, default values and validation, some variables, and quite a few resources with these types:
77
+
1. Review the template to get a better understanding of its structure. There are some parameters with types, default values and validation, some variables, and quite a few resources with these types:
78
78
79
79
- Microsoft.Storage/storageAccounts
80
80
- Microsoft.Network/publicIPAddresses
81
81
- Microsoft.Network/virtualNetworks
82
82
- Microsoft.Network/networkInterfaces
83
83
- Microsoft.Compute/virtualMachines
84
84
85
-
3. Pay attention to how simple the resource definitions are and the ability to implicitly reference symbolic names instead of explicit `dependsOn` throughout the template.
85
+
1. Pay attention to how simple the resource definitions are and the ability to implicitly reference symbolic names instead of explicit `dependsOn` throughout the template.
86
86
87
87
#### Task 2: Create a bicep module for storage resources
88
88
@@ -92,7 +92,7 @@ In this task, you will create a storage template module **storage.bicep** which
@@ -105,15 +105,15 @@ In this task, you will create a storage template module **storage.bicep** which
105
105
}
106
106
```
107
107
108
-
3. Commit the file, however, we're not done with it yet.
108
+
1. Commit the file, however, we're not done with it yet.
109
109
110
110

111
111
112
-
4. Next, hover your mouse over the bicep folder and click the ellipsis icon, then select **New**, and **File**. Enter **storage.bicep** for the name and click **Create**.
112
+
1. Next, hover your mouse over the bicep folder and click the ellipsis icon, then select **New**, and **File**. Enter **storage.bicep** for the name and click **Create**.
113
113
114
114

115
115
116
-
5. Now copy the following code snippet into the file and commit your changes:
116
+
1. Now copy the following code snippet into the file and commit your changes:
117
117
118
118
```bicep
119
119
@description('Location for all resources.')
@@ -140,7 +140,7 @@ In this task, you will modify the main template to reference the template module
140
140
141
141
1. Navigate back to the `simple-windows-vm.bicep` file and click on the **Edit** button once again.
142
142
143
-
2. Next, add the following code after the variables:
143
+
1. Next, add the following code after the variables:
144
144
145
145
```bicep
146
146
module storageModule './storage.bicep' = {
@@ -152,7 +152,7 @@ In this task, you will modify the main template to reference the template module
152
152
}
153
153
```
154
154
155
-
3. We also need to modify the reference to the storage account blob URI in our virtual machine resource to use the output of the module instead. Find the virtual machine resource and replace the diagnosticsProfile section with the following:
155
+
1. We also need to modify the reference to the storage account blob URI in our virtual machine resource to use the output of the module instead. Find the virtual machine resource and replace the diagnosticsProfile section with the following:
156
156
157
157
```bicep
158
158
diagnosticsProfile: {
@@ -163,44 +163,103 @@ In this task, you will modify the main template to reference the template module
163
163
}
164
164
```
165
165
166
-
4. Review the following details in the main template:
166
+
1. Review the following details in the main template:
167
167
168
168
- A module in the main template is used to link to another template.
169
169
- The module has a symbolic name called `storageModule`. This name is used for configuring any dependencies.
170
170
- You can only use **Incremental** deployment mode when using template modules.
171
171
- A relative path is used for your template module.
172
172
- Use parameters to pass values from the main template to the template modules.
173
173
174
-
5. Commit the template.
174
+
1. Commit the template.
175
175
176
-
#### Task 4: Deploy resources to Azure by YAML pipelines
176
+
###Exercise 2: Deploying the templates to Azure using YAML pipelines
177
177
178
+
In this lab, you will create a service connection and use it in an Azure DevOps YAML pipeline to deploy your template to your Azure environment.
179
+
180
+
#### Task 1: (skip if done) Create a Service Connection for deployment
181
+
182
+
In this task, you will create a Service Principal by using the Azure CLI, which will allow Azure DevOps to:
183
+
184
+
- Deploy resources on your Azure subscription.
185
+
- Have read access on the later created Key Vault secrets.
186
+
187
+
> **Note**: If you do already have a Service Principal, you can proceed directly to the next task.
188
+
189
+
You will need a Service Principal to deploy Azure resources from Azure Pipelines. Since we are going to retrieve secrets in a pipeline, we will need to grant permission to the service when we create the Azure Key Vault.
190
+
191
+
A Service Principal is automatically created by Azure Pipelines, when you connect to an Azure subscription from inside a pipeline definition or when you create a new Service Connection from the project settings page (automatic option). You can also manually create the Service Principal from the portal or using Azure CLI and re-use it across projects.
192
+
193
+
1. From the lab computer, start a web browser, navigate to the [**Azure Portal**](https://portal.azure.com), and sign in with the user account that has the Owner role in the Azure subscription you will be using in this lab and has the role of the Global Administrator in the Azure AD tenant associated with this subscription.
194
+
1. In the Azure portal, click on the **Cloud Shell** icon, located directly to the right of the search textbox at the top of the page.
195
+
1. If prompted to select either **Bash** or **PowerShell**, select **Bash**.
196
+
197
+
>**Note**: If this is the first time you are starting **Cloud Shell** and you are presented with the **You have no storage mounted** message, select the subscription you are using in this lab, and select **Create storage**.
198
+
199
+
1. From the **Bash** prompt, in the **Cloud Shell** pane, run the following commands to retrieve the values of the Azure subscription ID and subscription name attributes:
200
+
201
+
```bash
202
+
az account show --query id --output tsv
203
+
az account show --query name --output tsv
204
+
```
205
+
206
+
>**Note**: Copy both values to a text file. You will need them later in this lab.
207
+
208
+
1. From the **Bash** prompt, in the **Cloud Shell** pane, run the following command to create a Service Principal (replace the **myServicePrincipalName** with any unique string of characters consisting of letters and digits) and **mySubscriptionID** with your Azure subscriptionId :
209
+
210
+
```bash
211
+
az ad sp create-for-rbac --name myServicePrincipalName \
212
+
--role contributor \
213
+
--scopes /subscriptions/mySubscriptionID
214
+
```
215
+
216
+
>**Note**: The command will generate a JSON output. Copy the output to text file. You will need it later in this lab.
217
+
218
+
1. Next, from the lab computer, start a web browser, navigate to the Azure DevOps **eShopOnWeb** project. Click on **Project Settings>Service Connections (under Pipelines)** and **New Service Connection**.
219
+
220
+

221
+
222
+
1. On the **New service connection** blade, select**Azure Resource Manager** and **Next** (may need to scroll down).
223
+
224
+
1. The choose **Service Principal (manual)** and click on **Next**.
225
+
226
+
1. Fill in the empty fields using the information gathered during previous steps:
227
+
- Subscription Id and Name.
228
+
- Service Principal Id (appId), Service principal key (password) and Tenant ID (tenant).
229
+
- In **Service connection name**type**azure subs**. This name will be referenced in YAML pipelines when needing an Azure DevOps Service Connection to communicate with your Azure subscription.
230
+
231
+

232
+
233
+
1. Click on **Verify and Save**.
234
+
235
+
#### Task 2: Deploy resources to Azure by YAML pipelines
236
+
>>>>>>> Stashed changes
178
237
1. Navigate back to the **Pipelines** pane in of the **Pipelines** hub.
179
-
2. In the **Create your first Pipeline** window, click **Create pipeline**.
238
+
1. In the **Create your first Pipeline** window, click **Create pipeline**.
180
239
181
240
>**Note**: We will use the wizard to create a new YAML Pipeline definition based on our project.
182
241
183
-
3. On the **Where is your code?** pane, click **Azure Repos Git (YAML)** option.
184
-
4. On the **Select a repository** pane, click **eShopOnWeb_MultiStageYAML**.
185
-
5. On the **Configure your pipeline** pane, scroll down and select **Existing Azure Pipelines YAML File**.
186
-
6. In the **Selecting an existing YAML File** blade, specify the following parameters:
242
+
1. On the **Where is your code?** pane, click **Azure Repos Git (YAML)** option.
243
+
1. On the **Select a repository** pane, click **eShopOnWeb_MultiStageYAML**.
244
+
1. On the **Configure your pipeline** pane, scroll down and select**Existing Azure Pipelines YAML File**.
245
+
1. In the **Selecting an existing YAML File** blade, specify the following parameters:
187
246
- Branch: **main**
188
247
- Path: **.ado/eshoponweb-cd-windows-cm.yml**
189
-
7. Click **Continue** to save these settings.
190
-
8. In the variables section, choose a name for your resource group, set the desired location and replace the value of the service connection with one of your existing service connections you created earlier.
191
-
9. Click the **Save and run** button from the top right corder and when the commit dialog appeared, click **Save and run** again.
248
+
1. Click **Continue** to save these settings.
249
+
1. In the variables section, choose a name for your resource group, set the desired location and replace the value of the service connection with one of your existing service connections you created earlier.
250
+
1. Click the **Save and run** button from the top right corder and when the commit dialog appeared, click **Save and run** again.
192
251
193
252

194
253
195
-
10. Wait for the deploymemnt to finish and review the results.
254
+
1. Wait for the deploymemnt to finish and review the results.
196
255

197
256
198
-
#### Task 1: Remove the Azure lab resources
257
+
#### Task 3: Remove the Azure lab resources
199
258
200
259
In this task, you will use Azure Cloud Shell to remove the Azure resources provisioned in this lab to eliminate unnecessary charges.
201
260
202
261
1. In the Azure portal, open the **Bash** shell session within the **Cloud Shell** pane.
203
-
2. Delete all resource groups you created throughout the labs of this module by running the following command (replace the resource group name with what you chose):
262
+
1. Delete all resource groups you created throughout the labs of this module by running the following command (replace the resource group name with what you chose):
204
263
205
264
```bash
206
265
az group list --query "[?starts_with(name,'AZ400-EWebShop-NAME')].[name]" --output tsv | xargs -L1 bash -c 'az group delete --name $0 --no-wait --yes'
0 commit comments