From 081e2fc5cd9b03539e9e018dfaf56621ad8cce7c Mon Sep 17 00:00:00 2001 From: stackgen-terraform-bot Date: Tue, 9 Jun 2026 14:24:09 +0000 Subject: [PATCH] feat: update main.tf Closes stackgen-demo/azure_tf_sql_database#8 --- main.tf | 9 ++++---- tests/zone_redundant.tftest.hcl | 39 +++++++++++++++++++++++++++++++++ variables.tf | 6 +++++ 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 tests/zone_redundant.tftest.hcl diff --git a/main.tf b/main.tf index 30bba00..e35e3b0 100644 --- a/main.tf +++ b/main.tf @@ -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 } diff --git a/tests/zone_redundant.tftest.hcl b/tests/zone_redundant.tftest.hcl new file mode 100644 index 0000000..eb3e74f --- /dev/null +++ b/tests/zone_redundant.tftest.hcl @@ -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." + } +} diff --git a/variables.tf b/variables.tf index b1d236c..3d6a75b 100644 --- a/variables.tf +++ b/variables.tf @@ -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)