Skip to content

Commit c481de0

Browse files
authored
VED-759-Data Quality Reports (#885)
1 parent 6e68b0d commit c481de0

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

terraform/s3_dq_reports.tf

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Create s3 Bucket with conditional destroy for pr environments
2+
resource "aws_s3_bucket" "data_quality_reports_bucket" {
3+
bucket = "imms-${local.resource_scope}-data-quality-reports"
4+
force_destroy = local.is_temp
5+
6+
}
7+
8+
# Block public access to the bucket
9+
resource "aws_s3_bucket_public_access_block" "data_quality_reports_bucket_public_access_block" {
10+
bucket = aws_s3_bucket.data_quality_reports_bucket.id
11+
12+
block_public_acls = true
13+
block_public_policy = true
14+
ignore_public_acls = true
15+
restrict_public_buckets = true
16+
}
17+
18+
resource "aws_s3_bucket_lifecycle_configuration" "data_quality_reports" {
19+
bucket = aws_s3_bucket.data_quality_reports_bucket.id
20+
21+
rule {
22+
id = "GenericValidationReports"
23+
status = "Enabled"
24+
25+
filter {
26+
}
27+
28+
expiration {
29+
days = 14
30+
}
31+
}
32+
}
33+
34+
35+
# Add versioning to prevent against accidental deletes
36+
resource "aws_s3_bucket_versioning" "dq_source_versioning" {
37+
bucket = aws_s3_bucket.data_quality_reports_bucket.bucket
38+
versioning_configuration {
39+
status = "Enabled"
40+
}
41+
}
42+
43+
44+
# If used should attach to lambda or any aws service that needs to perform any operation
45+
resource "aws_iam_policy" "s3_dq_access" {
46+
policy = jsonencode({
47+
Version = "2012-10-17"
48+
Statement = [
49+
{
50+
Effect = "Allow"
51+
Action = ["s3:PutObject"]
52+
Resource = [
53+
aws_s3_bucket.data_quality_reports_bucket.arn,
54+
"${aws_s3_bucket.data_quality_reports_bucket.arn}/*"
55+
]
56+
}
57+
]
58+
})
59+
}
60+
61+
62+
resource "aws_s3_bucket_policy" "data_quality_bucket_policy" {
63+
bucket = aws_s3_bucket.data_quality_reports_bucket.id
64+
65+
policy = jsonencode({
66+
Version = "2012-10-17"
67+
Id = "data_quality_bucket_policy"
68+
Statement = [
69+
{
70+
Sid = "HTTPSOnly"
71+
Effect = "Deny"
72+
Principal = {
73+
AWS = "*"
74+
}
75+
Action = "s3:*"
76+
Resource = [
77+
aws_s3_bucket.data_quality_reports_bucket.arn,
78+
"${aws_s3_bucket.data_quality_reports_bucket.arn}/*"
79+
]
80+
Condition = {
81+
Bool = {
82+
"aws:SecureTransport" = "false"
83+
}
84+
}
85+
},
86+
]
87+
})
88+
}

0 commit comments

Comments
 (0)