Created
August 31, 2022 21:32
-
-
Save Mark-McCracken/43efe10cfc7167e8c97b1c9c4ac21d2f to your computer and use it in GitHub Desktop.
BigQuery tables from json schema
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
locals { | |
tables = {for idx, val in fileset(path.module, "./models/**/*.json"): | |
"${jsondecode(file("./${val}")).dataset}.${jsondecode(file("./${val}")).tableName}" => jsondecode(file("./${val}")) } | |
# Creates a map, keys are "dataset.table", values are decoded json. | |
# Will be unique per project | |
} | |
resource google_bigquery_table tables { | |
for_each = local.tables | |
depends_on = [ | |
resource.google_bigquery_dataset.subject_area_1_datasets, | |
resource.google_bigquery_dataset.subject_area_2_datasets, | |
resource.google_bigquery_dataset.subject_area_3_datasets, | |
resource.google_data_catalog_policy_tag.tags | |
] | |
dataset_id = each.value.dataset | |
table_id = each.value.tableName | |
description = each.value.description | |
schema = jsonencode([for c in each.value.columns: | |
{ | |
name: c.name, | |
type: c.type, | |
mode: c.mode, | |
description: c.description, | |
policyTags: { names: contains(keys(c), "piiCategory") ? [google_data_catalog_policy_tag.tags[c.piiCategory].id] : [google_data_catalog_policy_tag.unclassified.id] } | |
} | |
]) | |
labels = each.value.labels | |
clustering = length(each.value.clusteringColumns) > 0 ? each.value.clusteringColumns : null | |
deletion_protection = false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment