cloud-foundation-fabric/modules/__experimental_deprecated/bigquery-factory/README.md

80 lines
2.3 KiB
Markdown
Raw Normal View History

# Google Cloud BQ Factory
2023-02-08 09:18:45 -08:00
This module allows creation and management of BigQuery datasets tables and views by defining them in well-formatted YAML files. YAML abstraction for BQ can simplify users onboarding and also makes creation of tables easier compared to HCL.
2023-02-08 09:18:45 -08:00
This factory is based on the [BQ dataset module](https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/tree/master/modules/bigquery-dataset) which currently only supports tables and views. As soon as external table and materialized view support is added, this factory will be enhanced accordingly.
2023-02-08 09:18:45 -08:00
You can create as many files as you like, the code will loop through it and create everything accordingly.
## Example
### Terraform code
2023-05-13 20:51:46 -07:00
In this section we show how to create tables and views from a file structure similar to the one shown below.
```bash
2023-02-08 09:18:45 -08:00
bigquery
├── tables
│ ├── table_a.yaml
│ ├── table_b.yaml
├── views
│ ├── view_a.yaml
│ ├── view_b.yaml
```
2023-02-08 09:18:45 -08:00
First we create the table definition in `bigquery/tables/countries.yaml`.
2023-02-08 09:18:45 -08:00
```yaml
# tftest-file id=table path=bigquery/tables/countries.yaml
dataset: my_dataset
table: countries
deletion_protection: true
labels:
env: prod
schema:
- name: country
type: STRING
- name: population
type: INT64
```
2023-02-08 09:18:45 -08:00
And a view in `bigquery/views/population.yaml`.
```yaml
2023-02-08 09:18:45 -08:00
# tftest-file id=view path=bigquery/views/population.yaml
dataset: my_dataset
view: department
query: SELECT SUM(population) from my_dataset.countries
labels:
env: prod
```
2023-02-08 09:18:45 -08:00
With this file structure, we can use the factory as follows:
2023-02-08 09:18:45 -08:00
```hcl
module "bq" {
source = "./fabric/modules/__experimental_deprecated/bigquery-factory"
2023-02-08 09:18:45 -08:00
project_id = var.project_id
tables_path = "bigquery/tables"
views_path = "bigquery/views"
}
# tftest modules=2 resources=3 files=table,view
```
<!-- BEGIN TFDOC -->
## Variables
| name | description | type | required | default |
|---|---|:---:|:---:|:---:|
| [project_id](variables.tf#L17) | Project ID. | <code>string</code> | ✓ | |
2023-02-08 09:18:45 -08:00
| [tables_path](variables.tf#L22) | Relative path for the folder storing table data. | <code>string</code> | ✓ | |
| [views_path](variables.tf#L27) | Relative path for the folder storing view data. | <code>string</code> | ✓ | |
<!-- END TFDOC -->
2023-02-24 09:28:55 -08:00
## TODO
- [ ] add external table support
- [ ] add materialized view support