Skip to content

Commit 6e601ea

Browse files
authored
Merge pull request #31 from controlshift/handle_compressed_csvs
Add 'compress' setting to redshift loader lambda configuration based on response from CSL
2 parents 2f140d8 + fcdeb96 commit 6e601ea

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

config_item.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222
"successTopicARN": {"S": "${success_topic_arn}"},
2323
"failureTopicARN": {"S": "${failure_topic_arn}"},
2424
"batchSize": {"N": "1"},
25-
"currentBatch": {"S": "${current_batch}" }
25+
"currentBatch": {"S": "${current_batch}"},
26+
"compress": {"S": "${compress}"}
2627
}

config_table.tf

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ resource "aws_dynamodb_table" "loader_config" {
1313
}
1414

1515
resource "aws_dynamodb_table_item" "load_config_full_items" {
16-
for_each = toset([for table in jsondecode(data.http.bulk_data_schemas.body)["tables"] : table["table"]["name"]])
16+
for_each = toset([for table in local.parsed_bulk_data_schemas["tables"] : table["table"]["name"]])
1717

1818
table_name = aws_dynamodb_table.loader_config.name
1919
hash_key = aws_dynamodb_table.loader_config.hash_key
@@ -34,7 +34,7 @@ resource "aws_dynamodb_table_item" "load_config_full_items" {
3434
}
3535

3636
data "template_file" "loader_config_full_item" {
37-
for_each = toset([for table in jsondecode(data.http.bulk_data_schemas.body)["tables"] : table["table"]["name"]])
37+
for_each = toset([for table in local.parsed_bulk_data_schemas["tables"] : table["table"]["name"]])
3838

3939
template = "${file("${path.module}/config_item.json")}"
4040
vars = {
@@ -55,11 +55,12 @@ data "template_file" "loader_config_full_item" {
5555
current_batch = random_id.current_batch.b64_url
5656
column_list = data.http.column_list[each.key].body
5757
truncate_target = true
58+
compress = try(local.parsed_bulk_data_schemas["settings"]["compression_format"], "")
5859
}
5960
}
6061

6162
resource "aws_dynamodb_table_item" "load_config_incremental_items" {
62-
for_each = toset([for table in jsondecode(data.http.bulk_data_schemas.body)["tables"] : table["table"]["name"]])
63+
for_each = toset([for table in local.parsed_bulk_data_schemas["tables"] : table["table"]["name"]])
6364

6465
table_name = aws_dynamodb_table.loader_config.name
6566
hash_key = aws_dynamodb_table.loader_config.hash_key
@@ -80,7 +81,7 @@ resource "aws_dynamodb_table_item" "load_config_incremental_items" {
8081
}
8182

8283
data "template_file" "loader_config_incremental_item" {
83-
for_each = toset([for table in jsondecode(data.http.bulk_data_schemas.body)["tables"] : table["table"]["name"]])
84+
for_each = toset([for table in local.parsed_bulk_data_schemas["tables"] : table["table"]["name"]])
8485

8586
template = "${file("${path.module}/config_item.json")}"
8687
vars = {
@@ -101,6 +102,7 @@ data "template_file" "loader_config_incremental_item" {
101102
current_batch = random_id.current_batch.b64_url
102103
column_list = data.http.column_list[each.key].body
103104
truncate_target = false
105+
compress = try(local.parsed_bulk_data_schemas["settings"]["compression_format"], "")
104106
}
105107
}
106108

@@ -131,8 +133,12 @@ data "http" "bulk_data_schemas" {
131133
url = "https://${var.controlshift_hostname}/api/bulk_data/schema.json"
132134
}
133135

136+
locals {
137+
parsed_bulk_data_schemas = jsondecode(data.http.bulk_data_schemas.body)
138+
}
139+
134140
data "http" "column_list" {
135-
for_each = toset([for table in jsondecode(data.http.bulk_data_schemas.body)["tables"] : table["table"]["name"]])
141+
for_each = toset([for table in local.parsed_bulk_data_schemas["tables"] : table["table"]["name"]])
136142

137143
url = "https://${var.controlshift_hostname}/api/bulk_data/schema/columns?table=${each.key}"
138144
}

0 commit comments

Comments
 (0)