Skip to content

Commit 9e320c3

Browse files
committed
feat: data protection options with variables validation for storage account module
1 parent 25275d9 commit 9e320c3

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

infrastructure/modules/storage/main.tf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,44 @@ resource "azurerm_storage_account" "storage_account" {
1616
days = var.blob_properties_delete_retention_policy
1717
}
1818
versioning_enabled = var.blob_properties_versioning_enabled
19+
20+
container_delete_retention_policy {
21+
days = var.container_delete_retention_policy_days
22+
}
23+
24+
change_feed_enabled = var.blob_properties_change_feed_enabled
25+
26+
dynamic "restore_policy" {
27+
for_each = var.blob_properties_restore_policy_days != null ? [1] : []
28+
content {
29+
days = var.blob_properties_restore_policy_days
30+
}
31+
}
32+
}
33+
34+
dynamic "share_properties" {
35+
for_each = var.share_properties_retention_policy_days != null ? [1] : []
36+
content {
37+
retention_policy {
38+
days = var.share_properties_retention_policy_days
39+
}
40+
}
1941
}
2042

2143
lifecycle {
2244
ignore_changes = [tags]
45+
46+
# Validation 1: Prevent the Change Feed / Restore Policy mismatch
47+
precondition {
48+
condition = var.blob_properties_restore_policy_days == null || var.blob_properties_change_feed_enabled == true
49+
error_message = "Invalid configuration: If blob_properties_restore_policy_days is set, blob_properties_change_feed_enabled must be explicitly set to true."
50+
}
51+
52+
# Validation 2: Prevent the Days limit mismatch
53+
precondition {
54+
condition = var.blob_properties_restore_policy_days == null ? true : (var.blob_properties_restore_policy_days < var.blob_properties_delete_retention_policy)
55+
error_message = "Invalid configuration: blob_properties_restore_policy_days must be strictly less than blob_properties_delete_retention_policy."
56+
}
2357
}
2458
}
2559

infrastructure/modules/storage/variables.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,30 @@ variable "queue_transactions_high_threshold" {
184184
default = 1000
185185
}
186186

187+
variable "container_delete_retention_policy_days" {
188+
description = "Specifies the number of days that the container should be retained. Defaulting to 7 for baseline data protection."
189+
type = number
190+
default = null
191+
}
192+
193+
variable "blob_properties_change_feed_enabled" {
194+
description = "Is the blob service properties for change feed events enabled? Required for Point-in-Time Restore."
195+
type = bool
196+
default = false
197+
}
198+
199+
variable "blob_properties_restore_policy_days" {
200+
description = "Specifies the number of days that the blob can be restored. Set to null to disable by default. Note: Must be less than blob and container delete retention policy days."
201+
type = number
202+
default = null
203+
}
204+
205+
variable "share_properties_retention_policy_days" {
206+
description = "Specifies the number of days that the file share should be retained. Set to null to disable by default, or provide a number to enable."
207+
type = number
208+
default = null
209+
}
210+
187211
locals {
188212
alert_frequency_map = {
189213
PT5M = "PT1M"

0 commit comments

Comments
 (0)