-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbucket.tf
82 lines (64 loc) · 1.81 KB
/
bucket.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
# Random name for the S3 bucket
resource "random_pet" "s3_data_bucket_mame" {
length = 3
}
# S3 bucket to be used as data lake
resource "aws_s3_bucket" "data" {
bucket = "${local.namespace}-${random_pet.s3_data_bucket_mame.id}"
# DANGER !!!
force_destroy = var.destroy_all_resources
}
# block public access to the S3 bucket 1/2
resource "aws_s3_bucket_acl" "data" {
bucket = aws_s3_bucket.data.id
acl = "private"
}
# block public access to the S3 bucket 2/2
resource "aws_s3_bucket_public_access_block" "data" {
bucket = aws_s3_bucket.data.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
# setup default SSE for the S3 bucket
resource "aws_s3_bucket_server_side_encryption_configuration" "data" {
bucket = aws_s3_bucket.data.id
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
# S3 bucket logging configuration
resource "aws_s3_bucket_logging" "data" {
count = var.logging_bucket_id == null ? 0 : 1
bucket = aws_s3_bucket.data.id
target_bucket = var.logging_bucket_id
target_prefix = aws_s3_bucket.data.id
}
# S3 lifecycle policy
resource "aws_s3_bucket_lifecycle_configuration" "data" {
count = var.parquet_files_retention_days == null ? 0 : 1
bucket = aws_s3_bucket.data.id
rule {
id = "expire_parquet_files"
filter {
prefix = "data/"
}
expiration {
days = var.parquet_files_retention_days
}
status = "Enabled"
}
}
# S3 ObjectCreate notifications
resource "aws_s3_bucket_notification" "snowflake" {
count = var.snowflake_sqs_queue_arn == null ? 0 : 1
bucket = aws_s3_bucket.data.id
queue {
queue_arn = var.snowflake_sqs_queue_arn
events = ["s3:ObjectCreated:*"]
filter_prefix = "data/"
}
}