-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbucket.tf
More file actions
76 lines (63 loc) · 1.7 KB
/
bucket.tf
File metadata and controls
76 lines (63 loc) · 1.7 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
resource "aws_s3_bucket" "this" {
count = var.create_bucket ? 1 : 0
bucket = "${local.account_id}-${var.region}-vpcflowlog"
acl = "private"
tags = var.tags
lifecycle_rule {
enabled = true
transition {
days = 30
storage_class = "STANDARD_IA"
}
}
logging {
target_bucket = var.logging_bucket
target_prefix = "${local.account_id}-${var.region}-vpcflowlog/"
}
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "aws:kms"
kms_master_key_id = aws_kms_key.this[0].arn
}
}
}
versioning {
enabled = true
}
lifecycle {
prevent_destroy = true
}
}
resource "aws_s3_bucket_public_access_block" "this" {
count = var.create_bucket ? 1 : 0
bucket = aws_s3_bucket.this[0].id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
resource "aws_s3_bucket_policy" "vpcflowlog_bucket_policy" {
count = var.create_bucket ? 1 : 0
bucket = aws_s3_bucket.this[0].id
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "delivery.logs.amazonaws.com" },
"Action": "s3:GetBucketAcl",
"Resource": "${aws_s3_bucket.this[0].arn}"
},
{
"Effect": "Allow",
"Principal": { "Service": "delivery.logs.amazonaws.com" },
"Action": "s3:PutObject",
"Resource": "${aws_s3_bucket.this[0].arn}/AWSLogs/${data.aws_caller_identity.current.account_id}/*",
"Condition": { "StringEquals": { "s3:x-amz-acl": "bucket-owner-full-control" } }
}
]
}
EOF
}