Exercise - Set up your environment

Completed

Important

You need your own Azure subscription to run this exercise, and you might incur charges. If you don't already have an Azure subscription, create a free account before you begin.

Before you start to publish your toy company's reusable Bicep code, you need to configure your environment. In this section, you make sure that your Azure and Azure DevOps environments are set up to complete the rest of this module.

To meet these objectives, you'll:

  • Set up an Azure DevOps project for this module.
  • Clone the project's repository to your computer.
  • Create a resource group in Azure.
  • Create a service connection in Azure Pipelines.

Get the Azure DevOps project

In this section, you make sure that your Azure DevOps organization is set up to complete the rest of this module. You set it up by running a template that creates a project in Azure DevOps.

The modules in this learning path are part of a progression. For learning purposes, each module has an associated Azure DevOps project.

Tip

Even if you completed the preceding module in the learning path, follow these instructions to create a new project. Be sure to give the project a new name.

Run the template

Run a template that sets up your Azure DevOps project.

On the Azure DevOps Demo Generator site:

  1. Select Sign In, and then agree to the site usage terms by selecting Accept.

  2. On the Create New Project page, select your Azure DevOps organization and then, in the New Project Name box, enter a project name, such as toy-reusable.

    Screenshot of the Azure DevOps Demo Generator pane for creating a new project.

  3. Select Create Project.

    The template takes a few moments to run. It automatically creates a pipeline and Bicep file for you to work with in the next few exercises.

  4. Select Navigate to project to go to your project in Azure DevOps.

Important

The final exercise in this module contains important cleanup steps. Be sure to follow the cleanup steps even if you don't complete this module.

Clone the repository

  1. Select Repos > Files.

    Screenshot of Azure DevOps that shows the Repos menu, with Files highlighted.

  2. Select Clone.

    Screenshot of Azure DevOps showing the repository, with the Clone button highlighted.

  3. Select Generate Git Credentials. Copy your password and save it. You'll need this credential when authenticating to your repository when you later commit the updates to your YAML files.

    Screenshot of Azure DevOps that shows the repository settings, with the Generate Git Credentials button highlighted.

  4. Select Clone in VS Code. If you're prompted to allow Visual Studio Code to open, select Open.

    Screenshot of Azure DevOps that shows the repository settings, with the Clone in VS Code button highlighted.

  5. Create a folder to use for the repository, and then select Select Repository Location.

  6. You're using this repository for the first time, so you might be prompted to sign in.

    • If you're using Windows, enter the same credentials that you used to sign in to Azure DevOps earlier in this exercise.

    • If you're using macOS, enter the Git username and password that you generated a few moments ago.

  7. Visual Studio Code prompts you to open the repository. Select Open.

    Screenshot of Visual Studio Code that shows a prompt to open the cloned repository, with the Open button highlighted.

Sign in to Azure

To work with resource groups in Azure, sign in to your Azure account from the Visual Studio Code terminal. Be sure that you already installed the Azure CLI tools.

  1. In the Terminal menu, select New Terminal. The terminal window usually opens in the lower half of your screen.

    The default shell is typically pwsh, as shown on the right side of the terminal window.

    Screenshot of the Visual Studio Code terminal window, in which pwsh is shown as the shell option.

  2. Select the Launch Profile dropdown list, and then select Azure Cloud Shell (Bash).

    Screenshot of the Visual Studio Code terminal window. The terminal shell dropdown list and the Azure Cloud Shell (Bash) menu item are shown.

    A new shell opens.

Sign in to Azure by using the Azure CLI

  1. In the Visual Studio Code terminal, run the following command to sign in to Azure:

    az login
    
  2. In the browser that opens, sign in to your Azure account.

To work with resource groups in Azure, sign in to your Azure account from the Visual Studio Code terminal. Be sure that you already installed Azure PowerShell.

  1. In the Terminal menu, select New Terminal. The terminal window usually opens in the lower half of your screen.

    The default shell is typically pwsh, as shown on the right side of the terminal window.

    Screenshot of the Visual Studio Code terminal window, in which pwsh is shown as the shell option.

  2. Select the Launch Profile dropdown list, and then select Azure Cloud Shell (PowerShell).

    Screenshot of the Visual Studio Code terminal window. The terminal shell dropdown list and the Azure Cloud Shell (PowerShell) menu item are shown.

    A new shell opens.

Sign in to Azure by using Azure PowerShell

  1. In the Visual Studio Code terminal, run the following command to sign in to Azure:

    Connect-AzAccount
    
  2. In the browser that opens, sign in to your Azure account.

Create a resource group in Azure

To create a new resource group, run this Azure CLI command in the Visual Studio Code terminal:

az group create --name ToyReusable --location westus3

To create a resource group, run this Azure PowerShell command in the Visual Studio Code terminal:

New-AzResourceGroup -Name ToyReusable -Location westus3

Create a service connection in Azure Pipelines

Next, create a service connection in Azure Pipelines. This process automatically creates a service principal in Azure. It also grants the service principal the Contributor role on your resource group, which allows your pipeline to deploy into the resource group.

  1. In your browser, select Project settings.

    Screenshot of Azure DevOps that shows the menu, with the Project settings item highlighted.

  2. Select Service connections > Create service connection.

    Screenshot of Azure DevOps that shows the Service connections' pane, with the 'Create service connection' button highlighted.

  3. Select Azure Resource Manager > Next.

    Screenshot of Azure DevOps that shows the 'Service connections' pane, with the 'Azure Resource Manager' service connection type highlighted.

  4. Select Service principal (automatic) > Next.

    Screenshot of Azure DevOps that shows the New Azure service connection' pane, with the Service principal (automatic) option highlighted.

  5. In the Subscription dropdown list, select your Azure subscription.

    If a popup window appears with a message asking you to sign in to Azure, enter your credentials and sign in.

  6. In the Resource group dropdown list, select ToyReusable.

  7. In the Service connection name box, enter ToyReusable. Ensure that the Grant access permission to all pipelines checkbox is selected.

    Screenshot of Azure DevOps that shows the 'New Azure service connection' pane, with the details completed and the Save button highlighted.

    Tip

    In this exercise, for simplicity, you're giving every pipeline access to your service connection. When you create real service connections that work with production resources, consider restricting access to only the pipelines that need them.

  8. Select Save.