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
While direct editing works, using the `azd env set` command is preferred because it:
112
-
113
-
- Ensures proper formatting
114
-
- Validates the changes
115
-
- Avoids potential syntax errors
116
-
- Works consistently across different environments
117
-
118
99
### Output from Bicep
119
100
120
101
A powerful feature of `azd` is its ability to automatically capture output parameters from your Bicep infrastructure templates as environment variables. For example, when you define an output parameter in your `main.bicep` file:
This approach ensures that your application always has access to the most current resource information, such as:
133
114
134
115
- Service endpoints and URLs
135
-
- Connection strings
136
116
- Resource names and identifiers
137
-
- API keys (when properly secured)
138
117
139
118
## Get and use environment variables
140
119
141
-
Once set, you can access environment variables in several contexts:
120
+
Once set, you can access environment variables in several contexts.
142
121
143
-
### Using CLI commands
122
+
### CLI commands
144
123
145
124
To view all environment variables for the current environment:
146
125
@@ -160,26 +139,69 @@ For machine-readable output (useful in scripts):
160
139
azd env get-values --output json
161
140
```
162
141
163
-
### Pass environment variables to Bicep files
142
+
## Use environment variables in infrastructure files
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.
145
+
146
+
Consider the following common flow:
147
+
148
+
1. During `azd init`, `azd` sets these environment variables based on the user's response to prompts:
164
149
165
-
Environment variables can be referenced in Bicep parameter files (`main.parameters.json`) using a special substitution syntax:
2. Reference those variables in `main.parameters.json` in the `infra` folder. `azd` substitutes the values during provisioning and passes the resolved parameters to Bicep:
When `azd` processes this file during provisioning, it automatically substitutes the references with the actual environment variable values from the current environment's `.env` file. This behavior is useful when you want to influence provisioned resources using `azd` environment variables.
204
+
This pattern keeps your templates flexible, enables per-environment customization without code changes, and improves resource governance (naming, tagging, and discovery).
0 commit comments