-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy paths3.tf
More file actions
107 lines (87 loc) · 2.11 KB
/
s3.tf
File metadata and controls
107 lines (87 loc) · 2.11 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
resource "aws_s3_bucket" "this" {
provider = aws.main
bucket = var.project_name
policy = data.aws_iam_policy_document.this.json
website {
redirect_all_requests_to = "https://${var.target_domain}"
}
tags = merge(
var.tags,
{
"Name" = var.project_name
},
)
}
resource "aws_s3_bucket_public_access_block" "this" {
bucket = aws_s3_bucket.this.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
data "aws_iam_policy_document" "this" {
statement {
sid = "Redirect ${var.project_name}"
effect = "Allow"
principals {
identifiers = [
"*",
]
type = "AWS"
}
actions = [
"s3:*",
]
resources = [
"arn:aws:s3:::${var.project_name}",
"arn:aws:s3:::${var.project_name}/*"
]
}
version = "2012-10-17"
}
resource "aws_kms_key" "this" {
deletion_window_in_days = 10
enable_key_rotation = true
}
resource "aws_s3_bucket_server_side_encryption_configuration" "this" {
bucket = aws_s3_bucket.this.bucket
rule {
apply_server_side_encryption_by_default {
kms_master_key_id = aws_kms_key.this.arn
sse_algorithm = "aws:kms"
}
}
}
resource "aws_s3_bucket_versioning" "this" {
bucket = aws_s3_bucket.this.id
versioning_configuration {
status = "Enabled"
mfa_delete = true
}
}
resource "aws_s3_bucket" "log_bucket" {
bucket = "log_bucket"
}
resource "aws_s3_bucket_public_access_block" "log" {
bucket = aws_s3_bucket.log_bucket.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
resource "aws_s3_bucket_acl" "log_bucket_acl" {
bucket = aws_s3_bucket.log_bucket.id
acl = "log-delivery-write"
}
resource "aws_s3_bucket_logging" "this" {
bucket = aws_s3_bucket.this.id
target_bucket = aws_s3_bucket.log_bucket.id
target_prefix = "log/"
}
resource "aws_s3_bucket_versioning" "log_bucket" {
bucket = aws_s3_bucket.log_bucket.id
versioning_configuration {
status = "Enabled"
mfa_delete = true
}
}