-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdst_iam.tf
116 lines (102 loc) · 2.69 KB
/
dst_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Roles granting source account access to destination.
resource "aws_iam_role" "dst_lambda_execution_role" {
provider = aws.dst
name = "rds_replication_dst_lambda_execution_role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "${var.src_account_id}"
},
"Action": "sts:AssumeRole"
}
]
}
EOF
}
resource "aws_iam_role_policy" "dst_lambda_execution_policy" {
provider = aws.dst
name = "rds_replication_dst_lambda_execution_policy"
role = aws_iam_role.dst_lambda_execution_role.id
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"rds:CopyDBSnapshot",
"rds:DeleteDBSnapshot",
"rds:DescribeDBInstances",
"rds:DescribeDBSnapshots",
"rds:ModifyDBSnapshotAttribute",
"rds:DescribeDBSnapshotAttributes",
"rds:CopyDBClusterSnapshot",
"rds:DeleteDBClusterSnapshot",
"rds:DescribeDBClusterInstances",
"rds:DescribeDBClusterSnapshots",
"rds:ModifyDBClusterSnapshotAttribute",
"rds:DescribeDBClusterSnapshotAttributes",
"rds:ListTagsForResource"
],
"Resource": "*"
}
]
}
EOF
}
# IAM rule for the cleanup lambda function
resource "aws_iam_role" "dst_delete_old_snapshots_role" {
provider = aws.dst
name = "rds_replication_dst_delete_old_snapshots_role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
EOF
}
resource "aws_iam_role_policy" "dst_delete_old_snapshots_policy" {
provider = aws.dst
name = "rds_replication_dst_delete_old_snapshots_policy"
role = aws_iam_role.dst_delete_old_snapshots_role.id
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"rds:DeleteDBSnapshot",
"rds:DescribeDBInstances",
"rds:DescribeDBSnapshots",
"rds:DescribeDBSnapshotAttributes",
"rds:DescribeDBClusters",
"rds:DeleteDBClusterSnapshot",
"rds:DescribeDBClusterInstances",
"rds:DescribeDBClusterSnapshots",
"rds:ModifyDBClusterSnapshotAttribute",
"rds:DescribeDBClusterSnapshotAttributes"
],
"Resource": "*"
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "dst_delete_old_snapshots_basic_execution_policy" {
provider = aws.dst
role = aws_iam_role.dst_delete_old_snapshots_role.id
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}