Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ resource "azurerm_mssql_server" "this" {
}

resource "azurerm_mssql_database" "this" {
name = var.database_name
server_id = azurerm_mssql_server.this.id
sku_name = var.sku_name
max_size_gb = var.max_size_gb
name = var.database_name
server_id = azurerm_mssql_server.this.id
sku_name = var.sku_name
max_size_gb = var.max_size_gb
zone_redundant = var.zone_redundant

tags = var.tags
}
Expand Down
39 changes: 39 additions & 0 deletions tests/zone_redundant.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Unit tests for the zone_redundant variable on the SQL database module.
# Uses mock_provider for azurerm so no real cloud calls are made.

mock_provider "azurerm" {}

variables {
server_name = "test-sql-server-xyz"
database_name = "testdb"
admin_login = "sqladmin"
admin_password = "P@ssw0rd1234!"
}

run "zone_redundant_defaults_to_false" {
command = plan

assert {
condition = var.zone_redundant == false
error_message = "zone_redundant must default to false to preserve existing behaviour."
}

assert {
condition = azurerm_mssql_database.this.zone_redundant == false
error_message = "azurerm_mssql_database.this.zone_redundant should be false when the variable is unset."
}
}

run "zone_redundant_can_be_enabled" {
command = plan

variables {
zone_redundant = true
sku_name = "P1"
}

assert {
condition = azurerm_mssql_database.this.zone_redundant == true
error_message = "azurerm_mssql_database.this.zone_redundant should be true when var.zone_redundant = true."
}
}
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ variable "max_size_gb" {
default = 2
}

variable "zone_redundant" {
description = "Whether the database is zone redundant (spans multiple Availability Zones). Only supported on Premium and Business Critical service tiers, and General Purpose / Hyperscale tiers in supported regions."
type = bool
default = false
}

variable "tags" {
description = "Tags to apply to resources"
type = map(string)
Expand Down