Skip to content

Commit

Permalink
Upload driver scripts to s3 in terraform
Browse files Browse the repository at this point in the history
  • Loading branch information
kseebaldt committed Sep 19, 2022
1 parent 0171205 commit 9df8687
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 6 deletions.
18 changes: 16 additions & 2 deletions tf/modules/glue/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ EOF

inline_policy {
name = "policy-8675309"
policy = templatefile("${path.module}/crawler_policy.json.tpl", { data_bucket = var.data_bucket })
policy = templatefile("${path.module}/policies/crawler_policy.json.tpl", { data_bucket = var.data_bucket })
}
}

resource "aws_iam_policy" "glue_policy" {
name = "${var.app_prefix}-glue"
description = "Glue Access Policy"
policy = templatefile("${path.module}/policy.json.tpl", { app_prefix = var.app_prefix, role_arn = aws_iam_role.glue_role.arn })
policy = templatefile("${path.module}/policies/policy.json.tpl", { app_prefix = var.app_prefix, role_arn = aws_iam_role.glue_role.arn })
}

resource "aws_iam_role_policy_attachment" "glue_attach" {
Expand All @@ -63,3 +63,17 @@ resource "aws_glue_catalog_database" "stage_database" {
}
}
}

resource "aws_s3_object" "etl_script" {
bucket = var.data_bucket
key = "scripts/etl_job.py"
source = "${path.module}/scripts/etl_job.py"
etag = filemd5("${path.module}/scripts/etl_job.py")
}

resource "aws_s3_object" "shell_script" {
bucket = var.data_bucket
key = "scripts/shell_job.py"
source = "${path.module}/scripts/shell_job.py"
etag = filemd5("${path.module}/scripts/shell_job.py")
}
8 changes: 8 additions & 0 deletions tf/modules/glue/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ output "glue_crawler_role" {
output "stage_database" {
value = aws_glue_catalog_database.stage_database
}

output "etl_script_url" {
value = "s3://${var.data_bucket}/${aws_s3_object.etl_script.id}"
}

output "shell_script_url" {
value = "s3://${var.data_bucket}/${aws_s3_object.shell_script.id}"
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions tf/modules/pipelines/austin_traffic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resource "aws_glue_job" "import_raw_traffic_json" {

command {
name = "pythonshell"
script_location = "s3://${var.data_bucket}/scripts/shell_job.py"
script_location = var.shell_script_url
python_version = "3.9"
}

Expand Down Expand Up @@ -32,7 +32,7 @@ resource "aws_glue_job" "transform_traffic_raw_to_stage" {

command {
name = "glueetl"
script_location = "s3://${var.data_bucket}/scripts/etl_job.py"
script_location = var.etl_script_url
python_version = "3"
}

Expand Down
12 changes: 10 additions & 2 deletions tf/modules/pipelines/austin_traffic/vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ variable "data_bucket" {
type = string
}

variable "etl_script_url" {
type = string
}

variable "shell_script_url" {
type = string
}

variable "glue_role" {
type = object({
type = object({
arn = string
name = string
})
}

variable "glue_crawler_role" {
type = object({
type = object({
arn = string
name = string
})
Expand Down
2 changes: 2 additions & 0 deletions tf/modules/pipelines/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module "austin_traffic_pipeline" {

app_prefix = var.app_prefix
data_bucket = module.buckets.data_bucket
etl_script_url = module.glue.etl_script_url
shell_script_url = module.glue.shell_script_url
glue_role = module.glue.glue_role
glue_crawler_role = module.glue.glue_crawler_role
stage_database = module.glue.stage_database
Expand Down

0 comments on commit 9df8687

Please sign in to comment.