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
Copy file name to clipboardExpand all lines: articles/azure-developer-cli/work-with-environments.md
+49-49Lines changed: 49 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,22 +47,57 @@ The key components of this structure are:
47
47
3.**`.env` file**: Contains environment-specific variables used by your application and during deployment.
48
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
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
+
50
91
### Use the environment name in infrastructure files
51
92
52
93
You can use the `AZURE_ENV_NAME` variable from your environment's `.env` file to customize your infrastructure deployments in Bicep. This is useful for naming, tagging, or configuring resources based on the current environment.
53
94
54
-
1.Pass`AZURE_ENV_NAME` from the `.env` file to Bicep as an input parameter. This environment variable is set by `azd` when you initialize a project.
95
+
1.The`AZURE_ENV_NAME` environment variable is set by `azd` when you initialize a project.
55
96
56
97
```output
57
98
AZURE_ENV_NAME=dev
58
99
```
59
100
60
-
1. In your Bicep template, define a parameter for the environment name:
61
-
62
-
```bicep
63
-
param environmentName string
64
-
```
65
-
66
101
1. In your `main.parameters.json` file, reference the environment variable so `azd` will substitute its value:
67
102
68
103
```json
@@ -77,7 +112,13 @@ You can use the `AZURE_ENV_NAME` variable from your environment's `.env` file to
77
112
}
78
113
```
79
114
80
-
Now, when you deploy with `azd`, the value from `.env` will be passed to your Bicep file from `main.parameters.json`.
115
+
When you deploy with `azd`, the value from `.env` will be passed to your Bicep file from `main.parameters.json`.
116
+
117
+
1. In your Bicep template, define a parameter for the environment name:
118
+
119
+
```bicep
120
+
param environmentName string
121
+
```
81
122
82
123
1. You can use the `environmentName` parameter to tag resources, making it easy to identify which environment a resource belongs to:
83
124
@@ -100,47 +141,6 @@ You can use the `AZURE_ENV_NAME` variable from your environment's `.env` file to
100
141
101
142
This approach helps with resource management, cost tracking, and automation by associating each resource with its deployment environment.
102
143
103
-
## Environment variables
104
-
105
-
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:
106
-
107
-
- Configure your application's settings
108
-
- Define infrastructure parameters
109
-
- Store connection strings, endpoints, and secrets
110
-
111
-
The `.env` file contains these variables in a standard format:
|`AZURE_ENV_NAME`| Name of the current environment |
128
-
|`AZURE_LOCATION`| Azure region where resources are deployed |
129
-
|`AZURE_SUBSCRIPTION_ID`| ID of the Azure subscription used for this environment |
130
-
|`AZURE_RESOURCE_GROUP`| Name of the resource group for this environment |
131
-
132
-
> [!TIP]
133
-
> For other common environment variables and service-specific examples, visit the [Environment variables](manage-environment-variables.md) documentation.
134
-
135
-
When working with environment variables:
136
-
137
-
- 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).
138
-
- Use consistent naming across environments.
139
-
- Use the `azd env set` command to update variables safely.
140
-
141
-
> [!WARNING]
142
-
> 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.
143
-
144
144
## Compare other framework environments
145
145
146
146
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:
0 commit comments