-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiam.tf
58 lines (46 loc) · 1.38 KB
/
iam.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
################
# ec2/iam.tf #
################
#--------------------------------------------------------------------------
# Resource for creation IAM role for EC2 instance
#--------------------------------------------------------------------------
resource "aws_iam_role" "dlm_lifecycle" {
count = length(keys(var.snapshot_schedule_rule)) > 0 ? 1 : 0
name = "${var.name}-dlm-lifecycle-snapshot-ec2"
assume_role_policy = data.aws_iam_policy_document.dlm_lifecycle_trust_policy.json
}
data "aws_iam_policy_document" "dlm_lifecycle_trust_policy" {
statement {
effect = "Allow"
principals {
type = "Service"
identifiers = ["dlm.amazonaws.com"]
}
actions = ["sts:AssumeRole"]
}
}
resource "aws_iam_role_policy" "dlm_lifecycle" {
count = length(keys(var.snapshot_schedule_rule)) > 0 ? 1 : 0
name = aws_iam_role.dlm_lifecycle.0.id
role = aws_iam_role.dlm_lifecycle.0.id
policy = data.aws_iam_policy_document.dlm_lifecycle_policy.json
}
data "aws_iam_policy_document" "dlm_lifecycle_policy" {
statement {
effect = "Allow"
actions = [
"ec2:CreateTags"
]
resources = ["arn:aws:ec2:*::snapshot/*"]
}
statement {
effect = "Allow"
actions = [
"ec2:CreateSnapshot",
"ec2:DeleteSnapshot",
"ec2:DescribeVolumes",
"ec2:DescribeSnapshots",
]
resources = ["*"]
}
}