Configure Azure Developer CLI with Azure Deployment Environments

In this article, you create a new environment from an existing Azure Developer CLI (AZD) compatible template by using AZD. You learn how to configure Azure Deployment Environments (ADE) and AZD to work together to provision application infrastructure and deploy application code to the new infrastructure.

To learn the key concepts of how AZD and ADE work together, see Use Azure Developer CLI with Azure Deployment Environments.

Prerequisites

Attach Microsoft quick start catalog

Microsoft provides a quick start catalog that contains a set of AZD compatible templates that you can use to create environments. You can attach the quick start catalog to your dev center at creation or add it later. The quick start catalog contains a set of templates that you can use to create environments.

Examine an AZD compatible template

You can use an existing AZD compatible template to create a new environment, or you can add an azure.yaml file to your repository. In this section, you examine an existing AZD compatible template.

AZD provisioning for environments relies on curated templates from the catalog. Templates in the catalog might assign tags to provisioned Azure resources for you to associate your app services with in the azure.yaml file, or specify the resources explicitly. In this example, resources are specified explicitly.

For more information on tagging resources, see Tagging resources for Azure Deployment Environments.

  1. In the Azure portal, navigate to your dev center.

  2. In the left menu under Environment configuration, select Catalogs, and then copy the quick start catalog Clone URL.

    Screenshot of Azure portal showing the catalogs attached to a dev center, with clone URL highlighted.

  3. To view the quick start catalog in GitHub, paste the Clone URL into the address bar and press Enter.

  4. In the GitHub repository, navigate to the Environment-Definitions/ARMTemplates/Function-App-with-Cosmos_AZD-template folder.

  5. Open the environment.yaml file. At the end of the file, you see the allowed repositories that contain sample application source code.

    Screenshot of GitHub repository, showing the environment.yaml file with source templates highlighted.

  6. Copy the https://github.com/azure-samples/todo-python-mongo-swa-func repository URL, and then navigate to the repository in GitHub.

  7. In the root of the repository, open the azure.yaml file.

  8. In the azure.yaml file, in the services section, you see the web and API services that are defined in the template.

Note

Not all AZD compatible catalogs use the linked templates structure shown in the example. You can use a single catalog for all your environments by including the azure.yaml file. Using multiple catalogs and code repositories allows you more flexibility in configuring secure access for platform engineers and developers.

If you're working with your own catalog & environment definition, you can create an azure.yaml file in the root of your repository. Use the azure.yaml file to define the services that you want to deploy to the environment.

Create an environment from an existing template

Use an existing AZD compatible template to create a new environment.

Prepare to work with AZD

When you work with AZD for the first time, there are some one-time setup tasks you need to complete. These tasks include installing the Azure Developer CLI, signing in to your Azure account, and enabling AZD support for Azure Deployment Environments.

Install the Azure Developer CLI extension for Visual Studio Code

When you install AZD, the AZD tools are installed within an AZD scope rather than globally, and are removed if AZD is uninstalled. You can install AZD in Visual Studio Code or from the command line.

To enable Azure Developer CLI features in Visual Studio Code, install the Azure Developer CLI extension, version v0.8.0-alpha.1-beta.3173884. Select the Extensions icon in the Activity bar, search for Azure Developer CLI, and then select Install.

Screenshot of Visual Studio Code, showing the Sign in command in the command palette.

Sign in with Azure Developer CLI

Access your Azure resources by logging in. When you initiate a log in, a browser window opens and prompts you to log in to Azure. After you sign in, the terminal displays a message that you're signed in to Azure.

Sign in to AZD using the command palette:

Screenshot of Visual Studio Code, showing the Extensions pane with the Azure Developer CLI and Install highlighted.

The output of commands issued from the command palette is displayed in an azd dev terminal like the following example:

Screenshot of the AZD developer terminal, showing the press any key to close message.

Enable AZD support for ADE

When platform.type is set to devcenter, all AZD remote environment state and provisioning uses dev center components. AZD uses one of the infrastructure templates defined in your dev center catalog for resource provisioning. In this configuration, the infra folder in your local templates isn’t used.

Screenshot of Visual Studio Code, showing the Enable support command in the command palette.

Create a new environment

Now you're ready to create an environment to work in. You begin with an existing template. ADE defines the infrastructure for your application, and the AZD template provides sample application code.

  1. In Visual Studio Code, open an empty folder.

  2. Open the command palette, enter Azure Developer CLI init, and then from the list, select Azure Developer CLI (azd): init.

    Screenshot of the Visual Studio Code command palette with Azure Developer CLI (azd): init highlighted.

  3. In the list of templates, select Function-App-with-Cosmos_AZD-template.

    Screenshot of the Visual Studio Code command palette with a list of templates, Function App highlighted.

  4. In the AZD terminal, enter an environment name.

    Screenshot of the Azure Developer terminal, showing prompt for a new environment name.

  5. Select a project.

    Screenshot of the Azure Developer terminal, showing prompt to select a project.

  6. Select an environment definition.

    Screenshot of the Azure Developer terminal, showing prompt to select an environment definition.

    AZD creates the project resources, including an azure.yaml file in the root of your project.

Configure your devcenter

You can define AZD settings for your dev centers so that you don't need to specify them each time you update an environment. In this example, you define the names of the catalog, dev center, and project that you're using for your environment.

  1. In Visual Studio Code, navigate to the azure.yaml file in the root of your project.

  2. In the azure.yaml file, add the following settings:

    platform:
        type: devcenter
        config:
            catalog: MS-cat
            name: Contoso-DevCenter
            project: Contoso-Dev-project
    

    Screenshot of the azure.yaml file with dev center settings highlighted.

To learn more about the settings you can configure, see Configure dev center settings.

Provision your environment

You can use AZD to provision and deploy resources to your deployment environments using commands like azd up or azd provision.

To learn more about provisioning your environment, see Create an environment by using the Azure Developer CLI.

To how common AZD commands work with ADE, see Work with Azure Deployment Environments.