-
Notifications
You must be signed in to change notification settings - Fork 1
/
AzureBackup-DynamicRetentionPolicy.tf
61 lines (58 loc) · 2.44 KB
/
AzureBackup-DynamicRetentionPolicy.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# This variable has RSV policy defaults in it. It can be overridden by an additional declarition in the Inputs file if necessary
variable "default_rsv_retention_policy" {
type = map(string)
default = {
retention_daily_count = 14
retention_weekly_count = 0
#retention_weekly_weekdays = ["Sunday"]
retention_monthly_count = 0
#retention_monthly_weekdays = ["Sunday"]
#retention_monthly_weeks = [] #["First", "Last"]
retention_yearly_count = 0
#retention_yearly_weekdays = ["Sunday"]
#retention_yearly_weeks = [] #["First", "Last"]
#retention_yearly_months = [] #["January"]
}
}
resource "azurerm_recovery_services_protection_policy_vm" "mgmt-backuppolicy" {
name = "backup-mgmt-policy"
resource_group_name = azurerm_resource_group.srv-rg.name
recovery_vault_name = azurerm_recovery_services_vault.client-rsv.name
timezone = var.timezonestring
backup {
frequency = "Daily"
time = "18:00"
}
#Assume we will always have daily retention
retention_daily {
count = var.default_rsv_retention_policy["retention_daily_count"]
}
# Dynamically build blocks for weekly, monthly and yearly
# default variable will be empty for these, added in input file if necessary
dynamic "retention_weekly" {
# For every value in the weekly
# Syntax is: condition ? true_val : false_val
for_each = var.default_rsv_retention_policy["retention_weekly_count"] > 0 ? [1] : []
content {
count = var.default_rsv_retention_policy["retention_weekly_count"]
weekdays = var.default_rsv_retention_policy["retention_weekly_weekdays"]
}
}
dynamic "retention_monthly" {
for_each = var.default_rsv_retention_policy["retention_monthly_count"] > 0 ? [1] : []
content {
count = var.default_rsv_retention_policy["retention_monthly_count"]
weekdays = var.default_rsv_retention_policy["retention_monthly_weekdays"]
weeks = var.default_rsv_retention_policy["retention_monthly_weeks"]
}
}
dynamic "retention_yearly" {
for_each = var.default_rsv_retention_policy["retention_yearly_count"] > 0 ? [1] : []
content {
count = var.default_rsv_retention_policy["retention_yearly_count"]
weekdays = var.default_rsv_retention_policy["retention_yearly_weekdays"]
weeks = var.default_rsv_retention_policy["retention_yearly_weeks"]
months = var.default_rsv_retention_policy["retention_yearly_months"]
}
}
}