-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprefixed.tf
71 lines (62 loc) · 1.77 KB
/
prefixed.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
resource "aws_s3_bucket" "prefixed_bucket" {
count = var.suffix_enabled ? 1 : 0
bucket_prefix = var.bucket
acl = var.acl
policy = var.policy != "" ? local.policies[var.policy] : null
dynamic "lifecycle_rule" {
for_each = var.expiration_days > 0 ? [1] : []
content {
enabled = true
expiration {
date = var.expiration_days
}
}
}
#checkov:skip=CKV_AWS_21:Dynamic versioning block
versioning {
enabled = var.versioned
mfa_delete = true
}
dynamic "lifecycle_rule" {
for_each = var.versioned && var.noncurrent_version_expiration > 0 ? [1] : []
content {
enabled = true
noncurrent_version_expiration {
days = var.noncurrent_version_expiration
}
}
}
#checkov:skip=CKV_AWS_19:Dynamic encryption block
dynamic "server_side_encryption_configuration" {
for_each = var.encrypted ? [1] : []
content {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = var.encryption_key != "" ? "aws:kms" : "AES256"
kms_master_key_id = var.encryption_key != "" ? var.encryption_key : null
}
}
}
}
dynamic "logging" {
for_each = var.logging_bucket != "" ? [1] : []
content {
target_bucket = var.logging_bucket
target_prefix = var.bucket
}
}
dynamic "website" {
for_each = var.website_redirect != "" ? [1] : []
content {
redirect_all_requests_to = var.website_redirect
}
}
}
resource "aws_s3_bucket_public_access_block" "prefixed_bucket" {
count = var.suffix_enabled ? 1 : 0
bucket = aws_s3_bucket.prefixed_bucket[0].id
restrict_public_buckets = true
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
}