-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdata.tf
79 lines (72 loc) · 1.89 KB
/
data.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
######################################################################
## General access
######################################################################
data "aws_iam_policy_document" "deny_unencrypted_policy_document" {
statement {
sid = "DenyUnencryptedCommunication"
actions = [
"s3:*"
]
effect = "Deny"
principals {
identifiers = [
"*"
]
type = "AWS"
}
resources = [
aws_s3_bucket.this.arn,
"${aws_s3_bucket.this.arn}/*"
]
condition {
test = "Bool"
values = [false]
variable = "aws:SecureTransport"
}
}
}
data "aws_iam_policy_document" "general_read_only_policy_document" {
statement {
sid = "GeneralReadOnlyObjectAccess"
actions = [
"s3:List*",
"s3:Get*"
]
effect = "Allow"
principals {
identifiers = var.general_read_only_aws_principals
type = "AWS"
}
resources = [
aws_s3_bucket.this.arn,
"${aws_s3_bucket.this.arn}/*"
]
}
}
data "aws_iam_policy_document" "general_read_write_policy_document" {
statement {
sid = "GeneralReadWriteObjectAccess"
actions = [
"s3:List*",
"s3:Get*",
"s3:PutObject",
"s3:DeleteObject"
]
effect = "Allow"
principals {
identifiers = var.general_read_write_aws_principals
type = "AWS"
}
resources = [
aws_s3_bucket.this.arn,
"${aws_s3_bucket.this.arn}/*"
]
}
}
data "aws_iam_policy_document" "default_bucket_policy_document" {
source_policy_documents = concat(
[data.aws_iam_policy_document.deny_unencrypted_policy_document.json]
, length(var.general_read_only_aws_principals) > 0 ? [data.aws_iam_policy_document.general_read_only_policy_document.json] : []
, length(var.general_read_write_aws_principals) > 0 ? [data.aws_iam_policy_document.general_read_write_policy_document.json] : []
)
}