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

Related blog posts

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

January 28, 2026 by Katie Murray

If you’ve been trying to keep up with everything shipping in Microsoft Fabric, this January 2026 round-up is for you—covering the biggest updates across the platform, from new AI-powered catalog experiences and OneLake governance improvements to enhancements in Data Engineering, Data Warehouse, Real-Time Intelligence, and Data Factory. If you haven’t already, make sure FabCon Atlanta … Continue reading “Fabric January 2026 Feature Summary”

January 22, 2026 by Anna Hoffman

The SQL community is gathering in Atlanta this March for the first‑ever SQLCon, co‑located with FabCon, the Microsoft Fabric Community Conference, March 16-20. One registration unlocks both events, giving you access to deep SQL expertise and the latest in Fabric, Power BI, data engineering, real‑time intelligence, and AI. Whether you’re a DBA, developer, data engineer, architect, or a … Continue reading “Five Reasons to attend SQLCon”