Azure Managed DevOps Pool (MDP) is Microsoft’s fully managed solution for hosting Azure DevOps build agents securely in your Azure Virtual Network. One of its most powerful features is, undoubtedly, the ability to schedule when agents are available in standby mode, allowing you to optimize both performance and cost. For a comprehensive explanation of Azure Managed DevOps Pool fundamentals, you can refer to my previous article: Azure Managed DevOps Pool – Terraform. In this guide, I’ll show you how to implement efficient agent scheduling using Terraform to ensure your CI/CD pipelines run smoothly while minimizing unnecessary resource usage.
Understanding Agent Scheduling in Azure Managed DevOps Pool
When you create a Managed DevOps Pool, the “Standby agent mode” is off by default. This means there are no standby agents immediately available for your pipelines, which might result in wait times of up to 15 minutes for an agent to be provisioned on demand.
For better performance, you can enable standby agent mode and configure a schedule that provides the right capacity based on your workload patterns. When a standby agent schedule is configured, Managed DevOps Pools periodically compares the count of provisioned agents with the standby agent count specified in your provisioning scheme, starting new agents as required to maintain your desired count.
Status of the Azure Managed DevOps Pool Agent Scheduling deployment & test pipeline
Benefits of Agent Scheduling in Azure Managed DevOps Pools
Implementing proper agent scheduling provides several key advantages for your DevOps infrastructure:
- Cost Optimization: Significantly reduce expenses by ensuring agents run only when needed and automatically scale down during off-hours.
- Performance Improvement: Have agents ready during peak hours to eliminate waiting time for pipeline runs.
- Resource Efficiency: Match agent availability precisely to your team’s working patterns across different time zones.
- Automated Management: Eliminate the need for manual scaling or management of agent infrastructure.
Setting Up Agent Scheduling in Terraform for Azure Managed DevOps Pool
When implementing Managed DevOps Pool Agent Scheduling through Terraform, you’ll need to add a specific variable to your configuration that defines when and how many agents should be available in standby mode. This powerful scheduling capability is implemented using the following structure:
variable "agent_profile_resource_predictions" {
description = "Values for agents scheduling"
default = {
time_zone = "UTC"
days_data = [
# Sunday
{},
# Monday
{
"06:00:00" = 1
"08:00:00" = 2
"18:00:00" = 0
},
# Tuesday
{
"06:00:00" = 4
"08:00:00" = 2
"18:00:00" = 1
"20:00:00" = 0
},
# Wednesday
{
"06:00:00" = 1
"08:00:00" = 2
"19:00:00" = 1
"22:00:00" = 0
},
# Thursday
{
"06:00:00" = 1
"08:00:00" = 2
"17:00:00" = 0
},
# Friday
{
"06:00:00" = 1
"08:00:00" = 2
"18:00:00" = 1
"20:00:00" = 0
},
# Saturday
{}
]
}
}
This variable is structured as follows:
- A time zone setting (UTC)
- An array representing each day of the week (index 0 = Sunday, 6 = Saturday)
- For each day, a map of time entries where:
- The key is the start time in 24-hour format
- The value is the number of agents to provision at that time
For example, looking at Friday’s configuration:
- At 6:00 AM, 1 agent is provisioned
- At 8:00 AM, the count increases to 2 agents
- At 6:00 PM (18:00), it reduces to 1 agent
- At 8:00 PM (20:00), all agents are shut down (0 agents)
The empty maps for Saturday and Sunday indicate that no agents are needed on weekends.
Managing Different Needs Across Days
One of the most powerful aspects of this approach is the ability to tailor your agent availability to different needs on different days:
- Heavy development days: Configure more agents during core working hours
- Release days: Ensure higher capacity when you expect deployment activity
- Low activity periods: Scale down to zero during nights or weekends
- Regional needs: Adjust time zones to match your global team distribution
Complete Sample Code for Azure Managed DevOps Pool Scheduling
As always, on my blog, you can find ready-to-use code for implementing this solution. The complete Terraform configuration is available in my GitHub repository, where you’ll find not just the scheduling component but the entire setup for the Azure Managed DevOps Pool with proper networking, security configurations, and integration with Azure DevOps.
Conclusion: Optimizing Your Azure DevOps Infrastructure
In conclusion, implementing agent scheduling for Azure Managed DevOps Pools with Terraform provides a powerful way to optimize your CI/CD infrastructure. By using the variable structure shown in this article and implementing the transformation logic in your Terraform code, you can create sophisticated scheduling patterns that balance performance needs with cost efficiency.
This approach aligns perfectly with Infrastructure as Code principles, hence keeping your agent scheduling configuration version-controlled alongside your other infrastructure components. The result is, undoubtedly, a more efficient, cost-effective pipeline environment that scales to meet your needs exactly when required.
In summary, by implementing agent scheduling, you’re taking an important step toward optimizing your DevOps resources and ensuring your development team has the right tools at the right time. This leads to faster build times, reduced costs, and, moreover, more efficient use of your Azure resources.
Don’t forget to follow me on LinkedIn and share your comments on my posts to help foster community collaboration and learning in the Azure DevOps ecosystem!