Fabric101_CreateFabricCapacity_00

Microsoft Fabric 101 Episode 2: Creating Fabric Capacity using portal and Terraform

Welcome to Microsoft Fabric 101 series – your comprehensive guide to mastering Microsoft Fabric. This series of articles and videos (can be found in the end of this article) is designed to help you understand and effectively use Microsoft Fabric, whether you’re a beginner or looking to deepen your knowledge. We’ll cover everything from the basics of setting up and configuring your Fabric tenant to advanced features and best practices.

Prerequisite articles:

Series:
YT:https://www.youtube.com/playlist?list=PLeYDxzh-xRvag-65pBaucGGlcf1W_8STt5
Blog: https://pl.seequality.net//?s=fabr0ic+101
Let’s get started on this exciting journey!

Today, we will try to create Microsoft Fabric capacity using two different approaches: the Azure portal and Terraform. Let’s start with the first one. Before we create it, we have to register the resource provider for Microsoft Fabric for the subscription where our capacity will be located. What is an Azure Resource Provider? It is a set of REST operations that enable functionality for a specific Azure service—in this case, Fabric. Enabling providers is pretty simple; you can do it programmatically or using the GUI by selecting the proper subscription and then the Resource Provider tab, as shown below:

In the new window, simply find Microsoft.Fabric and click Register. As you can see below, there are some services that contain the word “fabric” in their names, so please ensure that you select the correct one:

If the Azure Resource Provider is registered, then we can start creating our Fabric Capacity. To do this, simply use the search box in the portal and type “Microsoft Fabric.” The well-known icon of Fabric should be visible, so please select it:

 

Now, like for any other Azure resources, click Create to open a “wizard” that will lead you through the process of resource creation:

Creating Fabric is a very similar experience to that of other resources. You will need to choose:

  • Subscription: The subscription where the capacity will be located.
  • Resource Group: The resource group where the capacity will be located.
  • Capacity Name: A unique name that will identify the capacity. Choose it carefully because it will be visible in the Power BI/Fabric portal.
  • Region: The region where the capacity will be located. Be aware that Fabric is not available everywhere; you can find the supported regions in the official documentation (link). Choose it according to your location and your company policy.
  • SKU: Probably the most important option. The right SKU gives you the proper level of performance, but better performance equals higher cost. Here, you have to consider your strategy because you can have a fixed-size capacity and prepare an Azure reservation to pay less, or pause/resume and scale up/scale down as needed. Also, be aware that for Enterprise features (like Private Endpoints, Copilot, etc.) and to allow your report consumers not to need an additional license (like in Power BI Premium PSKU), you need at least an F64 SKU. More about feature availability can be found in the documentation. For testing, it’s recommended to choose the smallest possible SKU to save money.
  • Fabric capacity administrator: Person or service principal that will be assigned to this capacity as an administrator. Unfortunately, we cannot assign security groups here for now.

The next screen is typical and gives you the possibility to assign tags, which can be useful for grouping costs or assigning metadata to your capacity:

 

That is all; you can click Create and after a few moments, it will be available for you:

You can create as many capacities as you want; they will be visible like any other Azure resources.

When you open this, you will see the option to Pause and Resume. For testing purposes, don’t forget to pause any unused capacity. As mentioned previously, please be aware that when you reserve some capacity to get a discount, you cannot Pause and Resume.

Our capacity is ready, so we can log in to the Fabric/Power BI Admin portal. There, under Capacity settings, you can see the created capacities. Please note that capacities that are paused cannot be configured from the Admin portal. You must resume them first, and then they will be configurable from the Admin portal. To configure it, just click the name to see all the settings.

 

 

Create Fabric capacity with Terraform

Of course, instead of manually creating Fabric capacity, you can also do it automatically. I will demonstrate how to achieve that using a simplified Terraform script. Please be aware that this post will not explain the Terraform concept—just show how to simply automate Fabric deployment.

First of all, I will show you what files consist of our simple project:

  • main.tf: Main Terraform file where we will have all the code and modules.
  • variables.tf: Separate file to keep parameterized values.

Of course, you can have a much more complex structure of files, but for our purposes, this is more than enough. In the variables file, we will have only three values:

  • location: Azure region where we want to place our Fabric Capacity. In my case, I chose Sweden Central.
  • sku: SKU for Fabric, which for testing, I chose F2.
  • admin_email: Every capacity must have an admin assigned to it, so I assigned my own email.

 

variable "location" {
  type        = string
  description = "Location of the resource group and modules"
  default     = "Sweden Central"
}

variable "sku" {
  type        = string
  description = "F SKU"
  default     = "F2"
}

variable "admin_email" {
  type        = string
  description = "Admin email address"
  default     = "adrian.chodkowski@seequality.net"
}

main.tf is also very simple in its construction. It contains:

  • azurerm provider: Because we will need it for resource group creation.
  • resource group creation: RG where Fabric capacity will be placed.
  • azure lock: A “do not delete” lock to prevent deletion of a capacity. I recommend adding it because it will secure your capacity from accidental deletion and loss of data.
  • module fabric_capacity: This module was prepared by Azure Data Labs and it creates Fabric Capacity.
terraform {
  required_providers {
    azurerm = {
      version = "= 3.70.0"
    }
  }
}

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "rg" {
  name     = "rg-fabric-tf"
  location = var.location
}

resource "azurerm_management_lock" "rg_lock" {
  name               = "rg-fabric-tf-lock"
  scope              = azurerm_resource_group.rg.id
  lock_level         = "CanNotDelete"
  notes              = "This lock is to prevent accidental deletion of the resource group."
}

module "fabric_capacity" {
  source            = "github.com/Azure/azure-data-labs-modules/terraform/fabric/fabric-capacity"

  basename          = "fabcap01"
  resource_group_id = azurerm_resource_group.rg.id
  location          = var.location

  sku               = var.sku
  admin_email       = var.admin_email
}

When you look at the code on GitHub, you will see that to create resources, it uses the azapi provider. This is because Fabric is not yet implemented in AzureRM, so we have to use azapi, which is a provider that complements AzureRM by enabling the management of Azure resources that are not yet or may never be supported in the AzureRM provider, such as private/public preview services and features. It is a pretty common approach, so you don’t have to worry about it.

And you know what? That’s all regarding coding—let’s try to deploy it. We will do it via the command line, so first, we have to log in to our Azure subscription. For that, we will use Azure CLI:

az login

It will show a login prompt where we can interactively log in. Of course, for automation scenarios such as from Azure DevOps pipelines, we should log in using a service connection, etc., but that is not the point of this article.

If you log in properly, you should see something similar to the picture below. If you have more than one subscription, you can type the number of a subscription (from the “No” column in the list of subscriptions) to set the proper context for the current session.

We are ready to go, so let’s initialize the Terraform project:

terraform init

The response should look like this:

Then we can see what Terraform is going to do (please be aware of the tfstate file concept to fully understand this operation – link):

terraform plan

As you can see below, all the resources will be created. The general recommendation is to perform terraform plan just to have a general idea of what Terraform is going to do. If we agree to the plan, we can create those resources (I added –auto-approve to skip additional approval in the command line):

terraform apply --auto-aprove

After executing the above command, all the resources are created without any problems.

Let’s try to drop the capacity using Terraform. We should get an error because of the “do not delete” lock:

terraform destroy

Simple and effective. Definitely worth checking out. Thank you for reading, and if you prefer watching, you can find the video below. Don’t forget to like and subscribe. Thanks!

 

Leave a Reply