Task 01 - Deploy a Bicep script

Introduction

Before you can start building your AI shopping assistant, you need to deploy the necessary Azure resources. This includes setting up a resource group, deploying a Bicep script to create the required infrastructure, and configuring environment variables for your application.

Description

In this task, you will deploy a Bicep script that sets up the necessary Azure resources for your AI shopping assistant. This includes creating a resource group and deploying the required infrastructure. In addition, you will install any software prerequisites needed for the application to run.

Success Criteria

  • You have installed software necessary for the application to run.
  • You have created a resource group in Azure.
  • You have deployed a Bicep script to create the necessary Azure resources.

Learning Resources

Key Tasks

01: Fork the repository

Fork this GitHub repository to your account. You will need to fork the repo in order to modify and use GitHub Actions workflows in later tasks.

Expand this section to view the solution

In order to fork this repository, make sure that you are signed in to GitHub with the account you would like to use. Then, select the Fork button.

Fork the GitHub repository

On the next page, select your account as the Owner and leave the repository name alone. Then, select Create fork to complete the process.

Complete the process of forking the GitHub repository

02: Run Codespace or install necessary software

To work through this training, you can either use a GitHub Codespace or install the necessary software on your local machine.

To use a GitHub Codespace, navigate to your forked repository and select the Code button. Then, select the Codespaces tab and choose Create codespace on main.

Create a GitHub Codespace

This Codespace is pre-configured with all the necessary software to complete this training.

Alternatively, you can install the necessary software on your local machine. This includes:

If you do not use a Codespace, you will also need to clone the repository to your local machine.

You can do this using the following command:

git clone https://github.com/<your-username>/TechWorkshop-L300-AI-Apps-and-Agents.git

Make sure to replace <your-username> with your actual GitHub username.

03: Create a resource group in Azure

After you have set up your development environment, the next step is to create a resource group in Azure.

Expand this section to view the solution

You can do this using the following command in the Azure CLI, assuming you are logged in and have selected the correct subscription:

az group create --name techworkshop-l300-ai-agents --location eastus2

Alternatively, you may choose to do this from the Azure portal. In the search bar at the top, search for and select Resource groups. Then, select the + Create button to create a new resource group. Choose your subscription and give the resource group a name such as techworkshop-l300-ai-agents.

Make sure to choose from one of the following regions for the resource group location:

  • East US 2
  • Sweden Central
  • France Central
  • Switzerland West

The reason for this is that certain Azure services used in this training are currently only available in these regions.

04: Deploy the Bicep script

You will use either the Azure CLI or the Bicep extension in Visual Studio Code to deploy the Bicep script that sets up the necessary Azure resources for this training.

Expand this section to view the solution

Before you can deploy the Bicep script, you need to create a parameter file that contains your user principal ID. This will define a role assignment that gives you the Data Contributor role on your CosmosDB account. In Visual Studio Code, open a new Terminal and ensure that you are in the root of your workspace. First, ensure that you are logged into the Azure CLI. You can do so using az login on a local machine or az login --use-device-code in a Codespace VM.

If you receive an error message reading, “Your sign-in was successful but does not meet the criteria to access this resource,” you are likely using a Microsoft EMU account or some other account that has stringent restrictions on machine access. You will need to use an external MCAPS subscription or some other paid subscription to continue. A Visual Studio subscription will not be sufficient, as these accounts will likely not have access to Microsoft Foundry and the language models we will use.

To generate the parameter file on Linux or macOS (such as on a Codespace VM), issue the following command:

cat > parameters.json << EOF
{
  "\$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "userPrincipalId": {
      "value": "$(az ad signed-in-user show --query id -o tsv)"
    }
  }
}
EOF

To generate the parameter file in PowerShell on Windows, issue the following command:

@"
{
  "`$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "userPrincipalId": {
      "value": "$(az ad signed-in-user show --query id -o tsv)"
    }
  }
}
"@ | Out-File -FilePath parameters.json -Encoding utf8

The next step is to deploy the Bicep stack, making sure to pass in the parameters.json file you have created. You can do this either via CLI, or you can use the Visual Studio Code Bicep extension.

To deploy via CLI in Linux or macOS, issue the following command:

az deployment group create \
  --resource-group techworkshop-l300-ai-agents \
  --template-file src/infra/DeployAzureResources.bicep \
  --parameters parameters.json

To deploy via CLI in PowerShell on Windows, issue the following command:

az deployment group create `
  --resource-group techworkshop-l300-ai-agents `
  --template-file src/infra/DeployAzureResources.bicep `
  --parameters parameters.json

To deploy the Bicep stack using the Visual Studio Code Bicep extension, open Visual Studio Code and select File > Open Folder. Then, navigate to the location where you cloned the repository and open that folder. Then, strike Ctrl+Shift+P (or Cmd+Shift+P on macOS) to open the command palette. In the command palette, type Bicep: Deploy Bicep File and select that option.

Deploy a Bicep file from Visual Studio Code.

Choose the file src/infra/DeployAzureResources.bicep from the file dialog.

Select the DeployAzureResources Bicep script for deployment.

You may be prompted to sign into your Azure account. If so, follow the prompts to complete the sign-in process. Then, strike Enter to accept the default deployment name.

Keep the default deployment name.

After that, you will need to select the subscription and resource group where you would like to deploy the resources. Choose the same resource group that you created in the previous step.

Choose the subscription and resource group that you have created for this training.

Finally, you will be prompted for a parameter file. Select Browse.

Select Browse for the parameter file.

Then enter the path to the root of your workspace and click or select parameters.json.

Select the parameter file that we generated earlier.

In the console window, you will find a link to the deployment in the Azure portal. You can select this link to monitor the progress of the deployment.

Monitor the progress of the deployment in the Azure portal.