-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbackup.tf
85 lines (73 loc) · 1.68 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
resource "aws_iam_role" "dlm_lifecycle_role" {
name = "dlm-lifecycle-role-${var.tenant}-${var.domain}"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "dlm.amazonaws.com"
},
"Effect": "Allow",
"Sid": "1"
}
]
}
EOF
}
resource "aws_iam_role_policy" "dlm_lifecycle" {
name = "dlm-lifecycle-policy-${var.tenant}-${var.domain}"
role = aws_iam_role.dlm_lifecycle_role.id
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:CreateSnapshot",
"ec2:DeleteSnapshot",
"ec2:DescribeVolumes",
"ec2:DescribeSnapshots"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ec2:CreateTags"
],
"Resource": "arn:aws:ec2:*::snapshot/*"
}
]
}
EOF
}
resource "aws_dlm_lifecycle_policy" "backup-gitlab" {
description = "Gitlab DLM lifecycle policy"
execution_role_arn = aws_iam_role.dlm_lifecycle_role.arn
state = "ENABLED"
policy_details {
resource_types = ["VOLUME"]
schedule {
name = "${var.days_retain_gitlab_snapshot} days of daily snapshots"
create_rule {
interval = 24
interval_unit = "HOURS"
times = ["23:15"]
}
retain_rule {
count = var.days_retain_gitlab_snapshot
}
tags_to_add = {
SnapshotCreator = "DLM"
}
copy_tags = true
}
target_tags = {
Snapshot = "gitlab.${var.tenant}.${var.domain}"
}
}
tags = var.tags
}