Azure SQL Database Terraform module — parameterised, azurerm 4.x, CI-validated.
Enterprise-grade Azure SQL Database module with comprehensive security, compliance, and performance features.
✅ High Availability - Zone redundancy, geo-redundancy, failover groups, read replicas
✅ Advanced Security - TDE, auditing, threat detection, vulnerability assessment, Azure Policy
✅ Network Security - Private endpoints, VNet integration, firewall rules, service endpoints
✅ Backup & Recovery - Automated backups, retention policies, point-in-time restore, LTR
✅ Performance - Multiple service tiers, auto-scaling, performance insights, query store
✅ Compliance - Azure Policy integration, audit logging, data classification
✅ Identity - Azure AD authentication, managed identities, RBAC
✅ Monitoring - Advanced diagnostics, Log Analytics, Application Insights integration
✅ Testing - Comprehensive Terratest suite with security and performance validation
Pin the module to a release tag:
module "sql_database" {
source = "git::https://github.com/AIRCLOUD-PL/azure-sql-database-module.git?ref=v1.0.0"
# required inputs
environment = "..."
location = "..."
resource_group_name = "..."
}All inputs and outputs are listed in the generated reference below (Inputs, Outputs). Worked examples live in examples/.
module "sql_database" {
source = "git::https://github.com/AIRCLOUD-PL/azure-sql-database-module.git?ref=v1.0.0"
sql_server_name = "sql-prod-westeurope-001"
location = "East US"
resource_group_name = "rg-production"
environment = "prod"
administrator_login = "sqladmin"
administrator_login_password = "P@ssw0rd123!"
databases = {
"appdb" = {
sku_name = "GP_Gen5_2"
max_size_gb = 32
}
}
tags = {
Environment = "Production"
}
}module "sql_database" {
source = "git::https://github.com/AIRCLOUD-PL/azure-sql-database-module.git?ref=v1.0.0"
sql_server_name = "sql-prod-westeurope-001"
location = "East US"
resource_group_name = "rg-production"
environment = "prod"
# Authentication
administrator_login = "sqladmin"
administrator_login_password = "P@ssw0rd123!"
azuread_administrator = {
login_username = "sql-admin@domain.com"
object_id = "00000000-0000-0000-0000-000000000000"
}
# Security Configuration
public_network_access_enabled = false
minimum_tls_version = "1.2"
enable_advanced_threat_protection = true
enable_vulnerability_assessment = true
enable_extended_auditing_policy = true
# Identity
identity_type = "SystemAssigned"
# Private Endpoints
private_endpoints = {
sql_server = {
subnet_id = azurerm_subnet.database.id
private_dns_zone_ids = [
azurerm_private_dns_zone.sql.id
]
}
}
# High Availability Databases
databases = {
"appdb" = {
sku_name = "BC_Gen5_4"
max_size_gb = 100
zone_redundant = true
read_scale = true
read_replica_count = 1
transparent_data_encryption = {
enabled = true
}
short_term_retention_policy = {
retention_days = 35
backup_interval_in_hours = 12
}
long_term_retention_policy = {
weekly_retention = "P12W"
monthly_retention = "P60M"
yearly_retention = "P10Y"
week_of_year = 1
}
}
"reporting" = {
sku_name = "HS_Gen5_2"
max_size_gb = 512
read_replica_count = 1
}
}
# Firewall Rules (for maintenance)
firewall_rules = {
"azure-services" = {
start_ip_address = "0.0.0.0"
end_ip_address = "0.0.0.0"
}
}
# Virtual Network Rules
virtual_network_rules = {
"app-subnet" = {
subnet_id = azurerm_subnet.application.id
}
}
# Diagnostic Settings
enable_diagnostic_settings = true
log_analytics_workspace_id = azurerm_log_analytics_workspace.example.id
diagnostic_settings = {
logs = [
{
category = "SQLSecurityAuditEvents"
enabled = true
},
{
category = "SQLInsights"
enabled = true
}
]
metrics = [
{
category = "Basic"
enabled = true
}
]
}
# Resource Protection
enable_resource_lock = true
lock_level = "CanNotDelete"
tags = {
Environment = "Production"
DataClass = "Confidential"
Compliance = "SOX"
Owner = "Platform Team"
}
}module "sql_database_primary" {
source = "git::https://github.com/AIRCLOUD-PL/azure-sql-database-module.git?ref=v1.0.0"
sql_server_name = "sql-prod-primary"
location = "East US"
resource_group_name = "rg-production"
environment = "prod"
administrator_login = "sqladmin"
administrator_login_password = "P@ssw0rd123!"
databases = {
"appdb" = {
sku_name = "BC_Gen5_4"
max_size_gb = 100
zone_redundant = true
}
}
}
module "sql_database_secondary" {
source = "git::https://github.com/AIRCLOUD-PL/azure-sql-database-module.git?ref=v1.0.0"
sql_server_name = "sql-prod-secondary"
location = "West US"
resource_group_name = "rg-production"
environment = "prod"
administrator_login = "sqladmin"
administrator_login_password = "P@ssw0rd123!"
databases = {
"appdb" = {
sku_name = "BC_Gen5_4"
max_size_gb = 100
}
}
}
# Failover Group
resource "azurerm_mssql_failover_group" "example" {
name = "sql-failover-group"
server_id = module.sql_database_primary.sql_server_id
databases = [module.sql_database_primary.database_ids["appdb"]]
partner_server {
id = module.sql_database_secondary.sql_server_id
}
read_write_endpoint_failover_policy {
mode = "Automatic"
grace_minutes = 60
}
tags = {
Environment = "Production"
Project = "SQL Database HA"
}
}- Basic - Simple SQL Database with private endpoint
- High Availability - Production-ready HA setup with failover groups
- Transparent Data Encryption (TDE) - Always encrypted data at rest
- Advanced Threat Protection - Real-time security monitoring and alerts
- Vulnerability Assessment - Automated security scanning with email notifications
- Extended Auditing - Comprehensive audit logging to storage/Log Analytics
- Private Endpoints - Secure private connectivity without public exposure
- VNet Integration - Network isolation and service endpoints
- Firewall Rules - Granular IP-based access control
- TLS 1.2 Minimum - Secure data in transit encryption
- Zone Redundancy - Cross-availability zone replication
- Geo-Redundancy - Cross-region failover with automatic failover groups
- Read Replicas - Read scale-out for performance optimization
- Automated Backups - Point-in-time restore with configurable retention
- Azure Policy Integration - Automated compliance enforcement
- Azure AD Integration - Modern authentication with conditional access
- Managed Identity - Secure service-to-service authentication
- Resource Locks - Protection against accidental deletion
- Diagnostic Settings - Comprehensive monitoring and alerting
The module includes comprehensive Terratest suites:
# Run all tests
cd test
go test -v
# Run specific test
go test -run TestSQLDatabaseBasic -v
# Run with parallel execution
go test -parallel 4 -vTest scenarios include:
- Basic SQL Server and database creation
- Security features validation
- Private endpoint connectivity
- High availability configurations
- Backup and retention policies
- Firewall rules and network security
- Resource locks and protection
- Input validation and error handling
Current version: v1.0.0
- Follow the established patterns for enterprise security
- Include comprehensive tests for new features
- Update documentation and examples
- Ensure backward compatibility
MIT
| Name | Version |
|---|---|
| terraform | >= 1.5.0 |
| azurerm | ~> 4.0 |
| Name | Version |
|---|---|
| azurerm | 4.81.0 |
No modules.
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| administrator_login | Administrator login name | string |
null |
no |
| administrator_login_password | Administrator login password | string |
null |
no |
| auditing_policy_log_monitoring_enabled | Enable log monitoring for auditing | bool |
true |
no |
| auditing_policy_retention_in_days | Retention days for auditing logs | number |
30 |
no |
| auditing_policy_storage_account_access_key | Storage account access key for auditing | string |
null |
no |
| auditing_policy_storage_account_access_key_is_secondary | Use secondary storage account access key | bool |
false |
no |
| auditing_policy_storage_endpoint | Storage endpoint for auditing policy | string |
null |
no |
| azuread_administrator | Azure AD administrator configuration | object({ |
null |
no |
| databases | Map of databases to create | map(object({ |
{} |
no |
| diagnostic_settings | Diagnostic settings configuration | object({ |
{ |
no |
| enable_advanced_threat_protection | Enable Advanced Threat Protection | bool |
true |
no |
| enable_diagnostic_settings | Enable diagnostic settings for SQL Server and databases | bool |
true |
no |
| enable_extended_auditing_policy | Enable extended auditing policy | bool |
true |
no |
| enable_policy_assignments | Enable Azure Policy assignments for SQL Database security | bool |
true |
no |
| enable_resource_lock | Enable resource lock for SQL Server and databases | bool |
false |
no |
| enable_vulnerability_assessment | Enable vulnerability assessment | bool |
true |
no |
| environment | Environment name (e.g., prod, dev, test) | string |
n/a | yes |
| failover_group | Failover group configuration | object({ |
null |
no |
| firewall_rules | Map of firewall rules | map(object({ |
{} |
no |
| identity_ids | List of User Assigned Identity IDs | list(string) |
[] |
no |
| identity_type | Type of Managed Identity | string |
"SystemAssigned" |
no |
| location | Azure region where resources will be created | string |
n/a | yes |
| lock_level | Resource lock level: CanNotDelete or ReadOnly | string |
"CanNotDelete" |
no |
| log_analytics_workspace_id | Log Analytics workspace ID for diagnostic settings | string |
null |
no |
| minimum_tls_version | Minimum TLS version | string |
"1.2" |
no |
| naming_prefix | Prefix for SQL Server naming | string |
"sql" |
no |
| primary_user_assigned_identity_id | Primary user assigned identity ID | string |
null |
no |
| private_endpoints | Private endpoint configurations | object({ |
{} |
no |
| public_network_access_enabled | Enable public network access | bool |
false |
no |
| resource_group_name | Name of the resource group | string |
n/a | yes |
| security_alert_policy_disabled_alerts | Disabled alerts for security policy | list(string) |
[] |
no |
| security_alert_policy_email_account_admins | Email account admins for security alerts | bool |
true |
no |
| security_alert_policy_email_addresses | Email addresses for security alerts | list(string) |
[] |
no |
| security_alert_policy_retention_days | Retention days for security alerts | number |
30 |
no |
| sql_server_name | Name of the SQL Server. If null, will be auto-generated. | string |
null |
no |
| sql_version | SQL Server version | string |
"12.0" |
no |
| tags | Tags to apply to all resources | map(string) |
{} |
no |
| virtual_network_rules | Map of virtual network rules | map(object({ |
{} |
no |
| vulnerability_assessment_email_subscription_admins | Email subscription admins for vulnerability scans | bool |
true |
no |
| vulnerability_assessment_emails | Email addresses for vulnerability scans | list(string) |
[] |
no |
| vulnerability_assessment_recurring_scans_enabled | Enable recurring vulnerability scans | bool |
true |
no |
| vulnerability_assessment_storage_account_access_key | Storage account access key for vulnerability assessment | string |
null |
no |
| vulnerability_assessment_storage_container_path | Storage container path for vulnerability assessment | string |
null |
no |
| Name | Description |
|---|---|
| administrator_login | Administrator login name |
| database_ids | Map of database names to database IDs |
| databases | Map of database names to database objects |
| failover_group_id | Failover group ID |
| firewall_rules | Created firewall rules |
| identity | Managed identity block |
| identity_principal_id | Principal ID of the system-assigned managed identity |
| private_endpoint_sql_server_id | SQL Server private endpoint ID |
| sql_server_fqdn | SQL Server fully qualified domain name |
| sql_server_id | SQL Server resource ID |
| sql_server_name | SQL Server name |
| virtual_network_rules | Created virtual network rules |
Browse all modules with usage snippets in the module catalog or on github.com/AIRCLOUD-PL. Built and maintained by AIRCLOUD: DevOps, cloud and AI engineering. Need a hand with Azure landing zones or platform engineering? See aircloud.com.pl/consulting.
