【发布时间】:2020-09-25 17:56:39
【问题描述】:
我正在尝试使用 Terraform ingesting data from Google Sheets 创建一个 BQ 表,这是我的 external_data_configuration 块
resource "google_bigquery_table" "sheet" {
dataset_id = google_bigquery_dataset.bq-dataset.dataset_id
table_id = "sheet"
external_data_configuration {
autodetect = true
source_format = "GOOGLE_SHEETS"
google_sheets_options {
skip_leading_rows = 1
}
source_uris = [
"https://docs.google.com/spreadsheets/d/xxxxxxxxxxxxxxxxx",
]
}
我将文件设为公开,但当我尝试创建表时出现错误:
错误:googleapi:错误 400:读取表格时出错:工作表,错误 消息:未能读取电子表格。错误:没有 OAuth 令牌 已找到 Google 云端硬盘范围。无效
我阅读了 Terraform documentation,似乎我需要在我刚刚不使用的 provider.tf 文件中指定 access_token 和 scopes '不知道该怎么做,因为我认为它会与我当前的身份验证方法(服务帐户)冲突
解决方案
将范围参数添加到您的 provider.tf
provider "google" {
credentials = "${file("${var.path}/secret.json")}"
scopes = ["https://www.googleapis.com/auth/drive","https://www.googleapis.com/auth/bigquery"]
project = "${var.project_id}"
region = "${var.gcp_region}"
}
您需要为 Google Driver 和 Bigquery 添加范围
【问题讨论】:
-
感谢您花时间分享解决方案!超级有用
标签: google-bigquery google-drive-api terraform-provider-gcp