18
18
# # Create the BigQuery dataset
19
19
resource "google_bigquery_dataset" "ds_edw" {
20
20
project = module. project-services . project_id
21
- dataset_id = " ds_edw "
21
+ dataset_id = " thelook "
22
22
friendly_name = " My EDW Dataset"
23
23
description = " My EDW Dataset with tables"
24
24
location = var. region
25
25
labels = var. labels
26
26
delete_contents_on_destroy = var. force_destroy
27
+
28
+ depends_on = [time_sleep . wait_after_apis ]
27
29
}
28
30
29
31
# # Create a BigQuery connection
@@ -33,6 +35,7 @@ resource "google_bigquery_connection" "ds_connection" {
33
35
location = var. region
34
36
friendly_name = " Storage Bucket Connection"
35
37
cloud_resource {}
38
+ depends_on = [time_sleep . wait_after_apis ]
36
39
}
37
40
38
41
# # Grant IAM access to the BigQuery Connection account for Cloud Storage
@@ -42,64 +45,146 @@ resource "google_storage_bucket_iam_binding" "bq_connection_iam_object_viewer" {
42
45
members = [
43
46
" serviceAccount:${ google_bigquery_connection . ds_connection . cloud_resource [0 ]. service_account_id } " ,
44
47
]
48
+ }
45
49
46
- depends_on = [
47
- google_bigquery_connection . ds_connection ,
48
- ]
50
+ # # Create a Biglake table for events with metadata caching
51
+ resource "google_bigquery_table" "tbl_edw_events" {
52
+ dataset_id = google_bigquery_dataset. ds_edw . dataset_id
53
+ table_id = " events"
54
+ project = module. project-services . project_id
55
+ deletion_protection = var. deletion_protection
56
+
57
+ schema = file (" ${ path . module } /src/schema/events_schema.json" )
58
+
59
+ external_data_configuration {
60
+ autodetect = true
61
+ connection_id = google_bigquery_connection. ds_connection . name
62
+ source_format = " PARQUET"
63
+ source_uris = [" gs://${ google_storage_bucket . raw_bucket . name } /thelook-ecommerce/events.parquet" ]
64
+ }
65
+
66
+ labels = var. labels
49
67
}
50
68
51
- # # Create a BigQuery external table
52
- resource "google_bigquery_table" "tbl_edw_taxi " {
69
+ # # Create a Biglake table for inventory_items
70
+ resource "google_bigquery_table" "tbl_edw_inventory_items " {
53
71
dataset_id = google_bigquery_dataset. ds_edw . dataset_id
54
- table_id = " taxi_trips "
72
+ table_id = " inventory_items "
55
73
project = module. project-services . project_id
56
74
deletion_protection = var. deletion_protection
57
75
76
+ schema = file (" ${ path . module } /src/schema/inventory_items_schema.json" )
77
+
58
78
external_data_configuration {
59
79
autodetect = true
60
- connection_id = " ${ module . project-services . project_id } . ${ var . region } . ds_connection"
80
+ connection_id = google_bigquery_connection . ds_connection . name
61
81
source_format = " PARQUET"
62
- source_uris = [" gs://${ google_storage_bucket . raw_bucket . name } /new-york-taxi-trips/tlc-yellow-trips-2022/taxi-*.Parquet" ]
82
+ source_uris = [" gs://${ google_storage_bucket . raw_bucket . name } /thelook-ecommerce/inventory_items.parquet" ]
83
+ }
84
+
85
+ labels = var. labels
86
+ }
87
+
88
+ # # Create a Biglake table with metadata caching for order_items
89
+ resource "google_bigquery_table" "tbl_edw_order_items" {
90
+ dataset_id = google_bigquery_dataset. ds_edw . dataset_id
91
+ table_id = " order_items"
92
+ project = module. project-services . project_id
93
+ deletion_protection = var. deletion_protection
63
94
95
+ schema = file (" ${ path . module } /src/schema/order_items_schema.json" )
96
+
97
+ external_data_configuration {
98
+ autodetect = true
99
+ connection_id = google_bigquery_connection. ds_connection . name
100
+ source_format = " PARQUET"
101
+ source_uris = [" gs://${ google_storage_bucket . raw_bucket . name } /thelook-ecommerce/order_items.parquet" ]
64
102
}
65
103
66
- schema = file (" ${ path . module } /src/taxi_trips_schema.json" )
104
+ labels = var. labels
105
+ }
106
+
107
+ # # Create a Biglake table for orders
108
+ resource "google_bigquery_table" "tbl_edw_orders" {
109
+ dataset_id = google_bigquery_dataset. ds_edw . dataset_id
110
+ table_id = " orders"
111
+ project = module. project-services . project_id
112
+ deletion_protection = var. deletion_protection
113
+
114
+ schema = file (" ${ path . module } /src/schema/orders_schema.json" )
115
+
116
+ external_data_configuration {
117
+ autodetect = true
118
+ connection_id = google_bigquery_connection. ds_connection . name
119
+ source_format = " PARQUET"
120
+ source_uris = [" gs://${ google_storage_bucket . raw_bucket . name } /thelook-ecommerce/orders.parquet" ]
121
+ }
67
122
68
123
labels = var. labels
124
+ }
69
125
70
- depends_on = [
71
- google_bigquery_connection . ds_connection ,
72
- google_storage_bucket . raw_bucket ,
73
- ]
126
+ # # Create a Biglake table for products
127
+ resource "google_bigquery_table" "tbl_edw_products" {
128
+ dataset_id = google_bigquery_dataset. ds_edw . dataset_id
129
+ table_id = " products"
130
+ project = module. project-services . project_id
131
+ deletion_protection = var. deletion_protection
132
+
133
+ schema = file (" ${ path . module } /src/schema/products_schema.json" )
134
+
135
+ external_data_configuration {
136
+ autodetect = true
137
+ connection_id = google_bigquery_connection. ds_connection . name
138
+ source_format = " PARQUET"
139
+ source_uris = [" gs://${ google_storage_bucket . raw_bucket . name } /thelook-ecommerce/products.parquet" ]
140
+ }
141
+
142
+ labels = var. labels
143
+ }
144
+
145
+ # # Create a Biglake table for products
146
+ resource "google_bigquery_table" "tbl_edw_users" {
147
+ dataset_id = google_bigquery_dataset. ds_edw . dataset_id
148
+ table_id = " users"
149
+ project = module. project-services . project_id
150
+ deletion_protection = var. deletion_protection
151
+
152
+ schema = file (" ${ path . module } /src/schema/users_schema.json" )
153
+
154
+ external_data_configuration {
155
+ autodetect = true
156
+ connection_id = google_bigquery_connection. ds_connection . name
157
+ source_format = " PARQUET"
158
+ source_uris = [" gs://${ google_storage_bucket . raw_bucket . name } /thelook-ecommerce/users.parquet" ]
159
+ }
160
+
161
+ labels = var. labels
74
162
}
75
163
76
164
# Load Queries for Stored Procedure Execution
77
- # # Load Lookup Data Tables
165
+ # # Load Distribution Center Lookup Data Tables
78
166
resource "google_bigquery_routine" "sp_provision_lookup_tables" {
79
167
project = module. project-services . project_id
80
168
dataset_id = google_bigquery_dataset. ds_edw . dataset_id
81
169
routine_id = " sp_provision_lookup_tables"
82
170
routine_type = " PROCEDURE"
83
171
language = " SQL"
84
- definition_body = templatefile (" ${ path . module } /src/sql/sp_provision_lookup_tables.sql" , { project_id = module.project- services.project_id })
85
-
86
- depends_on = [
87
- google_bigquery_dataset . ds_edw ,
88
- ]
172
+ definition_body = templatefile (" ${ path . module } /src/sql/sp_provision_lookup_tables.sql" , { project_id = module.project- services.project_id, dataset_id = google_bigquery_dataset.ds_edw.dataset_id })
89
173
}
90
174
91
-
92
- # # Add Looker Studio Data Report Procedure
93
- resource "google_bigquery_routine" "sproc_sp_demo_datastudio_report" {
175
+ # Add Looker Studio Data Report Procedure
176
+ resource "google_bigquery_routine" "sproc_sp_demo_lookerstudio_report" {
94
177
project = module. project-services . project_id
95
178
dataset_id = google_bigquery_dataset. ds_edw . dataset_id
96
179
routine_id = " sp_lookerstudio_report"
97
180
routine_type = " PROCEDURE"
98
181
language = " SQL"
99
- definition_body = templatefile (" ${ path . module } /src/sql/sp_lookerstudio_report.sql" , { project_id = module.project- services.project_id })
182
+ definition_body = templatefile (" ${ path . module } /src/sql/sp_lookerstudio_report.sql" , { project_id = module.project- services.project_id, dataset_id = google_bigquery_dataset.ds_edw.dataset_id })
100
183
101
184
depends_on = [
102
- google_bigquery_table . tbl_edw_taxi ,
185
+ google_bigquery_table . tbl_edw_inventory_items ,
186
+ google_bigquery_table . tbl_edw_order_items ,
187
+ google_bigquery_routine . sp_provision_lookup_tables ,
103
188
]
104
189
}
105
190
@@ -110,24 +195,26 @@ resource "google_bigquery_routine" "sp_sample_queries" {
110
195
routine_id = " sp_sample_queries"
111
196
routine_type = " PROCEDURE"
112
197
language = " SQL"
113
- definition_body = templatefile (" ${ path . module } /src/sql/sp_sample_queries.sql" , { project_id = module.project- services.project_id })
198
+ definition_body = templatefile (" ${ path . module } /src/sql/sp_sample_queries.sql" , { project_id = module.project- services.project_id, dataset_id = google_bigquery_dataset.ds_edw.dataset_id })
114
199
115
200
depends_on = [
116
- google_bigquery_table . tbl_edw_taxi ,
201
+ google_bigquery_table . tbl_edw_inventory_items ,
202
+ google_bigquery_table . tbl_edw_order_items ,
117
203
]
118
204
}
119
205
120
- # # Add Bigquery ML Model
206
+
207
+ # Add Bigquery ML Model
121
208
resource "google_bigquery_routine" "sp_bigqueryml_model" {
122
209
project = module. project-services . project_id
123
210
dataset_id = google_bigquery_dataset. ds_edw . dataset_id
124
211
routine_id = " sp_bigqueryml_model"
125
212
routine_type = " PROCEDURE"
126
213
language = " SQL"
127
- definition_body = templatefile (" ${ path . module } /src/sql/sp_bigqueryml_model.sql" , { project_id = module.project- services.project_id })
214
+ definition_body = templatefile (" ${ path . module } /src/sql/sp_bigqueryml_model.sql" , { project_id = module.project- services.project_id, dataset_id = google_bigquery_dataset.ds_edw.dataset_id })
128
215
129
216
depends_on = [
130
- google_bigquery_table . tbl_edw_taxi ,
217
+ google_bigquery_table . tbl_edw_order_items ,
131
218
]
132
219
}
133
220
@@ -138,10 +225,10 @@ resource "google_bigquery_routine" "sp_sample_translation_queries" {
138
225
routine_id = " sp_sample_translation_queries"
139
226
routine_type = " PROCEDURE"
140
227
language = " SQL"
141
- definition_body = templatefile (" ${ path . module } /src/sql/sp_sample_translation_queries.sql" , { project_id = module.project- services.project_id })
228
+ definition_body = templatefile (" ${ path . module } /src/sql/sp_sample_translation_queries.sql" , { project_id = module.project- services.project_id, dataset_id = google_bigquery_dataset.ds_edw.dataset_id })
142
229
143
230
depends_on = [
144
- google_bigquery_table . tbl_edw_taxi ,
231
+ google_bigquery_table . tbl_edw_inventory_items ,
145
232
]
146
233
}
147
234
@@ -151,6 +238,8 @@ resource "google_project_service_identity" "bigquery_data_transfer_sa" {
151
238
provider = google- beta
152
239
project = module. project-services . project_id
153
240
service = " bigquerydatatransfer.googleapis.com"
241
+
242
+ depends_on = [time_sleep . wait_after_apis ]
154
243
}
155
244
156
245
# # Grant the DTS service account access
@@ -162,6 +251,8 @@ resource "google_project_iam_member" "dts_service_account_roles" {
162
251
project = module. project-services . project_id
163
252
role = each. key
164
253
member = " serviceAccount:${ google_project_service_identity . bigquery_data_transfer_sa . email } "
254
+
255
+ depends_on = [time_sleep . wait_after_apis ]
165
256
}
166
257
167
258
# Create specific service account for DTS Run
@@ -206,7 +297,7 @@ resource "google_bigquery_data_transfer_config" "dts_config" {
206
297
data_source_id = " scheduled_query"
207
298
schedule = " every day 00:00"
208
299
params = {
209
- query = " CALL `${ module . project-services . project_id } .ds_edw.sp_bigqueryml_model`()"
300
+ query = " CALL `${ module . project-services . project_id } .${ google_bigquery_dataset . ds_edw . dataset_id } .sp_bigqueryml_model`()"
210
301
}
211
302
service_account_name = google_service_account. dts . email
212
303
0 commit comments