-
Notifications
You must be signed in to change notification settings - Fork 7
/
data.tf
70 lines (57 loc) · 1.4 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
data "aws_iam_policy_document" "access_identity" {
count = var.access_identity ? 1 : 0
statement {
actions = ["s3:GetObject"]
resources = ["arn:aws:s3:::$${bucket_name}$${origin_path}*"]
principals {
type = "AWS"
identifiers = [var.access_identity_arn]
}
}
}
data "template_file" "access_identity" {
count = var.access_identity ? 1 : 0
template = element(data.aws_iam_policy_document.access_identity.*.json, 0)
vars = {
origin_path = "/"
bucket_name = aws_s3_bucket.this.id
}
}
data "aws_iam_policy_document" "read" {
statement {
actions = var.read_permissions
resources = [
"${aws_s3_bucket.this.arn}/*",
aws_s3_bucket.this.arn
]
}
}
data "aws_iam_policy_document" "write" {
statement {
actions = var.write_permissions
resources = [
"${aws_s3_bucket.this.arn}/*"
]
}
}
data "aws_iam_policy_document" "public" {
count = var.acl == "public-read" ? 1 : 0
statement {
actions = var.read_permissions
principals {
type = "AWS"
identifiers = ["*"]
}
resources = [
aws_s3_bucket.this.arn,
"${aws_s3_bucket.this.arn}/*"
]
}
}
data "template_file" "public" {
count = var.acl == "public-read" ? 1 : 0
template = element(data.aws_iam_policy_document.public.*.json, 0)
}
data "template_file" "write" {
template = data.aws_iam_policy_document.write.json
}