Power Platform
Use Environment Variables, Not Hardcoded Values
Stop hardcoding URLs, IDs, and connection strings. Environment variables make your solutions portable across environments.
The Problem
Hardcoded values in canvas apps and cloud flows break the moment you move a solution from Dev to Test to Production. Different environments have different URLs, API keys, and resource IDs. Hardcoding them means manual edits after every deployment.
Bad Approach
// In a canvas app formula
Set(varApiUrl, "https://api-dev.contoso.com/v2");
Set(varTenantId, "a1b2c3d4-e5f6-7890-abcd-ef1234567890");
// In a Power Automate flow HTTP action
{
"uri": "https://api-dev.contoso.com/v2/orders",
"headers": {
"x-api-key": "sk-dev-abc123xyz"
}
}
Every environment promotion requires someone to find and replace these values. Someone will forget one. Something will break in production.
Good Approach
Define Environment Variables in your solution, then reference them.
In Power Automate:
{
"uri": "@{parameters('ApiBaseUrl')}/orders",
"headers": {
"x-api-key": "@{parameters('ApiKey')}"
}
}
In Canvas Apps (via a flow):
// Call a flow that returns env variable values
Set(
varConfig,
GetConfiguration.Run()
);
// Use the values
Set(varApiUrl, varConfig.ApiBaseUrl);
Setting values per environment:
| Variable | Dev | Test | Prod |
|---|---|---|---|
| ApiBaseUrl | api-dev.contoso.com | api-test.contoso.com | api.contoso.com |
| ApiKey | sk-dev-xxx | sk-test-xxx | sk-prod-xxx |
Each environment has its own current value while the solution stays identical.
Key Takeaway
Environment variables are the foundation of healthy ALM. One solution, zero manual edits between environments.