How-to guide

Schedule non-production environments on Azure

Learn how to schedule Azure dev, test and staging resources to stop and start on time using tags, Automation runbooks and checks that catch failures.

By the Cloudverg engineering team · · 6 min read

Why this matters

Non-production environments rarely need to run all night. Dev clusters, staging plans and test databases sit idle while Azure keeps billing. A schedule turns those idle hours into savings without ticket queues.

Stopping is not deleting. A deallocated VM stops compute charges, but disks, snapshots and reserved public IPs keep billing. Azure SQL Database has no stop button; serverless auto-pause is the cost control. App Service plans bill for instances even when the app is idle, so scale down or use autoscale schedules.

A schedule also changes operations. Morning starts expose expired secrets, failed migrations and dependency order problems. That is useful, but only if someone watches the start job. Build the schedule around real work and test runs, not a blanket 7 pm stop.

Before you start

List what runs in each non-production subscription. Export resources with Azure Resource Graph, then group by resource group and tags. Add Environment, Owner and AutoOff tags where missing. If tags are inconsistent, fix them first; the scheduler will depend on them.

Split resources into safe to deallocate, needs a native pause, and must stay on. Shared services such as DNS, Key Vault, container registries and CI agents often serve other environments. Keep them out unless you know every consumer.

Decide who owns the schedule. An Azure Automation account with a system-assigned managed identity needs a custom role that allows start and deallocate on target resource groups, not Owner at subscription scope. Define shutdown order: application tier first, data tier second. Start in reverse. Check maintenance windows, backup jobs and test pipelines too. A nightly load test can collide with the stop job. Put exceptions in a tag and make the runbook skip them.

How to do it

Use native controls first. DevTest Labs has auto-shutdown per lab VM. AKS has cluster start and stop. App Service plans and VM scale sets have autoscale schedules. Azure SQL serverless has auto-pause. Native features have fewer moving parts, but each covers one resource type.

For a mixed environment, Azure Automation runbooks are the usual fit. A runbook can read tags, call the right command per resource type and write a clear job log. Azure Functions with a timer trigger works too, but you own the runtime and retries. Logic Apps fits approval flows.

Keep schedules in UTC and make the runbook idempotent. If a VM is already stopped, log it and continue. Stagger start times by tier so a database is ready before the app connects.

  1. Tag the targets. Apply Environment, Owner and AutoOff tags to every resource group and resource you plan to schedule. Use one tag value as the switch, for example AutoOff=true, so the runbook never guesses from names. Exclude shared services with AutoOff=false.
  2. Create an Automation account. Create the account in the region where most targets run. Turn on a system-assigned managed identity and import the Az.Compute, Az.Resources and Az.Automation modules you need. Do not store a service principal secret in a variable.
  3. Grant least privilege. Assign a custom role at resource group scope that allows the exact actions your runbook calls. Include read, start and deallocate for virtual machines, and matching actions for AKS or databases. Keep subscription-level access out of the automation identity.
  4. Write a tag driven runbook. Query resources by tag, group them by type and call Stop-AzVM so each VM is deallocated, not just stopped. Handle AKS, VM scale sets and databases in separate functions so one failure does not stop the whole run. Log every action and every skip.
  5. Add start and stop schedules. Create one schedule for weekday mornings and one for evenings, in UTC, and link both to the runbook with a mode parameter. Stagger the start schedule by tier with separate runbooks or a delay parameter. Check daylight saving changes against local work hours twice a year.
  6. Wire alerts to the job. Add an Azure Monitor alert on failed Automation jobs and send it to an action group that reaches the owning team. Route job logs to a Log Analytics workspace. Search for skipped resources and failed starts after each run.
  7. Run a dry run. Trigger the stop runbook manually during a quiet window and confirm every target reaches Stopped (deallocated) or its native paused state. Start it again and run a smoke test on the first app developers use. Fix dependency order before you enable the daily schedule.
  8. Publish an override path. Document an override tag and a short request process for late test runs or release nights. Have the runbook check the tag at run time, not in a separate spreadsheet. Tell developers where the schedule lives.

How to check it worked

Open the runbook job history in the Automation account. A successful job is not enough; read the output and confirm each resource was stopped, skipped or failed. For VMs, the power state must read Stopped (deallocated). Stopped without deallocated can still bill compute.

Use Azure Resource Graph to query tagged resources and power states across subscriptions. Check AKS provisioning state, database status and App Service plan instance count. Record the expected state per tier so a missing resource stands out.

Check Cost Management by resource group and tag the next day. Cost data lands late, so compare a week of daily charts. Look for leftover charges from disks, public IPs, load balancers, snapshots and log ingestion.

Watch the morning start. A green runbook can still produce a broken app. Check the first login, the test suite and any background worker. If a database starts after the app, adjust order or add a retry.

Mistakes to avoid

Treating stop as delete is common. Deallocation leaves disks, NICs, public IPs, load balancers and storage accounts in place, and some bill. Inventory leftovers after the first week and decide what a separate cleanup job should delete.

Scheduling shared services without checking consumers causes outages. Key Vault, DNS, container registries and CI agents may serve other environments. Use an explicit exclude tag and review it monthly.

Timezone drift and missing exceptions cause support calls. Automation schedules run in UTC, so a 7 pm local stop moves by an hour when daylight saving changes. Release nights and long test runs need a documented override that does not require editing the runbook.

Do not let the schedule hide a bad environment. If developers keep overriding the stop job, the work hours or environment size is wrong. Fix the design or resize. A read-only review such as the Cloud cost audit at $4,500/month is one option to rank remaining waste; native schedules, autoscale and cleanup jobs are others.

Frequently asked questions

Can I schedule Azure VMs to start and stop without Azure Automation?

Yes. DevTest Labs has auto-shutdown per lab VM, and VM scale sets and App Service plans support autoscale schedules. These native options cover one resource type each. For mixed environments, a runbook is usually simpler than several disconnected schedules.

Does stopping an Azure VM remove all charges?

No. A deallocated VM stops compute charges, but OS and data disks, snapshots, reserved public IP addresses and load balancers can still bill. Storage accounts and Log Analytics ingestion also continue. Check leftover resources after the first stop cycle.

How do I keep a non-production database available during a scheduled stop?

Use native pause features where they exist, such as serverless auto-pause for Azure SQL Database or stop and start for Azure Database for PostgreSQL Flexible Server. For databases without a stop control, leave the database running and schedule the application tier instead. Test start order so the app does not connect before the database is ready.

Monthly plan

Want help with this? Cloud cost audit

$4,500/month

2 weeks · Starts within 10 business days

A two-week, read-only review of your AWS, Azure, Google Cloud or Oracle bill, with every saving ranked by dollars per month.

Renews monthly. Cancel any time.
What is included

Related guides

More cloud costs guides   Cloud cost audit

Smallest way to start

Get a senior architect on your problem this week

Ninety minutes a month on the cloud, AI or security question that is blocking you, a pre-read of your material and a written summary within two business days.

$450/month

Renews monthly. Cancel any time.