Posted inFabric

Deploying Fabric Capacity with Terraform

Introduction

During my visit of the Dutch Fabric user group meetup I found at that Fabric Capacity has to be deployed in Azure, not in the Fabric portal. The reason behind this is still unclear to me, and it might give some extra dependencies in large organization, since you don’t have to be fabric administrator, but you also need permissions in Azure.

One of the issues I faced because of this is that in a lot of organizations all Azure Infra has to be deployed with Infra as Code, and quite often a default language has been selected like Bicep, ARM or Terraform. Since terraform doesn’t have a Fabric Capacity resource available (yet) it means that you can’t simply deploy Fabric Capacity with Terraform.

In this blog I’ll describe how you can deploy Fabric Capacity with Terraform, based on the code I’ve found here

Before we start

Now before we start, I made some assumptions. Since Fabric Capacity most likely isn’t the first resource that will be deployed with Terraform, I assume that you already have experience with Terraform and that you are able to deploy infrastructure.

Deploying Fabric Capacity with Terraform

Providers

For most Azure resources, the azurerm provider (hashicorp/azurerm | Terraform Registry) is being used. Since the provider doesn’t have fabric capacity as resource, we will use an other provider, called azapi (Azure/azapi | Terraform Registry). Since this is an layer over ARM Rest API, it means that basically you can deploy anything that you could deploy with ARM. This is especially usefull for preview options, since they are quite often not available in the azurerm provider (yet).

Please note that if you are combining Fabric capacity with other azure resources, you might need multiple providers. The provider code will look as follow:

terraform {
 required_providers {
    azapi = {
      source  = "Azure/azapi"
    }
  }
}

Or in case of multiple providers:

terraform {
 required_providers {
    azapi = {
      source  = "Azure/azapi"
    }
    azurerm = {
      source  = "hashicorp/azurerm" 
    }
  }
}

provider "azurerm" {
  skip_provider_registration = "true"
  storage_use_azuread = true
  features {}
}

The Fabric capacity resource

Ok, now coming to the actual code. The resource is for azapi is azapi_resource, where the type is the Microsoft.Fabric/capacities@2023-11-01. For the name, only lowercase letters and numbers may be used. It must also be unique in the region. The parent_id is the resource group id, location the azure region. Make sure you have schema_validation_enabled set to false, or else the following error will be trown:

Error: embedded schema validation failed: the `type` is invalid.
│ resource type Microsoft.Fabric/capacities can’t be found.

In the body, we can add the Capacity administrators based on their UPN with properties -> administration -> members. And then add the SKU (for available sku’s see here: Microsoft Fabric – Pricing | Microsoft Azure). The tier is always Fabric.

resource "azapi_resource" "this" {
  type                      = "Microsoft.Fabric/capacities@2023-11-01"
  name                      = "fabriccapacityblog"
  parent_id                 = azurerm_resource_group.this.id
  location                  = "westeurope"
  schema_validation_enabled = false

  body = jsonencode({
    properties = {
      administration = {
        members = [
          "youradminemail@mail.com"
        ]
      }
    }
    sku = {
      name = "F2",
      tier = "Fabric"
    }
  })
}

Once the code has successfully been deployed, you can go towards the Azure portal and see Fabric Capacity:

In the Fabric Admin portal, the capacity will also be visible:

Summary

In this blog I’ve described how you can deploy Fabric Capacity with Terraform. It’s a good how-to to deploy preview functions, with terraform. I’m sure that in the future Fabric Capacity will be part of the azurerm provider, but until then this is a good alternative.

Sources

To come to this blog, I’ve used the following sources, used some of the code as inspiration and altered it when I felt that it was required:

One thought on “Deploying Fabric Capacity with Terraform

  1. Hi Remco. Great article! I’d like to add a remark: Microsoft Fabric can also be enabled through Power BI Premium Licenses, either for the entire organization or specific security groups. With Microsoft Fabric Capacity on Azure, organizations are billed by pay-per-use, instead of a fixed monthly rate. Keep up the good work!

    https://learn.microsoft.com/en-us/fabric/enterprise/buy-subscription
    https://learn.microsoft.com/en-us/fabric/admin/fabric-switch

Leave a Reply

Your email address will not be published. Required fields are marked *