-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy paths3.tf
45 lines (38 loc) · 1.11 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
data "aws_iam_policy_document" "this" {
statement {
sid = "AllowCloudFrontServicePrincipal"
actions = ["s3:GetObject"]
resources = ["${aws_s3_bucket.this.arn}/*"]
condition {
test = "StringEquals"
variable = "AWS:SourceArn"
values = [aws_cloudfront_distribution.this.arn]
}
principals {
type = "Service"
identifiers = ["cloudfront.amazonaws.com"]
}
}
}
resource "aws_s3_bucket" "this" {
bucket = local.s3_bucket_name
}
resource "aws_s3_bucket_policy" "this" {
bucket = aws_s3_bucket.this.id
policy = data.aws_iam_policy_document.this.json
}
resource "aws_s3_bucket_versioning" "this" {
count = var.s3_bucket_versioning == true ? 1 : 0
bucket = aws_s3_bucket.this.id
versioning_configuration {
status = "Enabled"
}
}
resource "aws_s3_bucket_public_access_block" "this" {
count = var.s3_bucket_public_access_block == true ? 1 : 0
bucket = aws_s3_bucket.this.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}