|
| 1 | +--- |
| 2 | +title: Azure Developer CLI environments overview |
| 3 | +description: Learn essential concenpts about environments using Azure Developer CLI (azd). |
| 4 | +author: alexwolfmsft |
| 5 | +ms.author: alexwolf |
| 6 | +ms.date: 08/04/2025 |
| 7 | +ms.service: azure-dev-cli |
| 8 | +ms.topic: how-to |
| 9 | +ms.custom: devx-track-azdevcli, build-2023 |
| 10 | +--- |
| 11 | + |
| 12 | +# Azure Developer CLI environments overview |
| 13 | + |
| 14 | +The Azure Developer CLI (`azd`) lets you manage multiple deployment environments for your projects, to keep configurations separate for development, testing, and production. This article explains essential concepts about how you can use environments to manage your development and deployment process. |
| 15 | + |
| 16 | +## What are environments? |
| 17 | + |
| 18 | +An environment in the Azure Developer CLI (`azd`) context represents a named collection of configuration settings, environment variables, and infrastructure parameters associated with a specific deployment of your application. Environments serve several important purposes: |
| 19 | + |
| 20 | +- **Isolation**: Keep development, testing, staging, and production deployments separate. |
| 21 | +- **Configuration management**: Maintain different settings for each environment. |
| 22 | +- **Collaboration**: Enable team members to work with their own environments. |
| 23 | +- **Resource organization**: Group and provision Azure resources by environment, such as using lower tier services for dev environments. |
| 24 | +- **Reproducibility**: Ensure consistent deployments across different stages. |
| 25 | + |
| 26 | +Each environment has its own Azure resource group and configuration settings. The environment name typically follows the pattern `rg-<environment-name>`, but this is not enforced by `azd` and is configurable by the user. This environment isolation helps prevent changes in one environment from affecting others. |
| 27 | + |
| 28 | +## Environment structure and configuration files |
| 29 | + |
| 30 | +Azure Developer CLI (`azd`) environments live in a directory structure within your project: |
| 31 | + |
| 32 | +```txt |
| 33 | +├── .azure [Created when you run azd init or azd up] |
| 34 | +│ ├── <environment-name-1> [Directory for environment-specific configurations] |
| 35 | +│ │ ├── .env [Environment variables for this environment] |
| 36 | +│ │ └── main.parameters.json [Infrastructure parameters for this environment] |
| 37 | +│ ├── <environment-name-2> [Another environment] |
| 38 | +│ │ ├── .env |
| 39 | +│ │ └── main.parameters.json |
| 40 | +│ └── config.json [Global azd configuration] |
| 41 | +``` |
| 42 | + |
| 43 | +The key components of this structure are: |
| 44 | + |
| 45 | +1. **`.azure` directory**: The root directory for all environment configurations. Excluded from source control by the `.gitignore` file by default. |
| 46 | +2. **Environment-specific directories**: Directories named after your environments, such as `dev`, `test`, `prod`. |
| 47 | +3. **`.env` file**: Contains environment-specific variables used by your application and during deployment. |
| 48 | +4. **`main.parameters.json`**: Contains parameters commonly used during infrastructure provisioning with Bicep or Terraform, but can be used for any per-environment `azd` configuration. This file is not intended to be used directly by end users. |
| 49 | + |
| 50 | +## Environment variables |
| 51 | + |
| 52 | +Azure Developer CLI [Environment variables](manage-environment-variables.md) provide a way to store configuration settings that influence and might vary between environments. When you run Azure Developer CLI commands, these variables are used to: |
| 53 | + |
| 54 | +- Configure your application's settings |
| 55 | +- Define infrastructure parameters |
| 56 | +- Store connection strings, endpoints, and secrets |
| 57 | + |
| 58 | +The `.env` file contains these variables in a standard format: |
| 59 | + |
| 60 | +```output |
| 61 | +AZURE_ENV_NAME=dev |
| 62 | +AZURE_LOCATION=eastus |
| 63 | +AZURE_SUBSCRIPTION_ID=00000000-0000-0000-0000-000000000000 |
| 64 | +RESOURCE_TOKEN=12345 |
| 65 | +AZURE_RESOURCE_GROUP=rg-dev-12345 |
| 66 | +SERVICE_WEB_HOSTNAME=web-dev-12345.azurewebsites.net |
| 67 | +SERVICE_API_HOSTNAME=api-dev-12345.azurewebsites.net |
| 68 | +``` |
| 69 | + |
| 70 | +Common environment variables include: |
| 71 | + |
| 72 | +| Variable | Description | |
| 73 | +|----------|-------------| |
| 74 | +| `AZURE_ENV_NAME` | Name of the current environment | |
| 75 | +| `AZURE_LOCATION` | Azure region where resources are deployed | |
| 76 | +| `AZURE_SUBSCRIPTION_ID` | ID of the Azure subscription used for this environment | |
| 77 | +| `AZURE_RESOURCE_GROUP` | Name of the resource group for this environment | |
| 78 | + |
| 79 | +> [!TIP] |
| 80 | +> For other common environment variables and service-specific examples, visit the [Environment variables](manage-environment-variables.md) documentation. |
| 81 | +
|
| 82 | +When working with environment variables: |
| 83 | + |
| 84 | +- Avoid committing `.env` files to source control. If environment configuration needs to be persisted or shared, users should leverage [Remote environments](remote-environments-support.md). |
| 85 | +- Use consistent naming across environments. |
| 86 | +- Use the `azd env set` command to update variables safely. |
| 87 | + |
| 88 | +> [!WARNING] |
| 89 | +> Never store secrets in an Azure Developer CLI `.env` file. These files can easily be shared or copied into unauthorized locations, or checked into source control. Use services such as Azure Key Vault or Azure Role Based Access Control (RBAC) for protected or secretless solutions. |
| 90 | +
|
| 91 | +## Compare other framework environments |
| 92 | + |
| 93 | +Many programming frameworks and tools such as Node.js, Django, or React use `.env` files for configuration. While Azure Developer CLI (`azd`) also uses `.env` files, there are important differences: |
| 94 | + |
| 95 | +| Concept | Azure Developer CLI `.env` | Framework `.env` Files | |
| 96 | +|--------|---------------------------|------------------------| |
| 97 | +| **Location** | Stored in `.azure/<environment-name>/.env` | Typically stored in project root directory | |
| 98 | +| **Environment Support** | Support for multiple user-defined environments (dev, test, prod) | Often require manual file switching or naming conventions (`.env.development`, `.env.production`) | |
| 99 | +| **Loading Mechanism** | Automatically loaded by `azd` commands | Usually require explicit loading in application code or build scripts | |
| 100 | +| **Integration** | Deeply integrated with Azure services and resource provisioning | General purpose configuration, not Azure-specific | |
| 101 | +| **Variable Management** | Managed via `azd env` commands | Typically edited manually or via custom scripts | |
| 102 | + |
| 103 | +While both serve similar purposes, Azure Developer CLI's `.env` approach adds structure and tooling designed for managing multiple deployment environments and Azure resources. |
| 104 | + |
| 105 | +> [!NOTE] |
| 106 | +> If your project already uses framework-specific `.env` files, you can keep both configuration systems without conflicts. |
| 107 | +> |
| 108 | +> `azd` environment variables override system environment variables of the same name for some operations. |
| 109 | +
|
| 110 | +## Next steps |
| 111 | + |
| 112 | +> [!div class="nextstepaction"] |
| 113 | +> [Work with environments](work-with-environments.md) |
| 114 | +
|
| 115 | +> [!div class="nextstepaction"] |
| 116 | +> [Manage environment variables in Azure Developer CLI](manage-environment-variables.md) |
0 commit comments