forked from riboseinc/terraform-aws-s3-cloudfront-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3.tf
76 lines (59 loc) · 1.17 KB
/
s3.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
resource "aws_s3_bucket" "main" {
provider = aws.main
bucket = var.fqdn
acl = "private"
policy = data.aws_iam_policy_document.bucket_policy.json
website {
index_document = var.index_document
error_document = var.error_document
routing_rules = var.routing_rules
}
force_destroy = var.force_destroy
tags = merge(
var.tags,
{
"Name" = var.fqdn
},
)
}
data "aws_iam_policy_document" "bucket_policy" {
provider = aws.main
statement {
sid = "AllowedIPReadAccess"
actions = [
"s3:GetObject",
]
resources = [
"arn:aws:s3:::${var.fqdn}/*",
]
condition {
test = "IpAddress"
variable = "aws:SourceIp"
values = var.allowed_ips
}
principals {
type = "*"
identifiers = ["*"]
}
}
statement {
sid = "AllowCFOriginAccess"
actions = [
"s3:GetObject",
]
resources = [
"arn:aws:s3:::${var.fqdn}/*",
]
condition {
test = "StringEquals"
variable = "aws:UserAgent"
values = [
var.refer_secret,
]
}
principals {
type = "*"
identifiers = ["*"]
}
}
}