You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 how to create, manage, and switch between environments to manage your development and deployment process.
14
+
The Azure Developer CLI (`azd`) helps you create and manage [Environments](environments-overview.md) with their own configurations, such as dev, test, and prod. This article shows how to create and manage environments, and how to leverage them with your Bicep infrastructure files.
15
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:
|`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:
|**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
-
## Create and manage environments
111
-
112
-
The Azure Developer CLI provides a set of commands to manage environments, such as creating, updating or switching between them. You can run these commands in specific environments without affecting others.
113
-
114
-
### Create environments
16
+
## Create environments
115
17
116
18
Create a new environment using the `azd env new` command:
117
19
@@ -133,7 +35,7 @@ You can also specify subscription and location directly in the command:
133
35
azd env new prod --subscription "My Production Subscription" --location eastus2
134
36
```
135
37
136
-
###List environments
38
+
## List environments
137
39
138
40
To see all available environments for your project, use:
139
41
@@ -150,7 +52,7 @@ test false true false
150
52
prod false true false
151
53
```
152
54
153
-
###Switch between environments
55
+
## Switch between environments
154
56
155
57
To switch to a different environment, use the `azd env select` command:
156
58
@@ -167,13 +69,13 @@ azd env select prod
167
69
> [!NOTE]
168
70
> This command changes your active environment, which affects subsequent `azd` commands like `provision` or `deploy`.
169
71
170
-
###Understand the default environment
72
+
## Understand the default environment
171
73
172
74
The global configuration file `.azure/config.json` keeps track of your currently selected environment. When you run `azd init` and no environments exist yet, `azd` automatically creates your first environment and sets it as the default. If you already have one or more environments and run `azd env new <name>`, you'll be prompted to choose whether to make the new environment the default. If you decline, the new environment is created but your current selection remains unchanged.
173
75
174
76
You can temporarily override the default environment for a single command by using the `--environment` flag. This does not change the default for future commands—only for that specific
175
77
176
-
###Refresh environment settings
78
+
## Refresh environment settings
177
79
178
80
You can refresh your local environment variables using the `azd env refresh` command. This command locates the most recent Azure deployment for your app, retrieves the environment variable values by name, and then updates your local `.env` file with those latest values for the select environment. For example, if you provisioned both a `dev` and `prod` version, and you currently have the `dev` environment selected, it will retrieve lates outputs from that deployment to populate the .env file.
179
81
@@ -191,7 +93,7 @@ Refreshing your environment is useful when:
191
93
192
94
If other team members made changes to environment configurations, or if you made changes through the Azure portal, you can refresh your local environment settings with:
193
95
194
-
###Run commands in specific environments
96
+
## Run commands in specific environments
195
97
196
98
You can run many `azd` commands in a specific environment without changing your active environment by using the `--environment` or `-e` flag:
0 commit comments