generated from DNXLabs/terraform-aws-template
-
Notifications
You must be signed in to change notification settings - Fork 4
/
iam.tf
86 lines (71 loc) · 2.25 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
resource "aws_iam_policy" "logging" {
name = "transfer-family-logging-${var.server_name}"
policy = join("", data.aws_iam_policy_document.logging[*].json)
}
resource "aws_iam_role" "logging" {
name = "transfer-family-logging-${var.server_name}"
assume_role_policy = join("", data.aws_iam_policy_document.assume_role_policy[*].json)
managed_policy_arns = [join("", aws_iam_policy.logging[*].arn)]
}
data "aws_iam_policy_document" "assume_role_policy" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["transfer.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "s3_access_for_sftp_users" {
for_each = { for user in var.sftp_users : user.username => user }
statement {
sid = "AllowListingOfUserFolder"
effect = "Allow"
actions = [
"s3:ListBucket"
]
resources = [
join("", data.aws_s3_bucket.landing[*].arn)
]
}
statement {
sid = "HomeDirObjectAccess"
effect = "Allow"
actions = [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject",
"s3:DeleteObjectVersion",
"s3:GetObjectVersion",
"s3:GetObjectACL",
"s3:PutObjectACL"
]
resources = [
"${join("", data.aws_s3_bucket.landing[*].arn)}/${each.value.username}/*"
]
}
}
data "aws_iam_policy_document" "logging" {
statement {
sid = "CloudWatchAccessForAWSTransfer"
effect = "Allow"
actions = [
"logs:CreateLogStream",
"logs:DescribeLogStreams",
"logs:CreateLogGroup",
"logs:PutLogEvents"
]
resources = ["*"]
}
}
resource "aws_iam_policy" "s3_access_for_sftp_users" {
for_each = { for user in var.sftp_users : user.username => user }
name = "${each.value.username}-s3-access-for-sftp"
policy = data.aws_iam_policy_document.s3_access_for_sftp_users[each.value.username].json
}
resource "aws_iam_role" "s3_access_for_sftp_users" {
for_each = { for user in var.sftp_users : user.username => user }
name = "${each.value.username}-s3-access-for-sftp"
assume_role_policy = join("", data.aws_iam_policy_document.assume_role_policy[*].json)
managed_policy_arns = [aws_iam_policy.s3_access_for_sftp_users[each.value.username].arn]
}