The following template is trying to create dataset, table, and view at the same time.
imports:
- path: templates/bigquery/bigquery_dataset.py
name: bigquery_dataset.py
- path: templates/bigquery/bigquery_table.py
name: bigquery_table.py
resources:
- name: pun-bq-dataset
type: bigquery_dataset.py
properties:
name: pun_bq_dataset
location: US
access:
- role: OWNER
userByEmail: <YOUR EMAIL>
- name: pun-bq-table
type: bigquery_table.py
properties:
name: pun_bq_table
datasetId: $(ref.pun-bq-dataset.datasetId)
schema:
- name: firstname
type: STRING
- name: lastname
type: STRING
- name: age
type: INTEGER
- name: pun-bq-view
type: bigquery_table.py
metadata:
dependsOn:
- pun-bq-table
properties:
name: pun_bq_view
datasetId: $(ref.pun-bq-dataset.datasetId)
view:
description: pun_bq_view
useLegacySql: false
query: "SELECT firstname, age FROM `<PROJECT_ID>.pun_bq_dataset.pun_bq_table`"
I'm not sure if this is the template issue or API issue but 75% of the time the deployment fails with error:
ERROR: (gcloud.deployment-manager.deployments.create) Error in Operation [operation-1559665247835-58a81dd10d54c-8bfdbf01-df6ae411]: errors:
- code: RESOURCE_ERROR
location: /deployments/pun-bq-create1/resources/pun_bq_view
message: '{"ResourceType":"bigquery.v2.table","ResourceErrorCode":"404","ResourceErrorMessage":{"code":404,"errors":[{"domain":"global","message":"Not
found: Table <PROJECT_ID>:pun_bq_dataset.pun_bq_table","reason":"notFound"}],"message":"Not
found: Table <PROJECT_ID>:pun_bq_dataset.pun_bq_table","statusMessage":"Not
Found","requestPath":"https://www.googleapis.com/bigquery/v2/projects/<PROJECT_ID>/datasets/pun_bq_dataset/tables","httpMethod":"POST"}}'
metadata:
dependsOn:
- pun-bq-table
metadata:
dependsOn:
- <PROJECT_ID>:pun_bq_dataset.pun_bq_table
but that didn't help either. It seems that dependOn
doesn't always behave as expected.