Enable Dynamic Configuration and Feature Flags
Estimated time: 45 minutes
You will learn how to use Azure App Configuration to manage application settings and feature flags centrally. You'll explore how modern cloud applications can benefit from centralized configuration management and dynamic feature toggling without requiring application redeployment.
Before you start
You need:
- Microsoft Edge or an Azure DevOps supported browser
- Azure subscription: You need an active Azure subscription or can create a new one
- Azure DevOps organization: Create one at Create an organization or project collection if you don't have one
- Account permissions: You need a Microsoft account or Microsoft Entra account with Contributor or Owner role in the Azure subscription
About Azure App Configuration
Azure App Configuration provides a service to manage application settings and feature flags centrally. Modern programs, especially those running in a cloud, generally have many distributed components. Spreading configuration settings across these components can lead to hard-to-troubleshoot errors during application deployment. Use App Configuration to store all the settings for your application and secure their access in one place.
Key benefits include:
- Centralized management of application settings and feature flags
- Dynamic configuration changes without application restart
- Feature flag management for controlled feature rollouts
- Point-in-time configuration snapshots for rollback scenarios
- Integration with Azure Key Vault for sensitive settings
Create and configure the team project
First, you'll create an Azure DevOps project for this lab.
- In your browser, open your Azure DevOps organization
- Click New Project
- Give your project the name eShopOnWeb
- Choose Scrum on the Work Item process dropdown
- Click Create
Import the eShopOnWeb Git Repository
Next, you'll import the sample repository that contains the application code.
- In your Azure DevOps organization, open the eShopOnWeb project
- Click Repos > Files
- Click Import
- In the Import a Git Repository window, paste this URL:
https://github.com/MicrosoftLearning/eShopOnWeb.git
- Click Import
The repository is organized this way:
- .ado folder contains Azure DevOps YAML pipelines
- src folder contains the .NET 8 website used in the lab scenarios
- Go to Repos > Branches
- Hover on the main branch then click the ellipsis on the right
- Click Set as default branch
Import and run CI/CD Pipelines
You'll import CI/CD pipelines to build and deploy the eShopOnWeb application. The CI pipeline is prepared to build the application and run tests. The CD pipeline will deploy the application to an Azure Web App.
Import and run the CI pipeline
Let's start by importing the CI pipeline named eshoponweb-ci.yml.
- Go to Pipelines > Pipelines
- Click Create Pipeline (if there are no pipelines) or New pipeline (if there are already created pipelines)
- Select Azure Repos Git (Yaml)
- Select the eShopOnWeb repository
- Select Existing Azure Pipelines YAML File
- Select the main branch and the /.ado/eshoponweb-ci.yml file
- Click Continue
- Click the Run button to run the pipeline
- Your pipeline will take a name based on the project name. Let's rename it for better identification
- Go to Pipelines > Pipelines and click on the recently created pipeline
- Click on the ellipsis and Rename/Remove option
- Name it eshoponweb-ci and click Save
Import and run the CD pipeline
Let's import the CD pipeline named eshoponweb-cd-webapp-code.yml.
- Go to Pipelines > Pipelines
- Click New pipeline
- Select Azure Repos Git (Yaml)
- Select the eShopOnWeb repository
- Select Existing Azure Pipelines YAML File
- Select the main branch and the /.ado/eshoponweb-cd-webapp-code.yml file
- Click Continue
- In the YAML pipeline definition, set the variable section:
- resource-group: the name of the resource group, for example rg-az400-container-NAME (replace NAME)
- location: the name of the Azure region, for example southcentralus
- templateFile: 'infra/webapp.bicep'
- subscriptionid: your Azure subscription id
- azureserviceconnection: 'azure subs'
- webappname: the globally unique name of the web app, for example az400-webapp-NAME
- Click Save and Run
- Open the pipeline and wait for it to execute successfully
Important: If you see the message "This pipeline needs permission to access resources before this run can continue", click on View, Permit and Permit again.
- Rename the pipeline to eshoponweb-cd-webapp-code for better identification
Create Azure App Configuration service
You'll create the Azure App Configuration service to centrally store the application configuration and feature flags.
- In the Azure portal, search for App Configuration and click Create app configuration
- Select or create a resource group
- Specify the location for the app configuration resource
- Enter a name for the configuration store (must be globally unique)
- Select the Standard pricing tier for this lab (required for feature flags)
- Click Review + create then Create
- Once the resource is created, go to the resource
Set up configuration keys in App Configuration
You'll add configuration keys that your application will consume.
- In the left pane of the App Configuration service, select Configuration explorer
- Click Create > Key-value and add:
- Key: eShopOnWeb:Settings:ShowPipelineInfo
- Value: true
- Label: leave empty
- Content type: leave empty
- Click Apply and repeat the process to add these keys:
- Key: eShopOnWeb:Settings:ShowImageDevVersion, Value: false
- Key: eShopOnWeb:Settings:ShowImageProdVersion, Value: true
Set up feature flags in App Configuration
You'll create feature flags to control application features dynamically.
- In the left pane of the App Configuration service, select Feature manager
- Click Create and add:
- Enable feature flag: checked
- Feature flag name: ShoppingCart
- Label: leave empty
- Description: Enable the shopping cart feature
- Click Apply
- Repeat to create another feature flag:
- Feature flag name: Pipeline
- Description: Enable the pipeline information display
Configure the application to use App Configuration
You'll modify the application to connect to Azure App Configuration.
Add App Configuration connection string
- In the Azure portal, go to your App Configuration resource
- Select Access keys from the left menu
- Copy the Primary connection string
- Go to your Azure Web App resource (created by the CD pipeline)
- In the left menu, select Configuration
- Click New application setting and add:
- Name: ConnectionStrings:AppConfig
- Value: [paste the App Configuration connection string]
- Deployment slot setting: leave unchecked
- Click OK then Save
Update application code
The sample application is already configured to use Azure App Configuration. The key integration points are:
-
Program.cs - The application is configured to use App Configuration:
builder.Host.ConfigureAppConfiguration((hostingContext, config) => { var settings = config.Build(); config.AddAzureAppConfiguration(options => { options.Connect(settings.GetConnectionString("AppConfig")) .UseFeatureFlags(); }); });
-
Views - The application uses feature flags to conditionally show content:
<feature name="ShoppingCart"> <div>Shopping cart feature is enabled!</div> </feature>
Test dynamic configuration and feature flags
You'll test the dynamic configuration capabilities by changing settings without redeploying the application.
Test configuration changes
- Navigate to your deployed web application URL
- Observe the current display of pipeline information
- Go back to App Configuration in the Azure portal
- In Configuration explorer, find the eShopOnWeb:Settings:ShowPipelineInfo key
- Change its value from true to false
- Click Apply
- Refresh your web application (may take up to 30 seconds to refresh)
- Notice that the pipeline information is no longer displayed
Test feature flag changes
- In your web application, observe whether the shopping cart feature is displayed
- Go back to App Configuration in the Azure portal
- In Feature manager, find the ShoppingCart feature flag
- Toggle its state (enable/disable)
- Click Apply
- Refresh your web application
- Notice that the shopping cart feature appears or disappears based on the flag state
Advanced feature flag scenarios
Feature flags support more advanced scenarios:
Conditional activation
- In the Azure portal, go to your App Configuration Feature manager
- Click on the Pipeline feature flag
- Click Add filter
- Select Targeting filter
- Configure percentage-based rollout:
- Default percentage: 50
- Groups: Leave empty for this demo
- Click Apply
This configuration will show the feature to 50% of users randomly.
Time-based activation
- Create a new feature flag called SpecialOffer
- Add a Time Window filter
- Set a start and end time for when the feature should be active
- This allows you to automatically enable/disable features based on time
Monitor App Configuration usage
You can monitor how your application uses App Configuration:
- In the Azure portal, go to your App Configuration resource
- Select Monitoring from the left menu
- Click Metrics to see:
- Requests - Number of configuration requests
- Throttled requests - Requests that were throttled
- Storage utilization - How much storage is being used
Clean up resources
Remember to delete the resources created in the Azure portal to avoid unnecessary charges:
- Delete the resource group containing your App Configuration and Web App resources
- In the Azure portal, navigate to your resource group
- Click Delete resource group
- Type the resource group name to confirm deletion
- Click Delete
Summary
In this lab, you learned how to:
- Enable dynamic configuration using Azure App Configuration
- Manage feature flags for controlled feature rollouts
- Configure applications to consume centralized configuration
- Test configuration changes without application redeployment
- Implement advanced feature flag scenarios like percentage rollouts and time-based activation
Azure App Configuration provides a powerful way to manage application settings and feature flags centrally, enabling dynamic configuration changes and controlled feature rollouts without requiring application redeployment. This leads to more flexible and maintainable cloud applications.