forked from lgallard/terraform-aws-backup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
66 lines (57 loc) · 1.64 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
59
60
61
62
63
64
65
66
resource "aws_iam_role" "ab_role" {
count = var.enabled && var.iam_role_arn == null ? 1 : 0
name = "aws-backup-plan-${var.plan_name}-role"
assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Action": ["sts:AssumeRole"],
"Effect": "allow",
"Principal": {
"Service": ["backup.amazonaws.com"]
}
}
]
}
POLICY
tags = var.tags
}
resource "aws_iam_role_policy_attachment" "ab_policy_attach" {
count = var.enabled && var.iam_role_arn == null ? 1 : 0
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForBackup"
role = aws_iam_role.ab_role[0].name
}
# Tag policy
resource "aws_iam_policy" "ab_tag_policy" {
count = var.enabled && var.iam_role_arn == null ? 1 : 0
description = "AWS Backup Tag policy"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"backup:TagResource",
"backup:ListTags",
"backup:UntagResource",
"tag:GetResources"
],
"Resource": "*"
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "ab_tag_policy_attach" {
count = var.enabled && var.iam_role_arn == null ? 1 : 0
policy_arn = aws_iam_policy.ab_tag_policy[0].arn
role = aws_iam_role.ab_role[0].name
}
# Restores policy
resource "aws_iam_role_policy_attachment" "ab_restores_policy_attach" {
count = var.enabled && var.iam_role_arn == null ? 1 : 0
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForRestores"
role = aws_iam_role.ab_role[0].name
}