Skip to content

Commit

Permalink
Create Backup Policy for SQLDatabase and SAPHanaDatabase (#1843)
Browse files Browse the repository at this point in the history
* init code for backup policy vm workload

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* separate SQLDatabase and SAPHana

* init code example

* revert code

* refactor backup policy code

* add example to workflow 106

* refactor backup_policies_vm_workloads implementation

* enforce required for backup block

* fix policy_type error

* fix protection_policy error

* add saphana tfvars

---------

Co-authored-by: thanhlcao <[email protected]>
Co-authored-by: khairi <[email protected]>
  • Loading branch information
3 people authored Nov 16, 2023
1 parent 8343019 commit df0a1ae
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/standalone-scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
"recovery_vault/103-asr-with-private-endpoint",
"recovery_vault/104-backupvault-with-private-endpoint",
"recovery_vault/105-asr-with-network-mapping",
"recovery_vault/106-backupvault-with-sqldatabase-saphana",
"redis_cache/103-redis-private-endpoints",
"role_mapping/100-simple-role-mapping",
"role_mapping/101-function-app-managed-identity",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
global_settings = {
regions = {
region1 = "australiaeast"
}
}
resource_groups = {
primary = {
name = "backup_policy_sql"
region = "region1"
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
recovery_vaults = {
asr1 = {
name = "vault_re1"
resource_group_key = "primary"
region = "region1"
vnet_key = "vnet_region1"
subnet_key = "asr_subnet"

soft_delete_enabled = false
backup_policies = {
vm_workloads = {
sql = {
name = "SQLTest"
workload_type = "SQLDataBase"
vault_key = "asr1"
rg_key = "primary"
timezone = "UTC"
compression_enabled = false
protection_policies = {
sqlfull = {
policy_type = "Full"
backup = {
frequency = "Daily"
time = "15:00"
}
retention_daily = {
count = 8
}
}
sqllog = {
policy_type = "Log"
backup = {
frequency_in_minutes = 15
}
simple_retention = {
count = 8
}
}
}
}
saphana = {
name = "SAPHANATest"
workload_type = "SAPHanaDatabase"
vault_key = "asr1"
rg_key = "primary"
timezone = "UTC"
compression_enabled = false
protection_policies = {
saphanafull = {
policy_type = "Full"
backup = {
frequency = "Daily"
time = "15:00"
}
retention_daily = {
count = 8
}
}
saphanalog = {
policy_type = "Log"
backup = {
frequency_in_minutes = 15
}
simple_retention = {
count = 8
}
}
}
}
}
}
}
}
78 changes: 78 additions & 0 deletions modules/recovery_vault/backup_policies_vm_workload.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
resource "azurerm_backup_policy_vm_workload" "vm_workload" {
for_each = try(var.settings.backup_policies.vm_workloads, {})

name = each.value.name
resource_group_name = local.resource_group_name
recovery_vault_name = azurerm_recovery_services_vault.asr.name
workload_type = each.value.workload_type

settings {
time_zone = each.value.timezone
compression_enabled = each.value.compression_enabled
}

dynamic "protection_policy" {
for_each = each.value.protection_policies

content {
policy_type = protection_policy.value.policy_type

backup {
frequency = try(protection_policy.value.backup.frequency, null)
frequency_in_minutes = try(protection_policy.value.backup.frequency_in_minutes, null)
time = try(protection_policy.value.backup.time, null)
weekdays = try(protection_policy.value.backup.weekdays, null)
}

dynamic "retention_daily" {
for_each = lookup(protection_policy.value, "retention_daily", null) == null ? [] : [1]

content {
count = protection_policy.value.retention_daily.count
}
}

dynamic "retention_weekly" {
for_each = lookup(protection_policy.value, "retention_weekly", null) == null ? [] : [1]

content {
count = protection_policy.value.retention_weekly.count
weekdays = protection_policy.value.retention_weekly.weekdays
}
}

dynamic "retention_monthly" {
for_each = lookup(protection_policy.value, "retention_monthly", null) == null ? [] : [1]

content {
count = protection_policy.value.retention_monthly.count
format_type = protection_policy.value.retention_monthly.format_type
monthdays = try(protection_policy.value.retention_monthly.monthdays, null)
weekdays = try(protection_policy.value.retention_monthly.weekdays, null)
weeks = try(protection_policy.value.retention_monthly.weeks, null)
}
}

dynamic "retention_yearly" {
for_each = lookup(protection_policy.value, "retention_yearly", null) == null ? [] : [1]

content {
count = protection_policy.value.retention_yearly.count
format_type = protection_policy.value.retention_yearly.format_type
months = protection_policy.value.retention_yearly.months
monthdays = try(protection_policy.value.retention_yearly.monthdays, null)
weekdays = try(protection_policy.value.retention_yearly.weekdays, null)
weeks = try(protection_policy.value.retention_yearly.weeks, null)
}
}

dynamic "simple_retention" {
for_each = lookup(protection_policy.value, "simple_retention", null) == null ? [] : [1]

content {
count = protection_policy.value.simple_retention.count
}
}
}
}
}
1 change: 1 addition & 0 deletions modules/recovery_vault/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ output "backup_policies" {
value = {
virtual_machines = azurerm_backup_policy_vm.vm
file_shares = azurerm_backup_policy_file_share.fs
vm_workloads = azurerm_backup_policy_vm_workload.vm_workload
}
}

Expand Down

0 comments on commit df0a1ae

Please sign in to comment.