-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
40 lines (32 loc) · 1017 Bytes
/
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
resource "aws_s3_bucket" "this" {
bucket_prefix = "${var.name_prefix}-tf-state"
tags = var.tags
}
resource "aws_s3_bucket_logging" "this" {
bucket = aws_s3_bucket.this.id
target_bucket = aws_s3_bucket.this-logs.id
target_prefix = "log/"
}
resource "aws_s3_bucket_public_access_block" "this" {
bucket = aws_s3_bucket.this.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
resource "aws_s3_bucket_versioning" "this" {
bucket = aws_s3_bucket.this.id
versioning_configuration {
status = "Enabled"
}
}
// Enable encryption on s3 bucket using aws_s3_bucket_server_side_encryption_configuration
resource "aws_s3_bucket_server_side_encryption_configuration" "this" {
bucket = aws_s3_bucket.this.id
rule {
apply_server_side_encryption_by_default {
kms_master_key_id = var.use_kms ? aws_kms_key.this[0].arn : null
sse_algorithm = var.use_kms ? "aws:kms" : "AES256"
}
}
}