Skip to content

Commit 5583379

Browse files
committed
allow all departments to create catalog tables via the manual bucket
1 parent 3848ba9 commit 5583379

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

terraform/etl/61-aws-glue-catalog-database.tf

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,21 @@ resource "aws_glue_catalog_database" "arcus_archive" {
8686
}
8787
}
8888

89-
resource "aws_glue_catalog_database" "parking_user_uploads" {
90-
name = "parking_user_uploads_db"
89+
locals {
90+
department_user_uploads_databases = {
91+
parking = "parking_user_uploads_db"
92+
housing = "housing_user_uploads_db"
93+
data_and_insight = "data_and_insight_user_uploads_db"
94+
child_fam_services = "child_fam_services_user_uploads_db"
95+
unrestricted = "unrestricted_user_uploads_db"
96+
env_services = "env_services_user_uploads_db"
97+
}
98+
}
99+
100+
resource "aws_glue_catalog_database" "department_user_uploads" {
101+
for_each = local.department_user_uploads_databases
102+
103+
name = each.value
91104

92105
lifecycle {
93106
prevent_destroy = true

terraform/etl/62-lambda-csv-to-glue-catalog.tf

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
# Lambda function to automatically create/delete Glue Catalog tables
22
# Workflow: S3 CSV upload/delete → SQS → Lambda → Glue Catalog table create/delete (retry once on failure → DLQ)
33

4+
locals {
5+
department_user_uploads_prefixes = {
6+
parking = "parking/"
7+
housing = "housing/"
8+
data_and_insight = "data-and-insight/"
9+
child_fam_services = "child-fam-services/"
10+
unrestricted = "unrestricted/"
11+
env_services = "env-services/"
12+
}
13+
}
14+
415
data "aws_iam_policy_document" "csv_to_glue_catalog_lambda_assume_role" {
516
statement {
617
actions = ["sts:AssumeRole"]
@@ -34,12 +45,11 @@ data "aws_iam_policy_document" "csv_to_glue_catalog_lambda_execution" {
3445
"glue:GetPartitions",
3546
"glue:DeletePartition",
3647
]
37-
# Currently only scoped to parking
38-
resources = [
39-
"arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.data_platform.account_id}:catalog",
40-
"arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.data_platform.account_id}:database/parking_user_uploads_db",
41-
"arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.data_platform.account_id}:table/parking_user_uploads_db/*",
42-
]
48+
resources = concat(
49+
["arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.data_platform.account_id}:catalog"],
50+
[for db_name in values(local.department_user_uploads_databases) : "arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.data_platform.account_id}:database/${db_name}"],
51+
[for db_name in values(local.department_user_uploads_databases) : "arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.data_platform.account_id}:table/${db_name}/*"]
52+
)
4353
}
4454

4555
statement {
@@ -177,11 +187,14 @@ resource "aws_sqs_queue_policy" "csv_to_glue_catalog_events" {
177187
resource "aws_s3_bucket_notification" "user_uploads_csv_notification" {
178188
bucket = module.user_uploads_data_source.bucket_id
179189

180-
queue {
181-
queue_arn = aws_sqs_queue.csv_to_glue_catalog_events.arn
182-
events = ["s3:ObjectCreated:*", "s3:ObjectRemoved:*"]
183-
filter_prefix = "parking/" # Currently only scoped to parking
184-
filter_suffix = ".csv"
190+
dynamic "queue" {
191+
for_each = local.department_user_uploads_prefixes
192+
content {
193+
queue_arn = aws_sqs_queue.csv_to_glue_catalog_events.arn
194+
events = ["s3:ObjectCreated:*", "s3:ObjectRemoved:*"]
195+
filter_prefix = queue.value
196+
filter_suffix = ".csv"
197+
}
185198
}
186199

187200
depends_on = [aws_sqs_queue_policy.csv_to_glue_catalog_events]

0 commit comments

Comments
 (0)