-
Notifications
You must be signed in to change notification settings - Fork 2
/
s3.tf
61 lines (52 loc) · 1.28 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
resource "aws_s3_bucket" "nlb_logs" {
bucket = var.bucket_name
}
resource "aws_s3_bucket_lifecycle_configuration" "bucket-config" {
bucket = aws_s3_bucket.nlb_logs.id
rule {
id = "short_retention_policy"
expiration {
days = 4
}
status = "Enabled"
}
}
resource "aws_s3_bucket_server_side_encryption_configuration" "nlb_logs_default_encryption" {
count = var.bucket_encrypted ? 1 : 0
bucket = aws_s3_bucket.nlb_logs.id
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
bucket_key_enabled = true
}
}
resource "aws_s3_bucket_policy" "nlb_logs_policy" {
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "delivery.logs.amazonaws.com"
},
"Action": [
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::${aws_s3_bucket.nlb_logs.id}/${var.bucket_prefix}/AWSLogs/${var.aws_account_id}/*"
]
}
]
}
POLICY
bucket = aws_s3_bucket.nlb_logs.bucket
}
resource "aws_s3_bucket_notification" "nlb_logs_bucket_notification" {
bucket = aws_s3_bucket.nlb_logs.id
queue {
queue_arn = aws_sqs_queue.nlb_logs_queue.arn
events = ["s3:ObjectCreated:*"]
}
}