google-bigquery - Terraform GCP bigquery 外部数据配置模块
问题描述
我正在为带有外部数据配置的 bigquery 表编写 terraform 模块。我有嵌套对象,下面的代码不起作用。
tables = { for table in var.tables : table["table_id"] => table }
}
locals {
tables_from_sheets = { for table_from_sheets in var.tables_from_sheets : table_from_sheets["table_id"] => table_from_sheets }
}
resource "google_bigquery_dataset" "main" {
dataset_id = var.dataset_id
friendly_name = var.friendly_name
description = var.description
location = var.location
default_table_expiration_ms = var.default_table_expiration_ms
project = var.project
labels = var.dataset_labels
}
resource "google_bigquery_table" "main" {
for_each = local.tables
dataset_id = google_bigquery_dataset.main.dataset_id
friendly_name = each.key
table_id = each.key
labels = each.value["labels"]
schema = each.value["schema"]
expiration_time = each.value["expiration_time"]
project = var.project
deletion_protection = each.value["deletion_protection"]
dynamic "external_data_configuration" {
for_each = each.value["external_data_configuration"] != null ? [each.value["external_data_configuration"]] : []
content {
autodetect = external_data_configuration.value["autodetect"]
source_format = external_data_configuration.value["source_format"]
source_uris = external_data_configuration.value["source_uris"]
dynamic "google_sheets_options" {
for_each = external_data_configuration.value.google_sheets_options
content {
range = google_sheets_options.value["range"]
skip_leading_rows = google_sheets_options.value["skip_leading_rows"]
}
}
}
}
}
变量.tf
variable "tables" {
description = "A list of objects which include table_id, schema, clustering, time_partitioning, expiration_time and labels."
default = []
type = list(object({
table_id = string,
schema = string, // Either pass json file or actual schema
deletion_protection = string,
external_data_configuration = object({
autodetect = bool,
source_format = string,
source_uris = list(string),
google_sheets_options = object({
skip_leading_rows = number,
range = string,
}),
}),
expiration_time = string,
labels = map(string),
}))
}
但是 terraform plan 有以下错误:
但是 terraform plan 有以下错误:
│错误:无效索引││在../../module/bquery/main.tf第42行,资源“google_bigquery_table”“main”中:│42:range = google_sheets_options.value[“range”]│├── ────────────── │ │ google_sheets_options.value 是 1 │ │ 这个值没有任何索引。
请让我知道如何解决此问题。我的理解可能对这些价值观有误。
解决方案
推荐阅读
- reactjs - 如何使用 Context API 更新组件提供者的状态
- powerbi - 隐藏另一个切片器的值的切片器
- c# - 如何使用 API 传输密码
- mongodb - 如何更新现有文档中的新数组
- powershell - 安装 dotnet core 问题
- python - 我想在列表中添加元素
- selenium-webdriver - 错误显示为“org.openqa.selenium.JavascriptException:javascript 错误:无法读取属性‘setAttribute’ of null”
- c - USB Linux API:从用户空间应用调用 ioctl 请求
- php - 追加到 MongoDB 中的数组 (PHP 7.2)
- ios - 如何在 Nativescript 中限制聊天气泡(标签)的宽度?