UPD: Adding monthly backup rule

This commit is contained in:
xpk 2024-04-30 10:19:12 +08:00
parent b697a2b0ca
commit 3c9b01ead4
Signed by: xpk
GPG Key ID: CD4FF6793F09AB86
3 changed files with 38 additions and 13 deletions

View File

@ -32,9 +32,10 @@ No modules.
| Name | Description | Type | Default | Required | | Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:| |------|-------------|------|---------|:--------:|
| backup-plan-name | Backup plan name | `string` | n/a | yes | | daily-backup-cron | Daily backup rule cron expression | `string` | n/a | yes |
| backup-plan-retention | Backup retention period | `number` | n/a | yes | | daily-backup-retention | Daily backup retention period | `number` | n/a | yes |
| backup-rule-cron | Backup rule cron expression | `string` | n/a | yes | | monthly-backup-cron | Monthly backup rule cron expression | `string` | n/a | yes |
| monthly-backup-retention | Monthly backup retention period | `number` | n/a | yes |
| service-opt-in | n/a | <pre>map(object({<br> enabled = bool<br> }))</pre> | <pre>{<br> "Aurora": {<br> "enabled": false<br> },<br> "DynamoDB": {<br> "enabled": true<br> },<br> "EBS": {<br> "enabled": false<br> },<br> "EC2": {<br> "enabled": true<br> },<br> "EFS": {<br> "enabled": true<br> },<br> "FSx": {<br> "enabled": false<br> },<br> "RDS": {<br> "enabled": true<br> },<br> "Redshift": {<br> "enabled": true<br> },<br> "S3": {<br> "enabled": false<br> },<br> "VirtualMachine": {<br> "enabled": false<br> }<br>}</pre> | no | | service-opt-in | n/a | <pre>map(object({<br> enabled = bool<br> }))</pre> | <pre>{<br> "Aurora": {<br> "enabled": false<br> },<br> "DynamoDB": {<br> "enabled": true<br> },<br> "EBS": {<br> "enabled": false<br> },<br> "EC2": {<br> "enabled": true<br> },<br> "EFS": {<br> "enabled": true<br> },<br> "FSx": {<br> "enabled": false<br> },<br> "RDS": {<br> "enabled": true<br> },<br> "Redshift": {<br> "enabled": true<br> },<br> "S3": {<br> "enabled": false<br> },<br> "VirtualMachine": {<br> "enabled": false<br> }<br>}</pre> | no |
## Outputs ## Outputs

View File

@ -99,20 +99,39 @@ resource "aws_backup_plan" "ab-plan" {
for_each = aws_backup_vault.ab-vault for_each = aws_backup_vault.ab-vault
name = "BackupPlan-${replace(each.value.name, "BackupVault-", "")}" name = "BackupPlan-${replace(each.value.name, "BackupVault-", "")}"
# daily backup
rule { rule {
rule_name = var.backup-plan-name rule_name = "Daily"
target_vault_name = each.value.name target_vault_name = each.value.name
schedule = var.backup-rule-cron schedule = var.daily-backup-cron
start_window = 60 start_window = 60
completion_window = 240 completion_window = 240
lifecycle { lifecycle {
delete_after = var.backup-plan-retention delete_after = var.daily-backup-retention
} }
recovery_point_tags = { recovery_point_tags = {
"CreatedBy" : "AWSBackup" "CreatedBy" : "AWSBackup"
"AWSBackupPlan" : "BackupPlan-${replace(each.value.name, "BackupVault-", "")}" "AWSBackupPlan" : "BackupPlan-${replace(each.value.name, "BackupVault-", "")}-Daily"
}
}
# monthly backup (takes precedence than daily)
rule {
rule_name = "Monthly"
target_vault_name = each.value.name
schedule = var.monthly-backup-cron
start_window = 60
completion_window = 240
lifecycle {
delete_after = var.monthly-backup-retention
}
recovery_point_tags = {
"CreatedBy" : "AWSBackup"
"AWSBackupPlan" : "BackupPlan-${replace(each.value.name, "BackupVault-", "")}-Monthly"
} }
} }

View File

@ -1,16 +1,21 @@
variable "backup-plan-name" { variable "daily-backup-cron" {
type = string type = string
description = "Backup plan name" description = "Daily backup rule cron expression"
} }
variable "backup-rule-cron" { variable "monthly-backup-cron" {
type = string type = string
description = "Backup rule cron expression" description = "Monthly backup rule cron expression"
} }
variable "backup-plan-retention" { variable "daily-backup-retention" {
type = number type = number
description = "Backup retention period" description = "Daily backup retention period"
}
variable "monthly-backup-retention" {
type = number
description = "Monthly backup retention period"
} }
variable "service-opt-in" { variable "service-opt-in" {