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
# Work with Azure Developer CLI environment variables
13
13
14
-
The Azure Developer CLI (`azd`) uses environment variables to store and manage configuration settings across multiple deployment environments. These variables control how your application is provisioned, deployed, and run in Azure. This article explains how environment variables work within `azd` environments and provides guidance on managing them effectively.
14
+
The Azure Developer CLI (`azd`) uses environment variables to store and manage configuration settings for deployment environments. These variables control how your application is provisioned, deployed, and runs in Azure. This article explains how environment variables work within `azd` environments and provides guidance on managing them effectively.
15
15
16
16
## Understand environment variables
17
17
18
18
In the context of the Azure Developer CLI, environment variables are key-value pairs that are tied to specific named environments like *dev*, *test*, or *prod*. Each `azd` environment maintains its own set of environment variables, allowing you to configure different settings for different deployment targets.
19
19
20
-
Environment variables in `azd` are configuration settings stored in `.env` files within your environment folders in the `.azure` folder. They serve as inputs to:
20
+
Environment variables in `azd` are stored in `.env` files within your environment folders in the `.azure` folder. They serve as inputs to:
21
21
22
22
- Application deployment workflows
23
23
- Configurations for Azure services and connections
24
-
- Infrastructure provisioning processes
24
+
- Infrastructure provisioning via Bicep and Terraform
25
25
26
26
Unlike traditional environment variables that exist at the operating system level, `azd` environment variables are scoped to specific environments within your project, providing isolation between different deployment targets.
27
27
28
28
Environment variables provide several key benefits when working with `azd`:
29
29
30
30
-**Environment isolation**: Keep configurations for development, testing, and production separate and distinct.
31
-
-**Configuration consistency**: Ensure all team members use the same settings when working with a specific environment.
32
-
-**Infrastructure as Code**: Define your infrastructure parameterization through variables rather than hard-coded values.
31
+
-**Configuration consistency**: Ensure all team members use the same settings for a specific environment.
32
+
-**Infrastructure as Code**: Define infrastructure parameterization through variables instead of hard-coded values.
33
33
-**Deployment automation**: Enable CI/CD pipelines to deploy to different environments using the same codebase but different configurations.
34
34
-**Simplified management**: Easily update settings across all services in an environment from a central location.
35
35
@@ -55,7 +55,7 @@ KEY2=value2
55
55
> [!TIP]
56
56
> Visit the [Working with environments](work-with-environments.md) article for more information about `azd` environments.
57
57
58
-
When you run `azd`commands such as `azd up`, the CLI automatically loads variables from the select environment's `.env` file.
58
+
When you run commands such as `azd up`, `azd` automatically loads variables from the select environment's `.env` file.
## Use environment variables in infrastructure files
143
143
144
-
You can use environment variables to customize your infrastructure templates. This is useful for naming, tagging, or configuring resources based on the current environment.
144
+
You can use environment variables to customize your infrastructure templates. This is useful for naming, tagging, or configuring resources based on the current environment.`azd` also uses tags to locate resources in Azure for deployment and other tasks.
145
145
146
146
Consider the following common flow:
147
147
@@ -180,9 +180,9 @@ Consider the following common flow:
180
180
param location string
181
181
```
182
182
183
-
`azd` supplies these Bicep parameters with substituted values in `main.parameters.json`.
183
+
`azd` supplies these Bicep parameters with the substituted values in `main.parameters.json`.
184
184
185
-
4. Use the parameters for resource naming and tags so you can easily identify which environment a resource belongs to:
185
+
4. Use the parameters for resource naming and tags to later identify which environment a resource belongs to:
186
186
187
187
```bicep
188
188
var resourceToken = toLower(uniqueString(resourceGroup().id, name, location))
@@ -203,6 +203,9 @@ Consider the following common flow:
203
203
204
204
This pattern keeps your templates flexible, enables per-environment customization without code changes, and improves resource governance (naming, tagging, and discovery).
205
205
206
+
> [!NOTE]
207
+
> `azd` also relies on tagging to locate Azure resources during the deployment stage.
208
+
206
209
### Hooks
207
210
208
211
In custom scripts and [hooks](azd-extensibility.md) defined in your `azure.yaml` file, you can access environment variables using the `azd env get-values` command:
0 commit comments