Skip to content

Commit 02025b4

Browse files
committed
fixes
1 parent 8746024 commit 02025b4

File tree

1 file changed

+7
-105
lines changed

1 file changed

+7
-105
lines changed

articles/azure-developer-cli/work-with-environments.md

Lines changed: 7 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -11,107 +11,9 @@ ms.custom: devx-track-azdevcli, build-2023
1111

1212
# Work with Azure Developer CLI environments
1313

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 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.
1515

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-
## 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
11517

11618
Create a new environment using the `azd env new` command:
11719

@@ -133,7 +35,7 @@ You can also specify subscription and location directly in the command:
13335
azd env new prod --subscription "My Production Subscription" --location eastus2
13436
```
13537

136-
### List environments
38+
## List environments
13739

13840
To see all available environments for your project, use:
13941

@@ -150,7 +52,7 @@ test false true false
15052
prod false true false
15153
```
15254

153-
### Switch between environments
55+
## Switch between environments
15456

15557
To switch to a different environment, use the `azd env select` command:
15658

@@ -167,13 +69,13 @@ azd env select prod
16769
> [!NOTE]
16870
> This command changes your active environment, which affects subsequent `azd` commands like `provision` or `deploy`.
16971
170-
### Understand the default environment
72+
## Understand the default environment
17173

17274
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.
17375

17476
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
17577

176-
### Refresh environment settings
78+
## Refresh environment settings
17779

17880
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.
17981

@@ -191,7 +93,7 @@ Refreshing your environment is useful when:
19193

19294
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:
19395

194-
### Run commands in specific environments
96+
## Run commands in specific environments
19597

19698
You can run many `azd` commands in a specific environment without changing your active environment by using the `--environment` or `-e` flag:
19799

0 commit comments

Comments
 (0)