Easily scale up or scale down your Fabric Capacity using Power Automate (Via email)

Following on from my previous blog post (Stop and start your Fabric Capacity using Power Automate) I got a question from Tristan as shown below!

I always enjoy a good challenge and I got it working! In this blog post I will use the same method where I am sending an email to scale up or scale down my Fabric Capacity.

The good news is that this works if the Capacity is paused or running (It might take a bit more time when running).

Fabric Capacity Details

Before completing the Power Automate flow, I first needed to get the Fabric Capacity details which I will use in the flow steps.

I logged into the Azure Portal and went to my existing Fabric Capacity, and I then got the following details:

  • Subscription
    • MVP
  • Resource Group
    • MVPN-RG_Demo
  • Resource Name which is also my Fabric Capacity Name
    • f2ause

This is what it looks like in the Azure Portal.

Granting Permissions to the Service Principal account

I wanted to use a Service Principal account for authentication, this makes it secure and also removes user access to the Fabric Resource.

To do this I did the following:

  • I went to my Fabric Capacity Resource.
  • I then clicked on Access control (IAM)
    • A screenshot of a computer

Description automatically generated
  • I clicked on Add role assignment
    • A screenshot of a computer

Description automatically generated
  • In the role assignment screen I then clicked on “Privileged administrator roles”
    • A screenshot of a computer

Description automatically generated
  • Next, I selected Contributor and clicked Next.
    • A screenshot of a computer

Description automatically generated
  • On the next screen, I made sure the following was selected
    • A screenshot of a computer

Description automatically generated
    • 1. User, group or service principal
    • 2. I then clicked on Select members.
  • I then searched for my service principal and selected it
    • A screenshot of a computer

Description automatically generated
  • I then clicked on Review + assign and assigned the service principal.
  • I could then see my service principal in the Access control (IAM)

Creating the Flow

What I then did was to create the flow with the following steps as explained below.

  • The first step I created was to look for an email sent to myself where in the Subject Line it contains “Scale Capacity:”
    • NOTE: Because I am extracting the values directly after the start of the subject “Scale Capacity:” make sure to keep it in the same format both for the flow and when sending the email.
  • The next step is where I am searching for the subject to only extract the Capacity size
    • A screenshot of a computer

Description automatically generated
    • The code I am using is the following
      • trim(split(split(triggerBody()?['subject'],'Scale Capacity:')[1],' ')[0])
    • For example if I wanted to scale it to an F4, my subject in my email would be “Scale Capacity:F4
  • Next, I created some Variables as it is easier to define and populate the variables which can then be re-used in subsequent steps. As well as if I need to use this flow for another capacity, I can just update the variables.
    • I created the following variables below.
      • Capacity_Size
        • This is using the size I got from the previous step
        • A screenshot of a computer

Description automatically generated
      • VAR Fabric Capacity Name
        • This is my Fabric Capacity Name
        • A screenshot of a computer

Description automatically generated
      • TimeZone
        • This is my local time zone so that I can offset the UTC Time zone which is the default time zone for Power Automate.
        • A screenshot of a computer

Description automatically generated
      • I then added the additional variables below which are needed when scaling the fabric capacity up or down
        • NOTE: All the details are from the Fabric Capacity Details in the previous section.
        • A screenshot of a computer

Description automatically generated
  • I am also using Azure Key Vault, to ensure that no sensitive details are stored in clear text.
    • A screenshot of a computer

Description automatically generated
  • In the next step is where I am going to use the Azure API to scale the Fabric to the size I specified in the subject of my email.
    • 1. This is the URI which is required to connect to the right Azure resources.
      • In here I used my previous variables to pass through the valid details
        • SubscriptionName, ResourceGroupName and FabricCapacityName
    • 2. The Method I needed to use is PATCH
    • 3. The content-type must be set to JSON
    • 4. In the body is where I am specifying that it is an SKU and the name is the size of the SKU.
      • Which in my example is an F4
    • There are also the authentication details below, which in my example I used my Service Principal.
  • I then put in a delay as it sometimes can take some time for the scaling to complete.
    • A white background with black text

Description automatically generated
  • Next I wanted to confirm what the status of my Fabric Capacity is.
    • To do this, I created the following step to check the status.
    • I searched for “Read a Resource”
      • A screenshot of a computer

Description automatically generated
    • As shown below I selected my Subscription from the dropdown menu.
    • I also selected the Resource Group from the dropdown menu.
    • I also selected the Resource Provider from the dropdown menu.
    • For the Shortcut Resource Id, I put in “capacities/” and then selected my variable called “FabricCapacityName” from above.
    • And finally, I put in the Client API Version which is “2023-11-01”
    • A screenshot of a computer

Description automatically generated
  • The steps was to send an email out the status of the Capacity so that I can confirm the size.
    • Then in the send email step I put in the following details
    • A screenshot of a computer

Description automatically generated
    • Number 1 is where I am inserting the Status check from the Capacity with the code below.
      • body('Check_Fabric_Capacity_Status_Again')?['properties']?['state']
    • Number 2 is where I am getting the SKU Size
      • body('Check_Fabric_Capacity_Status_Again')?['sku']?['name']
    • Number 3 is where I am getting the status of the Capacity
      • body('Check_Fabric_Capacity_Status_Again')?['properties']
    • Number 4 is where I am then using my variable from earlier called “TimeZone” to offset the DateTime so that is current for my time zone, which is GMT + 10 (I like to live in the future!)
      • addHours(utcNow(), variables('TimeZone'))
    • Number 5 is where I am getting the SKU Size
      • body('Check_Fabric_Capacity_Status_Again')?['sku']?['name']
  • I then saved my Flow.

Testing the Flow

The final steps are to test the flow to make sure that it will start or stop as expected when I send the email.

  • The first email test is to scale up the capacity.
    • A screenshot of a computer

Description automatically generated
    • The flow then ran, and I got the following email back giving me the Capacity Status and size
      • A close-up of a computer screen

Description automatically generated
    • I also then went into the Azure Portal to make sure that it had indeed scale to the specified size.
      • A screenshot of a computer

Description automatically generated

Summary

In this blog post, I have shown you how to scale your Fabric Capacity

I hope you found this blog post useful.

And if you have any questions or suggestions, peace in the comments below.

Here is the link to the flow I created if you wanted to use this in your organization.

FourMoo_FabricCapacity-ScaleUporDown.zip

Thanks for reading!