Ern*_*o U 5 google-drive-api google-bigquery terraform-provider-gcp
我正在尝试使用 Terraform从 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",
]
}
Run Code Online (Sandbox Code Playgroud)
我将文件设为公开,但是当我尝试创建表时出现错误:
错误:googleapi:错误 400:读取表格时出错:工作表,错误消息:无法读取电子表格。错误:未找到具有 Google Drive 范围的 OAuth 令牌。,无效
我阅读了 Terraform文档,似乎我需要在我的provider.tf文件中指定access_token和scopes我只是不知道该怎么做,因为我认为它会与我当前的身份验证方法(服务帐户)冲突
将 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}"
}
Run Code Online (Sandbox Code Playgroud)
您需要为 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
Run Code Online (Sandbox Code Playgroud)
默认情况下,大多数 GCP 服务接受并使用云平台范围。但是,Google Drive 不接受/使用云平台范围,因此 BigQuery 中的这一特定功能需要指定其他范围。为了完成这项工作,您应该使用 Google Drive 范围https://www.googleapis.com/auth/drive(相关 BQ 文档)来扩充默认的 terraform 范围列表。有关记录范围的更详尽列表,请参阅https://developers.google.com/identity/protocols/oauth2/scopes
访问令牌意味着您已经完成了身份验证流程并提供了必要的范围,因此您同时提供范围和令牌是没有意义的。您可以生成具有范围的令牌,或者使用具有其他范围的服务帐户。
希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
595 次 |
| 最近记录: |