Environment variables overview
Environment variables enable the basic application lifecycle management (ALM) scenario of moving an applications between Power Platform environments. In this scenario, the applications stay exactly the same except for a few key external application references (such as tables, connections, and keys) that are different between the source environment and the destination environment. The applications requires the structure of the tables or connections to be exactly the same between the source and the destination environments, with some differences. Environment variables allow you to specify which of these different external references should be updated as the application is moved across environments.
Environment variables store the parameter keys and values, which then serve as input to various other application objects. Separating the parameters from the consuming objects allows you to change the values within the same environment or when you migrate solutions to other environments. The alternative is leaving hard-coded parameter values within the components that use them. This is often problematic; especially when the values need to be changed during ALM operations. Because environment variables are solution components, you can transport the references (keys) and change the values when solutions are migrated to other environments.
New capabilities for data sources are just now being deployed and may not be available yet in your region.
Benefits of using environment variables:
- Provide new parameter values while importing solutions to other environments.
- Store configuration for the data sources used in canvas apps and flows. For example, SharePoint Online site and list parameters can be stored as environment variables; therefore allowing you to connect to different sites and lists in different environments without needing to modify the apps and flows.
- Package and transport your customization and configuration together and manage them in a single location.
- Package and transport secrets, such as credentials used by different components, separately from the components that use them.
- One environment variable can be used across many different solution components - whether they're the same type of component or different. For example, a canvas app and a flow can use the same environment variable. When the value of the environment variable needs to change, you only need to change one value.
- Additionally, if you need to retire a data source in production environments, you can simply update the environment variable values with information for the new data source. The apps and flows don't require modification and will start using the new data source.
- Supported by SolutionPackager and DevOps tools enable continuous integration and continuous delivery (CI/CD).
- The environment variables can be unpacked and stored in source control. You may also store different environment variables values files for the separate configuration needed in different environments. Solution Packager can then accept the file corresponding to the environment the solution will be imported to.
How do they work?
Environment variables can be created and modified within the modern solution interface, automatically created when connecting to certain data sources in canvas apps, or by using code. They can also be imported to an environment via solutions. Once environment variables are present in an environment, they can be used as inputs when authoring canvas apps, Power Automate flows, when developing plug-ins, as well as many other places such as adding a Power BI dashboard to a model-driven app. When these types of objects use environment variables, the values are then derived from the environment variables, and can be changed when solutions are imported to other environments.
Create an environment variable in a solution
- Sign in to Power Apps (make.powerapps.com), and then on the left pane select Solutions.
- Open the solution you want or create a new one.
- On the command bar, select New > More, and then select Environment variable.
- On the right pane, complete the following columns, and then select Save:
Display name. Enter a name for the environment variable.
Name. The unique name is automatically generated from the Display name, but you can change it.
Data Type. Select from Decimal number, Text, JSON, Two options, Data source, or Secret.
If Data source is the selected type, you'll also need to select the connector, a valid connection for the selected connector, and the parameter type. However, the connection is not stored as part of the environment variable. The connection is only used for retrieving available parameter values such as the SharePoint sites you have access to, or the lists associated with a site. For certain parameters such as SharePoint lists, you'll also need to select a parent data source environment variable such as the SharePoint site. Once saved, these will be related in the database.
If Secret is the selected type, additional information to set up and configure Azure Key Vault is needed to allow Power Platform to access the secret.
Current Value. Also known as the value. This property is optional and is a part of the environment variable value table. When a value is present it will be used, even if a default value is also present. Remove the value from your solution if you don't want to use it in the next environment. The values are also separated into separate JSON files within the exported solution.zip file and can be edited offline. More information: How do I remove a value from an environment variable?
Default Value. This column is part of the environment variable definition table and is not required. The default value is used if there's no current value.
Separation of default value and current value allows you to service the definition and the default value separately from the value. For example, an application publisher may list their offer on AppSource with a default value. Then optionally, the customer can provide a new value. When the application publisher publishes updates to the application, the value set by the customer won't be overwritten.
A value can't exist without a definition. The interface only allows creation of one value per definition.
Use data source environment variables in canvas apps
Use pre-existing data source environment variables
Environment variables can be reused across other apps and even different types of resources like cloud flows. You may wish to first create them within your solution and later use them while authoring canvas apps and cloud flows.
- Follow the steps above to Create an environment variable in a solution.
- Edit or create a canvas app from your solution.
- Add a new data source for SharePoint online.
- Select the Advanced tab. You'll see a filtered list of environment variables that you have access to and that match the parameter being set. For example, when you select the SharePoint site, you'll see a list of all data source environment variables with Connector = SharePoint and Parameter type = Site. The same is true when selecting SharePoint lists for a given site.
- Select the desired environment variable(s), and then select Connect.
If an environment variable from a different solution is selected, a dependency will exist on the solution containing the environment variable. Therefore, be sure to either:
- Add the environment variable to your current solution prior to exporting.
- Ensure the solution containing the environment variable is imported to the destination environment before your current solution is imported.
Automatically create data source environment variables when connecting to data
This option provides simplicity and ensures environment variables will always be used for data sources, such as SharePoint Online. However, some customers prefer to provide their own schema names and therefore should create them from solutions.
- Edit or create a canvas app from your solution.
- Select Settings > General and enable the setting to Automatically create environment variables when adding data sources.
- Add a New data source for SharePoint online.
- Select a SharePoint site, one or more lists, and then Connect.
To prevent creation of duplicate environment variables, you'll be prompted to use the existing environment variable when duplicates are identified. You can clear the option to use the existing environment variable if creation of a duplicate is desired.
- Select Save.
Pre-existing canvas apps will not automatically use data source environment variables. Remove the data source from the app and add them back using the above steps to upgrade these apps to use environment variables.
Use environment variables in Power Automate solution cloud flows
Environment variables can be used in solution cloud flows since they're available in the dynamic content selector. All types of environment variables can be used in triggers and actions. To use an environment variable in a solution cloud flow:
Edit or create a cloud flow in a solution.
In an action or a trigger, determine the parameter that you want to use for the environment variable:
a. If the parameter takes a simple value, such as a string or number, enter the parameter.
b. If the parameter is a lookup, scroll to the bottom of the lookup, and then select Enter custom value. Environment variables that you have access to are listed in the dynamic content selector with other dynamic content.
Select the desired environment variable.
Enter new values while importing solutions
The modern solution import interface includes the ability to enter values for environment variables. This sets the value property on the
You may remove the value from your solution before exporting the solution. This ensures the existing value will remain in your development environment, but will not get exported in the solution. This approach allows a new value to be provided while importing the solution into other environments. You will not be prompted for new values during solution import if the environment variables already have either a default value or value present; whether values are part of your solution or are already present in the target environment. More information: How do I remove a value from an environment variable?
A notification is displayed when the environment variables don't have any values. This is a reminder to set the values so that components dependent on environment variables don't fail.
environmentvariabledefinition table is user or team owned. When you create an application that uses environment variables, be sure to assign users the appropriate level of privilege to this table. Permission to the
environmentvariablevalue table is inherited from the parent
environmentvariabledefinition table and therefore doesn't require separate privileges. Privileges for
environmentvariabledefinition tables are included in Environment Maker and Basic User security roles by default. More information: Security in Dataverse.
Ensure environment variable names are unique so they can be referenced accurately. Duplicate environment variable display names make environment variables difficult to differentiate and use. Ensure environment variable names are unique so they can be referenced accurately. The names $authentication and $connection are specially reserved parameters for flows and should be avoided. Flow save will be blocked if environment variables with those names are used. If an environment variable is used in a flow and the display name of the environment variable is changed, then the designer will show both the old and new display name tokens to help with identification. When updating the flow, it's recommended to remove the environment variable reference and add it again.
Use Azure Key Vault secrets (preview)
[This topic is pre-release documentation and is subject to change.]
Environment variables allow for referencing secrets stored in Azure Key Vault. These secrets are then made available for use within Power Automate flows and custom connectors. Notice that the secrets aren't available for use in other customizations or generally via the API.
The actual secrets are stored in Azure Key Vault and the environment variable references the key vault secret location. Using Azure Key Vault secrets with environment variables require that you configure Azure Key Vault so that Power Platform can read the specific secrets you want to reference.
Environment variables referencing secrets aren't currently available from the dynamic content selector for use in flows.
This is a preview feature. More information: Model-driven apps and app management
Configure Azure Key Vault
To use Azure Key Vault secrets with Power Platform, the Azure subscription that has the vault must have the
PowerPlatform resource provider registered and the user who creates the environment variable must have appropriate permissions to the Azure Key Vault resource.
Microsoft.PowerPlatformresource provider in your Azure subscription. Follow these steps to verify and configure: Resource providers and resource types
Create an Azure Key Vault vault. Consider using a separate vault for every Power Platform environment to minimize the threat in case of a breach. Go to Best practices for using Azure Key Vault for more information. For more information about how to create a key vault, go to Quickstart - Create an Azure Key Vault with the Azure portal
The user who creates the environment variable must have read permission on the specific vault. You can verify permission using View my access on the Access Control > Check access tab of the Azure Key Vault on the Azure portal. If the user doesn't have access to the vault, grant access to this resource via the Key Vault Reader or other appropriate role.
Azure Key Vault must have Get secret access policy set for the Dataverse service principal. If it doesn't exist for this vault, add a new access policy. Select Add Access Policy and then select Get as the access policy. Next to Select principal, select None selected and then search for Dataverse. Select the Dataverse service principal with the 00000007-0000-0000-c000-000000000000 identity and then select Add. Once added, the access policy should look like this.
If you haven't done so already, add a secret to your new vault. More information: Azure Quickstart - Set and retrieve a secret from Key Vault using Azure portal
Create a new environment variable for the Key Vault secret
Once Azure Key Vault is configured and you have a secret registered in your vault, you can now reference it within Power Apps using an environment variable.
Sign on to Power Apps, and in the Solutions area, open the unmanaged solution you're using for development.
Select New > More > Environment variable.
Enter a Display name and optionally, a Description for the environment variable.
Select the Data Type as Secret and Secret Store as Azure Key Vault.
Choose from the following options:
- Select New Azure Key Vault value reference. After the information is added in the next step and saved, an environment variable value record is created.
- Expand Show default value, to display the fields to create a Default Azure Key Vault secret. After the information is added in the next step and saved, the default value demarcation is added to the environment variable definition record.
Enter the following information:
- Azure Subscription ID: The Azure subscription ID associated with the key vault.
- Resource Group Name: The Azure resource group where the key vault that contains the secret is located.
- Azure Key Vault Name: The name of the key vault that contains the secret.
- Secret Name: The name of the secret located in Azure Key Vault.
The subscription ID, resource group name, and key vault name can be found on the Azure portal Overview page of the key vault. The secret name can be found on the key vault page in the Azure portal by selecting Secrets under Settings.
User access validation for the secret is performed in the background. If the user doesn’t have at least read permission, this validation error is displayed: This variable didn't save properly. User is not authorized to read secrets from 'Azure Key Vault path'.
Currently, Azure Key Vault is the only secret store that is supported with environment variables.
The Azure Key Vault must be in the same tenant as your Power Platform subscription.
Create a Power Automate flow to test the environment variable secret
A simple scenario to demonstrate how to use a secret obtained from Azure Key Vault is to create a Power Automate flow to use the secret to authenticate against a web service.
The URI for the web service in this example is not a functioning web service.
Sign into PowerApps, select Solutions, and then open the unmanaged solution you want.
Select New > Automation > Cloud flow > Instant.
Enter a name for the flow, select Manually trigger a flow, and then select Create.
Select New step, select the Microsoft Dataverse connector, and then on the Actions tab select Perform an unbound action.
Select the action named RetrieveEnvironmentVariableSecretValue from the dropdown list.
Provide the environment variable unique name (not the display name) added in the previous section, for this example new_TestSecret is used.
Select ... > Rename to rename the action so that it can be more easily referenced in the next action. In the below screenshot, it has been renamed to GetSecret.
Select ... > Settings to display the GetSecret action settings.
Enable the Secure Outputs option in the settings, and then select Done. This is to prevent the output of the action getting exposed in the flow run history.
Select New step, search and select the HTTP connector.
Select the Method as GET and enter the URI for the web service. In this example, the fictitious web service httpbin.org is used.
Select Show advanced options, select the Authentication as Basic, and then enter the Username.
Select the Password field, and then on the Dynamic content tab under the flow step name above (GetSecret in this example) select RetrieveEnvironmentVariableSecretValueResponse EnvironmentVariableSecretValue, which is then added as an expression
Select ... > Settings to display the HTTP action settings.
Enable the Secure Inputs and Secure Outputs options in the settings, and then select Done. Enabling these options prevents the input and outputs of the action getting exposed in the flow run history.
Select Save to create the flow.
Manually run the flow to test it.
Using the run history of the flow, the outputs can be verified.
- SharePoint Online is currently the only data source supported for environment variables of type "data source" within canvas apps. However, the Dataverse connector will be updated soon for when connectivity is required to Dataverse environments other than the current environment. Other types of environment variables may be used within canvas apps by retrieving them as you would record data via a Dataverse connection.
- If you’re using environment variables for storing SharePoint data source parameters in canvas apps, ensure you use Display Name (instead of logical name, or ID) when using "Lookup" or "Person or group" column types.
- When environment variable values are changed directly within an environment instead of through an ALM operation like solution import, flows will continue using the previous value until the flow is either saved or turned off and turned on again.
- Validation of environment variable values happens within the user interfaces and within the components that use them, but not within Dataverse. Therefore ensure proper values are set if they're being modified through code.
- Power Platform Build Tools tasks aren't yet available for managing data source environment variables. However, this doesn't block their usage within Microsoft provided tooling and within source control systems.
- Interacting with environment variables via custom code requires an API call to fetch the values; there isn't a cache exposed for third party code to leverage.
- When editing a cloud flow, the environment variables shown in the dynamic content selector are unfiltered, but will be filtered by data type in the future.
- When editing a cloud flow, if an environment variable is added in another browser tab, the flow needs to be reopened in the flow designer to refresh the dynamic content selector.
- Environment variables referencing Azure Key Vault secrets are currently limited for use with Power Automate flows and custom connectors.
Frequently asked questions
How can I view where environment variables are being used?
Either through selecting Show dependencies in the solution interface, while authoring components, or in source control and in the solution file by viewing the app or flow metadata.
Are data source environment variables the same as connections?
No. Although they're related. A connection represents a credential or authentication required to interact with the connector. Data source environment variables store parameters that are required by one or more actions in the connector and these parameters often vary depending on the action. For example, a SharePoint Online connection doesn't store any information about sites, lists, or document libraries. Therefore calling the connector requires both a valid connection as well as some additional parameters.
Can data source environment variables be used with shared connections such as SQL Server with SQL authentication?
Generally no. Shared connections with SQL Server store the parameters required to connect to data within the connection. For example, the Server and Database name are provided when creating the connection and therefore are always derived from the connection.
Data source environment variables are used for connectors that rely on user based authentication such as Azure Active Directory because the parameters can't be derived from the connection. For these reasons authentication with SQL Server, which is a shared connection, won't use data source environment variables.
Can my automated ALM pipeline use different values files for different environments?
Yes. Solution packager accepts file name as input parameters so your pipeline can pack a different values file into the solution depending on the environment type it’s executing against.
What if someone inadvertently deletes a value?
If not already prevented by dependency system, runtime will use the last known value as a fallback.
If a value is changed, when does the new value get used in canvas apps and cloud flows?
It may take up to an hour to fully publish updated environment variables.
With cloud flows, the flows must currently be de-activated and reactivated in order to use the updated value.
Are premium licenses required?
No. While ALM requires Dataverse (or Dynamics 365 for Customer Engagement), use of premium connectors isn't required. The one caveat is if you're using the Dataverse connector to interact with environment variables as you would with other data records like accounts or contacts. Previously this was the only way to use environment variables in canvas apps and flows.
Is there a limit to the number of environment variables I can have?
No. However, the max size of a solution is 32 MB. See Create a solution
Can environment variable display names and descriptions be localized?
Should I use environment variables instead of storing configuration data in custom tables?
Yes if your configuration data isn't relational. Environment variables should be used for key: value pairs and when the value likely needs to different in other environments. Other tools such as the Configuration migration utility are better suited for migration of relational configuration data stored within custom tables. Unlike other configuration data, environment variables are migrated within solutions and therefore much simpler to manage and more performant to import.
How do I remove a value from an environment variable?
You might want to remove the value of an environment variable from your solution before exporting the solution. Then, the existing value will remain in your development environment, but won't be exported in the solution. This approach allows a new value to be provided while importing the solution into another environment.
To remove the value, follow these steps:
- In the solution where the environment variable is located select the environment variable to display the properties.
- Under Current Value, select ... > Remove from this solution.
Can I use environment variables in custom connectors?
Power Apps Blog: Environment variables available in preview! EnvironmentVariableDefinition table/entity reference Web API samples Create Canvas app from scratch using Dataverse. Create a flow with Dataverse Environment variable support in custom connectors