forked from kiwicom/terraform-aws-ftp-transfer-user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
68 lines (55 loc) · 2.03 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
# ---------------------------------------------------------------------------------------------------------------------
# CREATE IAM POLICY RULES FOR SFTP BUCKET
# ---------------------------------------------------------------------------------------------------------------------
data "aws_iam_policy_document" "transfer_user_assume_role" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["transfer.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "transfer_user_assume_policy" {
statement {
effect = "Allow"
actions = [
"s3:ListBucket",
]
resources = [
data.aws_s3_bucket.bucket.arn,
]
condition {
test = "StringLike"
variable = "s3:prefix"
values = [
var.s3_bucket_folder == "" ? "*" : "${var.s3_bucket_folder}/*",
]
}
}
statement {
effect = "Allow"
actions = local.s3_actions[var.access_type]
resources = [
var.s3_bucket_folder == "" ? "${data.aws_s3_bucket.bucket.arn}/*" : "${data.aws_s3_bucket.bucket.arn}/${var.s3_bucket_folder}/*",
var.s3_bucket_folder == "" ? data.aws_s3_bucket.bucket.arn : "${data.aws_s3_bucket.bucket.arn}/${var.s3_bucket_folder}",
]
}
}
# ---------------------------------------------------------------------------------------------------------------------
# CREATE IAM POLICY AND ROLE FROM DEFINED RULES
# ---------------------------------------------------------------------------------------------------------------------
# resource "random_string" "iam_id" {
# length = 8
# special = false
# }
resource "aws_iam_role" "transfer_user_assume_role" {
name = "${var.iam_name}-user-role"
assume_role_policy = data.aws_iam_policy_document.transfer_user_assume_role.json
}
resource "aws_iam_role_policy" "transfer_user_policy" {
name = "${var.iam_name}-user-policy"
role = aws_iam_role.transfer_user_assume_role.name
policy = data.aws_iam_policy_document.transfer_user_assume_policy.json
}