File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed
Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff 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+
6378resource "azurerm_monitor_diagnostic_setting" "database" {
6479 name = var. diagnostic_setting_name
6580 target_resource_id = azurerm_mssql_database. this . id
Original file line number Diff line number Diff 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+
100120variable "identity_ids" {
101121 description = " A list of user assigned identities to be assigned to this SQL database."
102122 type = list (string )
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments