-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
71 lines (63 loc) · 2.16 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
resource "aws_s3_bucket" "this" {
# checkov:skip=CKV_AWS_18: Access logging can be enabled by user if needed
# checkov:skip=CKV_AWS_144: CRR can be enabled by user if needed
# checkov:skip=CKV_AWS_21: Versioning can be enabled by user if needed
# checkov:skip=CKV_AWS_145: SSE encrytion depends on user
# checkov:skip=CKV_AWS_19: SSE encrytion depends on user
# checkov:skip=CKV_AWS_52: MFA delete can be enabled by user if needed
# checkov:skip=CKV2_AWS_62: Event notification can be enabled by user if needed
# checkov:skip=CKV2_AWS_61: Enabling lifecycle configuration depends on user
bucket = var.name
force_destroy = var.force_destroy
object_lock_enabled = var.object_lock_enabled
tags = var.tags
}
resource "aws_s3_bucket_ownership_controls" "this" {
bucket = aws_s3_bucket.this.id
rule {
object_ownership = var.object_ownership
}
}
data "aws_kms_key" "this" {
key_id = var.kms_key
}
resource "aws_s3_bucket_server_side_encryption_configuration" "this" {
bucket = aws_s3_bucket.this.id
rule {
apply_server_side_encryption_by_default {
sse_algorithm = var.kms_key == "alias/aws/s3" ? "AES256" : "aws:kms"
kms_master_key_id = var.kms_key == "alias/aws/s3" ? null : data.aws_kms_key.this.id
}
}
}
resource "aws_s3_bucket_public_access_block" "this" {
bucket = aws_s3_bucket.this.id
block_public_acls = var.block_public_acls
block_public_policy = var.block_public_policy
ignore_public_acls = var.ignore_public_acls
restrict_public_buckets = var.restrict_public_buckets
}
data "aws_iam_policy_document" "bucket_policy" {
statement {
sid = "AllowSSLRequestsOnly"
effect = "Deny"
actions = ["s3:*"]
resources = [
aws_s3_bucket.this.arn,
"${aws_s3_bucket.this.arn}/*"
]
principals {
type = "*"
identifiers = ["*"]
}
condition {
test = "Bool"
variable = "aws:SecureTransport"
values = ["false"]
}
}
}
resource "aws_s3_bucket_policy" "this" {
bucket = aws_s3_bucket.this.id
policy = var.policy == "" ? data.aws_iam_policy_document.bucket_policy.json : var.policy
}