Microsoft Fabric is analytical compute capacity shared between workloads such as Spark, SQL data warehouse, SQL database, Power BI and others.
You are charged for the potential compute you can call upon. If you are not using this compute, you can pause it to avoid being charged. But there’s not an auto-terminate option in the service. There is no schedule you can set to pause Fabric outside required hours.
But there are ways you can achieve this using other Azure services. Pipelines and Logic Apps are two ways I have read but I have yet to try those because this sort of activity is a natural fit for Azure Automation Runbooks.
We’re going to create a job in an Azure Runbook. This is an automated task or script to manage our cloud system.
You can achieve the following through code but here’s how to do it through the Azure Portal.
Create a new Azure Automation Account. This provides the environment and resources needed to run and manage Runbooks.
In Azure Automation, a runbook is a collection of tasks or processes designed to automate repetitive IT tasks. When a runbook is executed, it creates a job. A job represents a single execution instance of that runbook, with its own unique status, logs, and output.
Each time you start a runbook, a new job is created, allowing you to monitor its progress and results.
Luckily, there are ready-made runbooks to import from a gallery and one such ready-made runbook is to pause Fabric capacity. However you’ll need to tweak it in order for it to work.
First, in the Azure Automation Account menu, click Runbooks
and then select Import a runbook.
Click Browse from gallery and the blue hyperlink to open the gallery.
Search for “fabric” and you should see the following runbook appear, which you can import.
This is a PowerShell runbook and you can select the version of PowerShell that will be used. Typically, you’d choose the recommended version. Also give the runbook a name and optionally, update the description.
Runbooks are in one of several states and can’t be run until they are published. Our new runbook is in the “New” state at the moment.
Feel free to click the Publish button but you’ll see the runbook annoyingly remains in the New state without it being clear what is preventing it from being published.
What you’ll need to do is edit the PowerShell code, typically in the Azure Portal as it only needs a minor tweak.
You can do anything to the code, for example something as simple as adding a space to the end of a command line, in order to save the code and publish.
Whilst we’re here we might as well add something useful in so change the following line of code from this:
$tokenObject = Get-AzAccessToken -ResourceUrl https://management.azure.com/
to this:
$tokenObject = Get-AzAccessToken -ResourceUrl https://management.azure.com/ -AsSecureString
Azure PowerShell is updated monthly, with up to two annual releases introducing breaking changes. This addition to your runbook code will ensure your code isn’t affected by an upcoming breaking change in the Get-AzAccessToken cmdlet. You can read about those here.
Now you can click Publish and the runbook status will update to Published.
Finally, set up parameters to pass to the code and a schedule to execute the runbook.
Click Link to schedule.
Then Link a schedule to your runbook.
And create a new schedule, for example every weekday at 6pm. It’s possible to create fairly sophisticated schedules and you can read instructions here.
Once that’s done, click Configure parameters and run settings to put in the two parameters the code requires; the resource ID of your Fabric, and the operation which can be suspend or resume.
You can find the resource ID on the properties pane for your Fabric capacity.
Now you have an automation runbook which will run on the schedule you specified to suspend or resume you Fabric capacity.
It’s worth testing the runbook before relying on it. You can do that by clicking Start in the runbook.