Provisioning of Azure dedicated SQL Pools (formerly Azure SQL DW) with Terraform

Cloud Journeys with Anindita
2 min readFeb 21, 2021

The Azure dedicated SQL pools (formerly Azure SQL data warehouse) instance can be provisioned with HashiCorp Terraform. The building block of Azure SQL datawarehouse resource provisioning is similar to Azure SQL database with the edition name is different.

Prereqisites : Terraform 0.12+

AzureRM: ~>2.0

The building blocks of the Azure SQL dedicated pools in terraform consist of the following resources:

main.tf : The fundamental resource block of Azure SQL DW. Provisions azure resource group, azure SQL server & database.

# Create Azure Resource group

resource “azurerm_resource_group” “DP-300_rg” {

name = “${var.Resource_group}”

location = “${var.location}”

tags = “${var.Resource_group_tags}”

}

# Provision Azure SQL Server

resource “azurerm_sql_server” “example” {

depends_on = [“azurerm_resource_group.DP-300_rg”]

name = “${var.azsqlserver_name}”

resource_group_name = “${var.Resource_group}”

location = “${var.azsqlserver-location}”

version = “12.0”

administrator_login = “${var.azsqlserver-login}”

administrator_login_password = “${var.azsqlserver-login-password}”

tags = {

environment = “dev”

}

}

# Provision Azuere SQL database

resource “azurerm_sql_database” “example” {

depends_on = [azurerm_sql_server.example]

name = “${var.azsqlserverdb-name}”

resource_group_name = “${var.Resource_group}”

location = “${var.azsqlserver-location}”

edition = “${var.azurerm_sql_database_edition}”

server_name = “${var.azsqlserver_name}”

tags = {

environment = “dev”

}

}

variables.tf : The variables of the resource declaration to be defined in this file.

variable “subscription_id” {

type = string

description = “The Subscription Id for Azure account”

}

variable “client_id” {

type = string

description = “The Client Id of the service principal”

}

variable “client_secret” {

type = string

description = “The client secret of the service pricipal”

}

variable “tenant_id” {

type = string

description = “the tenant Id of the directory”

}

variable “Resource_group” {

type = string

description = “The resource group of Azure Firewall resource”

}

variable “location” {

type = string

description = “The location of the resource group”

}

variable “Resource_group_tags” {

type = map(string)

default = {OWNER = “Owner_name”, Origin = “az-database”, ReasonCreated = “certification”}

description = “The Azure Resource group tags”

}

variable “azsqlserver_name” {

type = string

description = “The Azure SQL Server Name”

}

variable “azsqlserver-location” {

type = string

description = “The Azure SQL Server location”

}

variable “azsqlserver-login” {

type = string

description = “The Azure SQL Server login name”

}

variable “azsqlserver-login-password” {

type = string

description = “The Azure SQL Server login password”

}

variable “azsqlserverdb-name” {

type = string

description = “The Azure SQL Server db name”

}

variable “azurerm_sql_database_edition” {

type = string

description = “The Azure SQL database edition”

}

Finally, in the “terraform.tfvars “ file, where the values of the variables to be defined, in the database edition type to be specified as “DataWarehouse”.

azurerm_sql_database_edition = “DataWarehouse”

The entire terraform configuration of Azure SQL DW resource provisioning building blocks are available in the following Github repo:

https://github.com/imcuteani/awesome-terraform-azdata/tree/main/Azure_SQL_DW

#Happy Terraforming!

--

--

Cloud Journeys with Anindita

Cloud Architect. Azure, AWS certified. Terraform & K8, Cloud Native expert. Passionate with GenAI. Views are own.