-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathetl.tf
154 lines (140 loc) · 4.27 KB
/
etl.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
################################################################
# Glue data catalog
################################################################
resource "aws_glue_catalog_database" "data_lake_raw_db" {
name = "raw_db"
}
resource "aws_glue_catalog_database" "data_lake_curated_db" {
name = "curated_db"
}
resource "aws_glue_catalog_database" "data_lake_aggregated_db" {
name = "aggregated_db"
}
resource "aws_glue_catalog_table" "employee" {
name = "employee"
database_name = aws_glue_catalog_database.data_lake_raw_db.name
table_type = "EXTERNAL_TABLE"
storage_descriptor {
compressed = false
input_format = "org.apache.hadoop.mapred.TextInputFormat"
location = "s3://${module.s3_bucket_raw.bucket.bucket}/employee/"
output_format = "org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat"
ser_de_info {
name = "LazySimpleSerDe"
serialization_library = "org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe"
parameters = {
"field.delim" : ","
}
}
columns {
name = "employee_id"
type = "bigint"
}
columns {
name = "first_name"
type = "string"
}
columns {
name = "last_name"
type = "string"
}
columns {
name = "email"
type = "string"
}
columns {
name = "phone_number"
type = "string"
}
columns {
name = "hire_date"
type = "string"
}
columns {
name = "job_id"
type = "string"
}
columns {
name = "salary"
type = "bigint"
}
columns {
name = "commission_pct"
type = "bigint"
}
columns {
name = "manager_id"
type = "bigint"
}
columns {
name = "department_id"
type = "bigint"
}
}
}
################################################################
# Glue jobs for ETL
################################################################
resource "aws_s3_bucket" "glue" {
bucket = "glue-${local.post_fix}"
acl = "private"
}
resource "aws_s3_account_public_access_block" "glue" {
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
resource "aws_iam_role" "glue_execution_role" {
name = "GlueExecutionRole"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "glue.amazonaws.com"
}
},
]
})
}
resource "aws_iam_role_policy_attachment" "glue_service_role" {
for_each = toset([
"arn:aws:iam::aws:policy/service-role/AWSGlueServiceRole",
"arn:aws:iam::aws:policy/AmazonS3FullAccess",
])
role = aws_iam_role.glue_execution_role.name
policy_arn = each.value
}
resource "aws_s3_bucket_object" "spline_agent_jar" {
bucket = aws_s3_bucket.glue.bucket
key = "lib/${basename(local.spline_agent_file_path)}"
source = local.spline_agent_file_path
etag = filemd5(local.spline_agent_file_path)
}
module "glue_job_raw_to_curated_employee_optimize" {
source = "./modules/etl_glue_job"
name = "RawToCurated_employee_optimize"
role_arn = aws_iam_role.glue_execution_role.arn
script_file_path = "src/glue/raw_to_curated_employee_optimize.py"
s3_bucket_name = aws_s3_bucket.glue.bucket
lineage_endpoint = aws_apigatewayv2_stage.data_lineage.invoke_url
jars = "s3://${aws_s3_bucket_object.spline_agent_jar.bucket}/${aws_s3_bucket_object.spline_agent_jar.key}"
job_parameters = {
"--OUTPUT_LOCATION": "s3://${module.s3_bucket_curated.bucket.bucket}/employee/"
}
}
module "glue_job_curated_to_aggregated_employee" {
source = "./modules/etl_glue_job"
name = "CuratedToAggregated_employee"
role_arn = aws_iam_role.glue_execution_role.arn
script_file_path = "src/glue/curated_to_aggregated_employee.py"
s3_bucket_name = aws_s3_bucket.glue.bucket
lineage_endpoint = aws_apigatewayv2_stage.data_lineage.invoke_url
jars = "s3://${aws_s3_bucket_object.spline_agent_jar.bucket}/${aws_s3_bucket_object.spline_agent_jar.key}"
job_parameters = {
"--OUTPUT_LOCATION": "s3://${module.s3_bucket_aggregated.bucket.bucket}/employee/"
}
}