-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnapshot.tf
82 lines (65 loc) · 1.71 KB
/
snapshot.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
# Data Lifecycle Manager (DLM) lifecycle policy for managing snapshots
resource "aws_iam_role" "dlm_lifecycle_role" {
name = "dlm-lifecycle-role"
description = "Data Lifecycle Manager (DLM) lifecycle role for managing snapshots"
assume_role_policy = data.aws_iam_policy_document.dlm_lifecycle_trust.json
}
data "aws_iam_policy_document" "dlm_lifecycle_trust" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["dlm.amazonaws.com"]
}
}
}
resource "aws_iam_role_policy" "dlm_lifecycle" {
name = "dlm-lifecycle-policy"
role = aws_iam_role.dlm_lifecycle_role.id
policy = data.aws_iam_policy_document.dlm_lifecycle.json
}
data "aws_iam_policy_document" "dlm_lifecycle" {
statement {
sid = "AllowSnapshots"
actions = [
"ec2:CreateSnapshot",
"ec2:DeleteSnapshot",
"ec2:DescribeVolumes",
"ec2:DescribeSnapshots",
]
resources = ["*"]
}
statement {
sid = "AllowSnasphotTagging"
actions = [
"ec2:CreateTags",
]
resources = ["arn:aws:ec2:*::snapshot/*"]
}
}
resource "aws_dlm_lifecycle_policy" "backup" {
description = "DLM lifecycle policy"
execution_role_arn = aws_iam_role.dlm_lifecycle_role.arn
state = "ENABLED"
policy_details {
resource_types = ["VOLUME"]
target_tags = {
Snapshot = "true"
}
schedule {
name = "1 week of daily snapshots"
create_rule {
interval = 24
interval_unit = "HOURS"
times = ["09:09"]
}
retain_rule {
count = 7
}
tags_to_add = {
SnapshotCreator = "DLM"
}
copy_tags = true
}
}
}