Reallocate Workspaces To A Different Fabric Capacity: Low Code Solution
Overview
I’m not saying this blog coincides with the current active Fabric Trials coming to an end, but… What we’re trying to do here is move Workspaces from one Fabric Capacity to another just incase the contents of the workspace allocated to an expiring trial gets deleted…. Also, if we have a lot of workspaces to reallocate then it’s very tedious and time-consuming to manually reallocate each one either through the workspace settings, or via the admin portal. However, the Fabric REST APIs allow us to reallocate a Workspace to another Fabric Capacity (amongst many other actions.
I like using Fabric Pipelines to work with the REST API as it’s very simply to get up and running.
But What About The Trial?
Going back to that whole “trial coming to an end” thing, well at the moment a users current active trial isn’t being extended so if a user has activated a trial previously, it’s likely coming to an end. But, another user in the tenant can start another trial (currently). So we should just be able to start a new trial and move all the workspaces allocated to an existing trial, right? Well, sort of…problem is that the user that started the trial is the only capacity admin on that trial capacity, no-one else can be added (nor can anyone be added as a Capacity contributor). Which means you can’t reallocate a Workspace assigned to a trial capacity, to another trial capacity.
What we can do is reallocate the Workspaces to a non-trial capacity e.g. a Pay As You Go (PAYG) capacity, then reallocate to a new trial capacity created by a second user. All the steps that follow will require the 2 users to be a capacity admin on the “interim” capacity.
As a note, if you’re moving Workspaces to a non-trial capacity then you don’t need the second user steps. We’re only doing this because admin tasks for trial capacities are locked to the user that created the trial.
Walkthough
Let’s go through the steps required to use the Fabric REST API. Now, I’m going to use the Pipelines service with the Web task to send a request to the Fabric API to reallocate the capacity if the Workspace is assigned to my current trial capacity. Of course you can use the Fabric REST API in other ways too but if you’re not able to use the Fabric REST API programmatically I find this a pretty simple method.
Prerequisites
- An F2 Capacity created in Azure
- 2 user accounts in Fabric
- Each user account should have a Fabric trial activated
- Each user needs to be a capacity admin of the F2 capacity
- Each user needs to have contributor or admin permissions on Workspaces that need reallocating
Retrieve Capacity IDs
We need the Fabric Capacity ID of the 2 trials and the PAYG capacity, we can do this in the Fabric Admin portal (or via REST API, but I want to show you the ID). Settings > Admin Portal > Capacity Settings. Click the Trial tab and then the gear icon under the ACTIONS column. Make a note of the Capacity ID, do this for the 2 trials and also the PAYG capacity which will be in the Fabric Capacity tab.
Create Connection
Now we need to create 2 connections to the Fabric REST API for both our trial users. To do this:
- On the home page click Settings > Manage connections and gateways
- Click New and select Cloud connection type
- Give the connection a name, E.G Fabric_REST_API
- For the Connection Type, select Web 2
- Base URL: https://api.fabric.microsoft.com/v1
- Token Audience Uri: https://api.fabric.microsoft.com
- Authentication Method: OAuth 2.0
- Click Edit Credentials and login
Repeat the above for the second “new” trial user (will need to login to Fabric using the account). Problem is we cannot trigger the API to move a workspace to a trial capacity with any other user account than the account that created the trial.
At the end of this, you should have 2 connections created for each user.
Create Pipeline
Let’s create a Pipeline to reallocate the Workspaces. We’ll create a process whereby we’ll get a list of all workspaces, then loop through each workspace and if it’s assigned to the “old” trial capacity, it’ll be reallocated to the F2 capacity. Do the following steps with the user that has the trial capacity you need to move away from.
Create Parameters
- In a Workspace assigned to a Fabric Capacity, create a new Data Pipeline
- Create 2 parameters:
- CurrentCapacityID
- NewCapacityID
- For the first run, assign the current trial capacity ID to CurrentCapacityID, and the PAYG F2 capacity ID to NewCapacityID
Create Web Task
- Add a Web Task to the canvas and configure as follows:
- Name: Get List Of Workspaces
- Connection: Select the Web 2 connection created earlier
- Relative URL: /workspaces
- Method: GET
Create ForEach Loop
- Add a ForEach task to the canvas and connect the Web task On Success to this ForEach task
- In Settings:
- Batch Count: 3 (you can also try Sequential if you get errors relating to too many requests)
- Items: @activity(‘Get List Of Workspaces’).output.value
Create Check Process and Reallocate Capacity
- Within the ForEach task, add an If Condition
- Configure the If Condition:
- Activities\Expression: @equals(item().capacityId,toLower(pipeline().parameters.CurrentCapacityID))
- In the True section of the If Condition, add a Web task with the settings:
- Name: Reallocate Capacity
- Connection: Select the Web 2 connection created earlier
- Relative URL: /workspaces/@{item().id}/assignToCapacity
- Method: POST
- Body: {“capacityId”: “@{pipeline().parameters.NewCapacityID}”}
- Headers:
- Name: Content-type
- Value: application/json
Reallocate from Trial to PAYG Capacity
Once the pipeline is in place, run it as the user with the current (expiring) trial. The process will get a list of all workspaces in the tenant, check if a workspace is allocated to the trial capacity, if so it will then trigger the API to reallocate the workspace to the PAYG Fabric capacity.
Reallocate from PAYG Capacity to New Trial
Now, if we want to reallocate the Workspaces to a new trial capacity, we need to login into Fabric using the account that created the new trial. Once logged in:
- Open the existing pipeline
- Modify the CurrentCapacityID and NewCapacityID to reflect the PAYG capacity ID and the new trial capacity ID
- Modify the Web 2 connection to reference the connection created by the user with the new trial
- Run the pipeline