forked from fmasuhr/terraform-aws-cloudfront-logs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3.tf
90 lines (72 loc) · 1.85 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
data "aws_canonical_user_id" "current" {}
resource "aws_s3_bucket" "this" {
bucket = var.bucket_name
tags = var.tags
lifecycle {
prevent_destroy = true
}
}
resource "aws_s3_bucket_acl" "this" {
bucket = aws_s3_bucket.this.id
access_control_policy {
owner {
id = data.aws_canonical_user_id.current.id
}
grant {
grantee {
id = data.aws_canonical_user_id.current.id
type = "CanonicalUser"
}
permission = "FULL_CONTROL"
}
grant {
# Grant CloudFront logs access to your Amazon S3 Bucket
# https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/AccessLogs.html#AccessLogsBucketAndFileOwnership
grantee {
id = "c4c1ede66af53448b93c283ce9448c4ba468c9432aa01d700d3878632f77d2d0"
type = "CanonicalUser"
}
permission = "FULL_CONTROL"
}
}
}
resource "aws_s3_bucket_lifecycle_configuration" "this" {
bucket = aws_s3_bucket.this.bucket
rule {
id = "expiration"
status = "Enabled"
expiration {
days = var.retention
}
noncurrent_version_expiration {
noncurrent_days = 1
}
}
}
resource "aws_s3_bucket_public_access_block" "this" {
bucket = aws_s3_bucket.this.bucket
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
data "aws_iam_policy_document" "s3_bucket_readonly" {
statement {
actions = [
"s3:Get*",
"s3:List*",
]
resources = [
aws_s3_bucket.this.arn,
"${aws_s3_bucket.this.arn}/*",
]
}
}
resource "aws_s3_bucket_notification" "this" {
bucket = aws_s3_bucket.this.bucket
lambda_function {
lambda_function_arn = aws_lambda_function.this.arn
events = ["s3:ObjectCreated:*"]
}
depends_on = [aws_lambda_permission.s3_bucket_invoke_function]
}