Skip to content
This repository was archived by the owner on Jan 21, 2026. It is now read-only.

Commit acaccd9

Browse files
committed
Added steps to create a service connection
1 parent 9030c09 commit acaccd9

1 file changed

Lines changed: 85 additions & 26 deletions

File tree

Instructions/Labs/AZ400_M06_L12_Azure_Deployments_Using_Resource_Manager_Templates.md

Lines changed: 85 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,21 @@ In this exercise, you will set up the prerequisites for the lab, which consist o
4141

4242
#### Task 1: (skip if done) Create and configure the team project
4343

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

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**.
4747

4848
![Create Project](images/create-project.png)
4949

5050
#### Task 2: (skip if done) Import eShopOnWeb Git Repository
5151

5252
In this task you will import the eShopOnWeb Git repository that will be used by several labs.
5353

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**:
5555

5656
![Import Repository](images/import-repo.png)
5757

58-
2. The repository is organized the following way:
58+
1. The repository is organized the following way:
5959
- **.ado** folder contains Azure DevOps YAML pipelines.
6060
- **.devcontainer** folder container setup to develop using containers (either locally in VS Code or GitHub Codespaces).
6161
- **.azure** folder contains Bicep&ARM infrastructure as code templates used in some lab scenarios.
@@ -74,15 +74,15 @@ In this task, you will use Visual Studio Code to create an Azure Bicep template
7474

7575
![Simple-windows-vm.bicep file](./images/m06/browsebicepfile.png)
7676

77-
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:
7878

7979
- Microsoft.Storage/storageAccounts
8080
- Microsoft.Network/publicIPAddresses
8181
- Microsoft.Network/virtualNetworks
8282
- Microsoft.Network/networkInterfaces
8383
- Microsoft.Compute/virtualMachines
8484

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

8787
#### Task 2: Create a bicep module for storage resources
8888

@@ -92,7 +92,7 @@ In this task, you will create a storage template module **storage.bicep** which
9292

9393
![Edit button](./images/m06/edit.png)
9494

95-
2. Now delete the storage resource:
95+
1. Now delete the storage resource:
9696

9797
```bicep
9898
resource storageAccount 'Microsoft.Storage/storageAccounts@2022-05-01' = {
@@ -105,15 +105,15 @@ In this task, you will create a storage template module **storage.bicep** which
105105
}
106106
```
107107

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

110110
![Commiting the file](./images/m06/commit.png)
111111

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**.
113113

114114
![New file menu](./images/m06/newfile.png)
115115

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:
117117

118118
```bicep
119119
@description('Location for all resources.')
@@ -140,7 +140,7 @@ In this task, you will modify the main template to reference the template module
140140

141141
1. Navigate back to the `simple-windows-vm.bicep` file and click on the **Edit** button once again.
142142

143-
2. Next, add the following code after the variables:
143+
1. Next, add the following code after the variables:
144144

145145
```bicep
146146
module storageModule './storage.bicep' = {
@@ -152,7 +152,7 @@ In this task, you will modify the main template to reference the template module
152152
}
153153
```
154154

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:
156156

157157
```bicep
158158
diagnosticsProfile: {
@@ -163,44 +163,103 @@ In this task, you will modify the main template to reference the template module
163163
}
164164
```
165165

166-
4. Review the following details in the main template:
166+
1. Review the following details in the main template:
167167

168168
- A module in the main template is used to link to another template.
169169
- The module has a symbolic name called `storageModule`. This name is used for configuring any dependencies.
170170
- You can only use **Incremental** deployment mode when using template modules.
171171
- A relative path is used for your template module.
172172
- Use parameters to pass values from the main template to the template modules.
173173

174-
5. Commit the template.
174+
1. Commit the template.
175175

176-
#### Task 4: Deploy resources to Azure by YAML pipelines
176+
### Exercise 2: Deploying the templates to Azure using YAML pipelines
177177

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+
![New Service Connection](images/new-service-connection.png)
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+
![Azure Service Connection](images/azure-service-connection.png)
232+
233+
1. Click on **Verify and Save**.
234+
235+
#### Task 2: Deploy resources to Azure by YAML pipelines
236+
>>>>>>> Stashed changes
178237
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**.
180239

181240
> **Note**: We will use the wizard to create a new YAML Pipeline definition based on our project.
182241

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:
187246
- Branch: **main**
188247
- 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.
192251

193252
![Save and running the YAML pipeline after making changes](./images/m06/saveandrun.png)
194253

195-
10. Wait for the deploymemnt to finish and review the results.
254+
1. Wait for the deploymemnt to finish and review the results.
196255
![Successful resource deployment to Azure using YAML pipelines](./images/m06/deploy.png)
197256

198-
#### Task 1: Remove the Azure lab resources
257+
#### Task 3: Remove the Azure lab resources
199258

200259
In this task, you will use Azure Cloud Shell to remove the Azure resources provisioned in this lab to eliminate unnecessary charges.
201260

202261
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):
204263

205264
```bash
206265
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

Comments
 (0)