I am new to terraform. Please let me know where I am doing wrong. Below is my main.tf code:
resource "google_bigquery_dataset" "demo" {
dataset_id = "${var.db_id}"
friendly_name = "${var.friendly_name}"
location = "${var.region}"
default_table_expiration_ms = "3600000"
labels = {
env = "default"
}
}
resource "google_bigquery_table" "demo" {
dataset_id = "${var.db_id}"
table_id = "${var.table}"
time_partitioning {
type = "DAY"
}
labels = {
env = "default"
}
schema = <<EOF
[
{
"name": "br_op_inventory_a",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "state",
"type": "STRING",
"mode": "NULLABLE"
}
]
EOF
}
resource "google_bigquery_table" "devops" {
dataset_id = "${var.db_id}"
table_id = "${var.table_1}"
time_partitioning {
type = "DAY"
}
labels = {
env = "default"
}
schema = <<EOF
[
{
"name": "br_op_inventory_a",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "state",
"type": "STRING",
"mode": "NULLABLE"
}
]
EOF
}
and here is my variables.tf code:
variable "friendly_name" {
default="test"
}
variable "region" {
default="asia-south1"
}
variable "db_id" {
default="operation_performance_test_2"
}
variable "table" {
default="sample_demo"
}
variable "table_1" {
default="price_inventory"
}
everything works fine when I run terraform init and terraform plan commands. But, when I try to run terraform apply command, I get the following error:
google_bigquery_table.demo: Creating...
google_bigquery_table.devops: Creating...
google_bigquery_dataset.demo: Creation complete after 4s [id=projects/midyear-cursor-264117/datasets/operation_performance_test_2]
Error: googleapi: Error 404: Not found: Dataset midyear-cursor-264117:operation_performance_test_2, notFound
on main.tf line 10, in resource "google_bigquery_table" "demo":
10: resource "google_bigquery_table" "demo" {
Error: googleapi: Error 404: Not found: Dataset midyear-cursor-264117:operation_performance_test_2, notFound
on main.tf line 35, in resource "google_bigquery_table" "devops":
35: resource "google_bigquery_table" "devops" {
When I again try to run terraform apply command, both the tables get created. Below is the console:
google_bigquery_table.devops: Creating...
google_bigquery_table.demo: Creating...
google_bigquery_table.devops: Creation complete after 3s [id=projects/midyear-cursor-264117/datasets/operation_performance_test_2/tables/price_inventory]
google_bigquery_table.demo: Creation complete after 4s [id=projects/midyear-cursor-264117/datasets/operation_performance_test_2/tables/sample_demo]
Apply complete! Resources: 2 added, 0 changed, 0 destroyed
Why doesn't the tables get created when I run the terraform apply command the first time ? Please help me solve this issue.
dataset
creation is a bit delayed in Bigquery runtime, thus all the requests withtable
spreading are just suspended with the above mentioned error. You can consider adjusting the code with depends_on argument leveraging dependency in runpath. – Nick_Kh Apr 7 '20 at 8:35