Hi just wonder if anyone can assist I have bq-table resource which works perfectly fine as it is. I provide the table schema as a json file within a subdirectory called bq-schema - this is picked up and the table and schema is created fine
When I call this as a module I get the following error
Error: Invalid function argument
│
│ on .terraform/modules/bigquery-tables/main.tf line 11, in resource "google_bigquery_table" "bqtable":
│ 11: schema = file("${path.module}/bq-schema/${var.bq_table[count.index]["schema_id"]}")
│ ├────────────────
│ │ count.index is 0
│ │ path.module is ".terraform/modules/bigquery-tables"
│ │ var.bq_table is list of object with 1 element
│
│ Invalid value for "path" parameter: failed to read file: read .terraform/modules/bigquery-tables/bq-schema: is a directory
On windows the error is - "Invalid value for path parameter - failed to read - the handle is invalid
My resource is as following
> resource "google_bigquery_table" "bqtable" {
> dataset_id = var.dataset_id
> count = length(var.bq_table)
> table_id = var.bq_table[count.index]["table_id"]
> labels = var.labels
> schema = file("${path.module}/bq-schema/${var.bq_table[count.index]["schema_id"]}")
> }
Variables.tf
variable “bq_table” {
default =
type = list(object({
table_id = string
schema_id = string
}))
}
variable “labels” {
type = map(string)
}variable “dataset_id” {
type = string}
Tfvars
bq_table = [
{
schema_id = “table-schema-01.json”
table_id = “table1”
}
]labels = {
env = “development”
}
dataset_id = “testing”
Module/main.tf
module “bigquery-tables” {
source = “/xxx/Modules/bigquery-tables"
dataset_id = “testing”
bq_table = [
{
table_id = “”
schema_id = “”
}
]
labels = var.labels
}
Any ideas anyone ?, thanks