forked from willfarrell/terraform-logs-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
116 lines (99 loc) · 2.71 KB
/
main.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
resource "aws_s3_bucket" "default" {
bucket = "${var.name}-logs"
// TODO not support yet - https://github.com/terraform-providers/terraform-provider-aws/issues/9459
/*object_level_logging {
target_trail = var.target_trail
events = "Read/Write"
}*/
force_destroy = false
/*tags = merge(
var.tags,
{
Security = "SSE:AWS"
}
)*/
}
resource "aws_s3_bucket_lifecycle_configuration" "default" {
bucket = aws_s3_bucket.default.id
rule {
id = "log"
status = "Enabled"
filter {
and {
tags = {
rule = "log"
autoclean = "true"
}
}
}
dynamic "transition" {
for_each = var.transition_infrequent_days < var.expiration_days ? [1] : []
content {
days = var.transition_infrequent_days
storage_class = "STANDARD_IA"
}
}
dynamic "transition" {
for_each = var.transition_glacier_days < var.expiration_days ? [1] : []
content {
days = var.transition_glacier_days
storage_class = "GLACIER"
}
}
expiration {
days = var.expiration_days
}
}
}
resource "aws_s3_bucket_versioning" "default" {
bucket = aws_s3_bucket.default.id
versioning_configuration {
status = "Enabled"
}
}
resource "aws_s3_bucket_logging" "default" {
count = var.logging_bucket != "" ? 1 : 0
bucket = aws_s3_bucket.default.id
target_bucket = var.logging_bucket
target_prefix = "AWSLogs/${local.account_id}/S3/${var.name}-logs/"
}
resource "aws_s3_bucket_server_side_encryption_configuration" "default" {
bucket = aws_s3_bucket.default.id
rule {
apply_server_side_encryption_by_default {
sse_algorithm = var.sse_algorithm
kms_master_key_id = var.kms_key_arn
}
}
}
resource "aws_s3_bucket_object_lock_configuration" "default" {
depends_on = [aws_s3_bucket_versioning.default]
bucket = aws_s3_bucket.default.id
object_lock_enabled = "Enabled"
rule {
default_retention {
mode = "COMPLIANCE"
days = var.expiration_days
}
}
}
resource "aws_s3_bucket_public_access_block" "default" {
depends_on = [
aws_s3_bucket.default]
bucket = aws_s3_bucket.default.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
# https://docs.aws.amazon.com/macie/latest/userguide/macie-setting-up.html#macie-setting-up-enable
# https://www.terraform.io/docs/providers/aws/r/macie_s3_bucket_association.html
# move to AWS s3 example
//resource "aws_macie_s3_bucket_association" "example" {
// bucket_name = "tf-macie-example"
// prefix = "data"
//
// classification_type {
// one_time = "FULL"
// }
//}