Ağ & Network
100%

Managing Development Prerequisites and Command Execution with Azure Developer CLI (azd)

Explore the new `azd tool` and `azd exec` features to manage development environment requirements and run commands securely with Azure Developer CLI (azd).

Introduction

Azure Developer CLI (azd) is a command line tool designed to simplify the application development process in Azure cloud environments. With the latest updates, development environment requirements management and command execution processes, which are among the most common problems faced by developers, have been significantly improved. In this article, the new `azd tool` command group and how to use the `azd exec` tool will be explained in detail.

Issue: Managing Development Environment Requirements

One of the biggest challenges when developing Azure applications is template deployment errors due to lack of appropriate development tools or incompatible versions. For example:

  • Required .NET SDK, Node.js, Python or Java SDKs are missing.
  • Docker not installed locally or running on the wrong version.
  • Tools required to identify Azure resources, such as Bicep CLI, are not up to date.

These problems reduce productivity by causing developers to waste time and cause deployment errors. Azure Developer CLI provides the `azd tool` command group for these problems, making it possible to automatically manage the development environment.

Solution: Managing Development Tools with `azd tool` Command Group

The

`azd tool` suite of commands simplifies the process of discovering, installing, and updating development environment requirements. This command group provides the following basic functions:

1. Discovery of Available Tools (`azd tool list`)

With the following command, you can view the list of tools installed on the system and supported by the Azure Developer CLI:

azd tool list

Output Example:

Name Version Installed Supported
----------------------------------------------
dotnet 8.0.100 ✅ ✅
node 20.11.1 ✅ ✅
python 3.11.6 ❌ ✅
docker 24.0.7 ✅ ✅
bicep 0.27.1 ❌ ✅

2. Installation of Required Tools (`azd tool install`)

You can install missing tools with a single command. For example, to install the Python SDK:

azd tool install python --version 3.11.6

Similarly, to install Bicep CLI:

azd tool install bicep

3. Updating Tools (`azd tool upgrade`)

To automatically update the latest supported versions:

azd tool upgrade

Note: This command updates all supported tools to the latest stable version by default. To update a specific tool:

azd tool upgrade bicep --version 0.28.0

4. Uninstalling Tools (`azd tool uninstall`)

To remove a tool from the system:

azd tool uninstall python

Problem: Executing Commands with Environment Arguments and Secrets

Commands run in Azure applications often need environment variables and Azure Key Vault secrets. In traditional methods, these variables must be set manually or explicitly specified on the command line. This situation both creates a security risk and causes the commands to become complicated.

Solution: Safe and Contextual Command Execution with `azd exec`

`azd exec`

`azd exec` is a new command execution tool that runs commands with a full environment context and Azure Key Vault secrets. This tool offers the following features:

1. Management of Environment Arguments

`azd exec` automatically loads the necessary environment arguments before running commands. For example, you can automatically set the `AZURE_RESOURCE_GROUP` variable required to create an Azure Resource Group:

azd exec --command "az group create --name MyResourceGroup --location eastus"

2. Integrating Azure Key Vault Secrets

You can automatically parse secrets from Azure Key Vault and transfer them to commands. For example, to retrieve a database connection string from Key Vault:

azd exec --command "az deployment group create --resource-group MyResourceGroup --template-file main.bicep --parameters dbConnectionString=@Microsoft.KeyVault(SecretUri=https://mykeyvault.vault.azure.net/secrets/dbConnectionString)"

3. Cross Platform Support

`azd exec` works on all major operating systems, including Windows, Linux and macOS. This way, developers get a consistent experience across different platforms.

Application Steps: Using `azd tool` and `azd exec`

  • Install Azure Developer CLI

    Install Azure Developer CLI on your system with the following command:

    azd auth login

    This command allows you to log in to your Azure account and configure the CLI.

  • Check Development Tools

    List existing tools and identify any that are missing:

    azd tool list
  • Install Missing Tools

    For example, to install Docker:

    azd tool install docker

    To install the Python SDK:

    azd tool install python --version 3.11.6
  • Update Your Development Environment

    Update all tools to the latest versions:

    azd tool upgrade
  • Run Commands with `azd exec`

    For example, to create an Azure Resource Group:

    azd exec --command "az group create --name MyResourceGroup --location eastus"

    To distribute a Bicep template using a secret from the Key Vault:

    azd exec --command "az deployment group create --resource-group MyResourceGroup --template-file main.bicep --parameters dbPassword=@Microsoft.KeyVault(SecretUri=https://mykeyvault.vault.azure.net/secrets/dbPassword)"
  • Tips and Warnings

    Tip 1: When using the `azd tool install` command, if you do not specify the `--version` parameter, Azure Developer CLI will automatically select the most suitable version. However, if a specific version is required, be sure to specify it.

    Warning 1: When using the `azd exec` command, the commands run with your Azure account privileges by default. Therefore, review your authorizations before performing sensitive transactions.

    Tip 2: When using Azure Key Vault secrets, specify the URI of the secrets correctly. Incorrect URIs may cause commands to fail.

    Conclusion

    Azure Developer CLI's new `azd tool` and `azd exec` features aim to solve the most common problems developers encounter when developing Azure applications. The `azd tool` command set automatically manages development environment requirements, while the `azd exec` tool ensures safe and contextual execution of commands. Thanks to these features, developers both save time and minimize deployment errors. To start using Azure Developer CLI, you can review official documentation.

    Related Articles

    View All