gpt4 book ai didi

google-bigquery - Bigquery 使用 Terraform 从 Sheet 文件创建表

转载 作者:行者123 更新时间:2023-12-03 23:46:47 27 4
gpt4 key购买 nike

我正在尝试使用 Terraform 创建 BQ 表 ingesting data from Google Sheets这是我的 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",
]
}

我将文件设为公开,但是当我尝试创建表时出现错误:

Error: googleapi: Error 400: Error while reading table: sheet, error message: Failed to read the spreadsheet. Errors: No OAuth token with Google Drive scope was found., invalid



我读了 Terraform documentation看来我需要指定 access_token 范围 在我的 provider.tf 文件我只是不知道该怎么做,因为我认为它会与我当前的身份验证方法(服务帐户)冲突

解决方案

将 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 添加范围

最佳答案

我怀疑您只需要提供范围,同时保留现有的服务帐户凭据。服务帐户凭据文件未指定范围。根据 terraform 文档,默认使用以下范围:

> https://www.googleapis.com/auth/compute
> https://www.googleapis.com/auth/cloud-platform
> https://www.googleapis.com/auth/ndev.clouddns.readwrite
> https://www.googleapis.com/auth/devstorage.full_control
> https://www.googleapis.com/auth/userinfo.email

默认情况下,大多数 GCP 服务接受并使用云平台范围。但是,Google Drive 不接受/使用云平台范围,因此 BigQuery 中的此特定功能需要指定其他范围。为了完成这项工作,您应该使用 Google Drive 范围 https://www.googleapis.com/auth/drive 增加范围的默认 terraform 列表。 ( relevant BQ documentation )。有关文档范围的更详尽列表,请参阅 https://developers.google.com/identity/protocols/oauth2/scopes

访问 token 意味着您已经完成了身份验证流程并提供了必要的范围,因此您同时提供范围和 token 是没有意义的。您要么使用范围生成 token ,要么使用具有其他范围的服务帐户。

希望这可以帮助。

关于google-bigquery - Bigquery 使用 Terraform 从 Sheet 文件创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62233763/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com