Microsoft Fabric Updates Blog

Creating SQL database workload in Fabric with Terraform: A Step-by-Step Guide (Preview)

Infrastructure as Code (IaC) tools like Terraform have revolutionized the way developers and organizations deploy and manage infrastructure. With its declarative language and ability to automate provisioning, Terraform reduces human error, ensures consistency, and speeds up deployment across cloud and on-premises environments. In this document, we’ll explore how you can create SQL databases workloads in Microsoft Fabric using Terraform.

Why Use Terraform for Fabric Workloads?

Terraform, developed by HashiCorp, is a powerful open-source IaC tool that simplifies infrastructure management. It’s particularly useful for creating resources in Microsoft Fabric workloads thanks to its ability to ensure repeatable, scalable, and consistent deployments. Whether you’re scaling applications or updating configurations, Terraform offers a streamlined solution to manage the entire lifecycle of your projects.

Prerequisites

Before diving into creating a SQL database in Fabric, ensure you have the following:

Steps

1. Prepare Your Environment

After downloading Terraform, extract the files to a directory of your choice. Open a command prompt and navigate to this folder. Then, create a new working directory using the following text: mkdir terraform_demo && cd terraform_demo

2. Log In to Fabric

Authenticate Fabric tenant by running the following command: az login –scope https://fabric.microsoft.com/.default

Select your user account and subscription number from the list displayed.

3. Create Required Files

In your terraform_demo folder, create the following files using a notepad, VS Code or any editor of your choice. Each file will contain specific configurations for your SQL database and Fabric workspace.

  • variables.tf: Define variables for workspace name, database name, and capacity.
  • terraform.tfvars: Assign values to the variables defined in variables.tf.
  • workspace.tf: Define the Fabric workspace resource.
  • providers.tf: Specify the required Terraform provider configuration.
  • sqldatabase.tf: Define the SQL database resource to be created.
  • outputs.tf: Output workspace and SQL database identifiers for verification.

Example Content for Files:

File – variables.tf

variable “fabric_workspace_name” {
description = “Name for the Workspace to be created or already exists.”
type = string
}
variable “fabric_sql_database_name” {
description = “Name for the SQL database to be created.”
type = string
}
variable “fabric_capacity_name” {
description = “Fabric capacity where workspace/SQL database need to be created.”
type = string
}

File – terraform.tfvars

fabric_workspace_name = “<Enter workspace Name>”
fabric_sql_database_name = “<Enter SQL database Name”
fabric_capacity_name = “<Enter capacity Name>”

File – workspace.tf:

data “fabric_capacity” “capacity” {
display_name = var.fabric_capacity_name
}
resource “fabric_workspace” “example_workspace” {
display_name = var.fabric_workspace_name
description = “Getting started workspace”
capacity_id = data.fabric_capacity.capacity.id
}

File – providers.tf

terraform {
required_version = “>= 1.8, < 2.0”
required_providers {
fabric = {
source = “microsoft/fabric”
version = “1.2.0”
}
}
}
provider “fabric” {
preview = true
}

File – sqldatabase.tf

resource “fabric_sql_database” “example_sql” {
workspace_id = fabric_workspace.example_workspace.id
display_name = var.fabric_sql_database_name

}

File – outputs.tf

output “capacity_id” {
value = data.fabric_capacity.capacity.id
}
output “sql_database_id” {
value = fabric_sql_database.example_sql.id
}

output “sql_connection_string”{
value = fabric_sql_database.example_sql.properties.connection_string
}

4. Initialize Terraform

In the command prompt, navigate to the folder where you have created the files, as completed in the previous steps.

Run the following command:

..\terraform init

A message will generate confirming that Terraform has been successfully initialized.

5. Create an execution plan

Run the following command:

..\Terraform plan -out main.tfplan

This command will create an execution plan but will not execute it. The optional -out parameter would allow you to create an output file for the plan.

5. Apply Terraform Configuration

Run the following command:

..\terraform apply main.tfplan

This command will review the file created in previous command and apply the configurations.

6. Test and Verify

Log into Microsoft Fabric to verify that the workspace and SQL database have been created.

7. Clean up resources

Run the following command

..\terraform plan -destroy -out main.destroy.tfplan

..\terraform apply main.destroy.tfplan

Conclusion

Using Terraform to create and manage SQL databases in Fabric workloads simplifies the process, ensuring consistent and error-free deployments. By leveraging the power of Infrastructure as Code, you can save time, reduce manual effort, and scale your configurations with ease.

Start your journey with Terraform today and experience the efficiency and reliability it brings to infrastructure management as well as Dev ops.

Terraform Resources for SQL database – fabric_sql_database | Resources | microsoft/fabric | Terraform | Terraform Registry

Entradas de blog relacionadas

Creating SQL database workload in Fabric with Terraform: A Step-by-Step Guide (Preview)

febrero 25, 2026 por Katie Murray

Welcome to the February 2026 Microsoft Fabric update! This month brings a wide range of enhancements across the Fabric platform—from improvements to the OneLake Catalog and developer experiences, to meaningful updates in Data Engineering, Data Factory, Real‑Time Intelligence, and more. Whether you’re building, operating, or scaling solutions in Fabric, there’s plenty here to explore. And … Continue reading “Fabric February 2026 Feature Summary”

febrero 23, 2026 por Anna Hoffman

If you’ve been on X (formerly Twitter) the past two weeks, you’ve probably seen or at least felt the shockwaves. Matt Shumer, CEO of HyperWrite and co-founder of OthersideAI, published a 5,000-word essay titled “Something Big Is Happening” that has now been viewed over 73 million times. In it, he compares this moment in AI … Continue reading “Something big IS happening—is your data platform ready?”