Skip to content

Commit 5ebe019

Browse files
feat(database): add new long_term_retention_policy_time_based_immutability and long_term_retention_policy_time_based_immutability_mode variables (#197)
Co-authored-by: Henrik Knutsen <46495473+hknutsen@users.noreply.github.com>
1 parent ea42aec commit 5ebe019

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

modules/database/main.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ resource "azurerm_mssql_database" "this" {
6060
}
6161
}
6262

63+
resource "azapi_update_resource" "long_term_retention_policy" {
64+
count = var.long_term_retention_policy_time_based_immutability == "Enabled" ? 1 : 0
65+
66+
type = "Microsoft.Sql/servers/databases/backupLongTermRetentionPolicies@2024-11-01-preview"
67+
parent_id = azurerm_mssql_database.this.id
68+
name = "default"
69+
70+
body = {
71+
properties = {
72+
timeBasedImmutability = var.long_term_retention_policy_time_based_immutability
73+
timeBasedImmutabilityMode = var.long_term_retention_policy_time_based_immutability_mode
74+
}
75+
}
76+
}
77+
6378
resource "azurerm_monitor_diagnostic_setting" "database" {
6479
name = var.diagnostic_setting_name
6580
target_resource_id = azurerm_mssql_database.this.id

modules/database/variables.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,26 @@ variable "long_term_retention_policy_week_of_year" {
9797
default = 1
9898
}
9999

100+
variable "long_term_retention_policy_time_based_immutability" {
101+
description = "Whether time based immutability backups are enabled for long-term retention policy. Value must be either 'Enabled' or 'Disabled'."
102+
type = string
103+
default = "Disabled"
104+
validation {
105+
condition = var.long_term_retention_policy_time_based_immutability == "Enabled" || var.long_term_retention_policy_time_based_immutability == "Disabled"
106+
error_message = "The value must be either 'Enabled' or 'Disabled'."
107+
}
108+
}
109+
110+
variable "long_term_retention_policy_time_based_immutability_mode" {
111+
description = "The mode of time based immutability for long-term retention policy. Value must be either 'Locked' or 'Unlocked'. Only effective if long_term_retention_policy_time_based_immutability is enabled"
112+
type = string
113+
default = "Unlocked"
114+
validation {
115+
condition = var.long_term_retention_policy_time_based_immutability_mode == "Locked" || var.long_term_retention_policy_time_based_immutability_mode == "Unlocked"
116+
error_message = "The value must be either 'Locked' or 'Unlocked'."
117+
}
118+
}
119+
100120
variable "identity_ids" {
101121
description = "A list of user assigned identities to be assigned to this SQL database."
102122
type = list(string)

modules/database/versions.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,10 @@ terraform {
77
# Version 4.31.0 is required to use the "enabled_metric" argument for the "azurerm_monitor_diagnostic_setting" resource.
88
version = ">= 4.31.0"
99
}
10+
11+
azapi = {
12+
source = "azure/azapi"
13+
version = ">= 2.0.0"
14+
}
1015
}
1116
}

0 commit comments

Comments
 (0)