[英]getting error while trying to copy data using google_bigquery_data_transfer_config using terraform
I am trying to setup a bigquery data transfer configuration using terraform. I am using my personal gcp account.我正在尝试使用 terraform 设置 bigquery 数据传输配置。我正在使用我的个人 gcp 帐户。 I have a setup of terraform on my laptop so that terraform and gcp can work together.我在笔记本电脑上设置了 terraform,这样 terraform 和 gcp 就可以一起工作了。
Trying this below code in main.tf,在 main.tf 中尝试下面的代码,
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "4.18.0"
}
}
}
provider "google" {
# Configuration options
project="gcp-project-100"
region="us-central1"
zone="us-central1-a"
credentials = "keys.json"
}
data "google_project" "project" {
}
resource "google_project_iam_member" "permissions" {
project = data.google_project.project.project_id
role = "roles/iam.serviceAccountShortTermTokenMinter"
member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-bigquerydatatransfer.iam.gserviceaccount.com"
}
resource "google_bigquery_data_transfer_config" "query_config" {
depends_on = [google_project_iam_member.permissions]
display_name = "my-query"
location = "US"
data_source_id = "scheduled_query"
schedule = "every wednesday 09:30"
service_account_name = "service-${data.google_project.project.number}@gcp-sa-bigquerydatatransfer.iam.gserviceaccount.com"
destination_dataset_id = "practice"
params = {
destination_table_name_template = "test_gsod"
write_disposition = "WRITE_TRUNCATE"
query = "select station_number , year , month,day, mean_temp,mean_dew_point ,mean_visibility from `bigquery-public-data.samples.gsod`"
}
}
terraform apply is failing with below details terraform 申请失败,详情如下
google_bigquery_data_transfer_config.query_config: Creating... ╷ │ Error: Error creating Config: googleapi: Error 403: The caller does not have permission │ │ with google_bigquery_data_transfer_config.query_config, │ on main.tf line 27, in resource "google_bigquery_data_transfer_config" "query_config": │ 27: resource "google_bigquery_data_transfer_config" "query_config" { google_bigquery_data_transfer_config.query_config:创建...╷│错误:创建配置时出错:googleapi:错误403:调用者没有权限││与google_bigquery_data_transfer_config.query_config,│在main.tf第27行,资源“google_bigquery_data_transfer_config”“query_config” :│27:资源“google_bigquery_data_transfer_config”“query_config”{
Can someone please help me, how to do this setup properly.有人可以帮助我,如何正确进行此设置。
The issue is resolved now.现在问题已解决。 I have used below piece of code along with bigquery admin role for my terraform service account.我为我的 terraform 服务帐户使用了以下代码以及 bigquery 管理员角色。
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "4.18.0"
}
}
}
provider "google" {
# Configuration options
project="gcp-project-100"
region="us-central1"
zone="us-central1-a"
credentials = "keys.json"
}
resource "google_bigquery_data_transfer_config" "query_config" {
display_name = "my-query"
location = "US"
data_source_id = "scheduled_query"
schedule = "every 15 mins"
destination_dataset_id = "practice"
params = {
destination_table_name_template = "test_gsod"
write_disposition = "WRITE_TRUNCATE"
query = "select station_number , year , month,day, mean_temp,mean_dew_point ,mean_visibility from `bigquery-public-data.samples.gsod`"
}
}
Now it is working fine. Thanks.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.