-
Notifications
You must be signed in to change notification settings - Fork 1
/
backup.tf
56 lines (45 loc) · 1.36 KB
/
backup.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
resource "aws_kms_key" "kms_key" {
description = "${var.name}-key"
}
resource "aws_backup_vault" "vault" {
name = "${var.name}-vault"
kms_key_arn = aws_kms_key.kms_key.arn
}
resource "aws_backup_plan" "plan" {
name = "${var.name}-plan"
rule {
rule_name = "${var.name}-daily"
target_vault_name = aws_backup_vault.vault.name
schedule = var.daily_cron
lifecycle {
// default = 5 weeks * 7 days = 35 days
delete_after = var.daily_delete_after
}
}
rule {
rule_name = "${var.name}-weekly"
target_vault_name = aws_backup_vault.vault.name
schedule = var.weekly_cron
lifecycle {
// default = 3 months * 30 days = 90 days
delete_after = var.weekly_delete_after
}
}
rule {
rule_name = "${var.name}-monthly"
target_vault_name = aws_backup_vault.vault.name
schedule = var.monthly_cron
lifecycle {
// default = 3 months * 30 days = 90 days
cold_storage_after = var.monthly_cold_storage_after
// default = 2 years * 365 days = 730 days
delete_after = var.monthly_delete_after
}
}
}
resource "aws_backup_selection" "arn_resource_selection" {
iam_role_arn = aws_iam_role.aws_backup_role.arn
name = "${var.name}-resources"
plan_id = aws_backup_plan.plan.id
resources = var.backup_resource_ids
}