Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/gcp/bigquery/.tflint.hcl
88 changes: 42 additions & 46 deletions modules/gcp/bigquery/main.tf
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
locals {

bq_tables = flatten([
for dataset_key, values in var.bq_datasets : [
for table_key, table_values in lookup(values, "tables") : {
dataset_id = dataset_key
table_id = table_key
for table_key, table_values in lookup(values, "tables", {}) : {
dataset_id = dataset_key
table_id = table_key
deletion_protection = try(table_values.deletion_protection, false)
friendly_name = try(table_values.friendly_name, table_key)
description = try(table_values.description, null)
source_uris = table_values.source_uris
source_format = try(table_values.source_format, "PARQUET")
}
]
])
friendly_name = try(table_values.friendly_name, table_key)
description = try(table_values.description, null)
source_uris = table_values.source_uris
source_format = try(table_values.source_format, "PARQUET")
}
]
])

bq_datasets_access_policy = flatten([
for dataset_key, values in var.bq_datasets : [
for role_key, members in lookup(values, "access") : {
for role_key, members in lookup(values, "access", {}) : {
dataset_id = dataset_key
role = role_key
members = members
Expand All @@ -26,19 +26,15 @@ locals {

labels = var.labels

postgres_password = var.postgres_password

stored_procedures = {}
cloudsql_scheduled_postgres_transfers = {}
}


resource "google_project_service" "bigquerydatatransfer"{
resource "google_project_service" "bigquerydatatransfer" {
project = var.project
service = "bigquerydatatransfer.googleapis.com"
}

resource "google_project_service" "bigquery"{
resource "google_project_service" "bigquery" {
project = var.project
service = "bigquery.googleapis.com"
}
Expand All @@ -51,9 +47,9 @@ resource "google_bigquery_dataset" "bq_datasets" {
max_time_travel_hours = 168

# default_table_expiration_ms = 3600000 # 1 hr
friendly_name = each.key
description = each.value.dataset_description
labels = local.labels
friendly_name = each.key
description = each.value.dataset_description
labels = local.labels
delete_contents_on_destroy = each.value.force_destroy

}
Expand All @@ -71,50 +67,50 @@ resource "google_bigquery_dataset_iam_binding" "bq_access" {

resource "google_bigquery_data_transfer_config" "cloudsql_postgres_transfer" {
for_each = {
for dt_config in var.cloudsql_scheduled_postgres_transfers: dt_config.name => dt_config
for dt_config in var.cloudsql_scheduled_postgres_transfers : dt_config.name => dt_config
}

display_name = each.key
project = var.project
location = "US"
data_source_id = "postgresql"
schedule = each.value.schedule
display_name = each.key
project = var.project
location = "US"
data_source_id = "postgresql"
schedule = each.value.schedule
destination_dataset_id = google_bigquery_dataset.bq_datasets[each.value.destination_dataset].dataset_id
params = {
"assets": jsonencode(each.value.source_table_names)
"connector.authentication.username": each.value.username
"connector.authentication.password": var.postgres_password
"connector.database": each.value.database
"connector.endpoint.host": each.value.host
"connector.endpoint.port": 5432
"connector.encryptionMode": each.value.encryption_mode
"connector.networkAttachment": try(each.value.network_attachment, null)
"connector.schema": each.value.schema
"assets" : jsonencode(each.value.source_table_names)
"connector.authentication.username" : each.value.username
"connector.authentication.password" : var.postgres_password
"connector.database" : each.value.database
"connector.endpoint.host" : each.value.host
"connector.endpoint.port" : 5432
"connector.encryptionMode" : each.value.encryption_mode
"connector.networkAttachment" : try(each.value.network_attachment, null)
"connector.schema" : each.value.schema

}
service_account_name = var.service_account_email
depends_on = [google_bigquery_dataset.bq_datasets]
depends_on = [google_bigquery_dataset.bq_datasets]
}

resource "google_bigquery_table" "bq_tables" {
depends_on = [google_bigquery_dataset.bq_datasets]

project = var.project
project = var.project

for_each = {
for table in local.bq_tables: table.table_id => table
for_each = {
for table in local.bq_tables : table.table_id => table
}

table_id = each.key
dataset_id = each.value.dataset_id
deletion_protection = each.value.deletion_protection
friendly_name = each.value.friendly_name
description = try(each.value.description, null)
friendly_name = each.value.friendly_name
description = try(each.value.description, null)

external_data_configuration {
autodetect = true # Parquet files used
autodetect = true # Parquet files used
source_format = each.value.source_format
source_uris = each.value.source_uris
source_uris = each.value.source_uris
}

labels = local.labels
Expand All @@ -124,4 +120,4 @@ resource "google_bigquery_table" "bq_tables" {
external_data_configuration
]
}
}
}
Empty file added modules/gcp/bigquery/outputs.tf
Empty file.
3 changes: 2 additions & 1 deletion modules/gcp/bigquery/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ variable "postgres_password" {

variable "labels" {
type = map(any)
}
description = "Labels on the bigquery dataset"
}
Loading