简体   繁体   English

尝试使用 terraform 使用 google_bigquery_data_transfer_config 复制数据时出错

[英]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.

相关问题 在 terraform 模块中使用列表(字符串)数据类型时出错 - getting error while using list(string) data type in terraform module Google BigQuery 数据传输 - 数据集复制 - Google BigQuery data transfer - dataset copy 在Terraform中使用python加载csv数据到bigquery - Loading csv data to bigquery using python in Terraform 在谷歌云中,使用命令“terraform apply”时出现此错误? - In google cloud, I am getting this error while using the command "terraform apply"? 使用 pandas to_gbq 在 Google BigQuery 中创建表时读取数据时出现 400 错误 - 400 Error while reading data using pandas to_gbq to create a table in Google BigQuery 使用 Cloud Data Fusion 将数据从 SFTP 提取到 GCS 或 BigQuery 时出错 - Error while Data Ingestion from SFTP to GCS or BigQuery using Cloud Data Fusion 使用 Databricks 将数据写入 Bigquery 时出错 Pyspark - Error writing data to Bigquery using Databricks Pyspark 使用 AWS SCT 进行 Redshift 数据传输的 Bigquery 失败了吗? - Bigquery to Redshift data transfer using AWS SCT failing? 使用 Apache Airflow 在 Google 数据目录中创建分类时出错 - Error while creating Taxonomy in Google Data Catalog using Apache Airflow 使用 PySpark 从 BigQuery 读取和写入数据:错误 `Failed to find data source: bigquery` - Reading and writing data from BigQuery, using PySpark: ERROR `Failed to find data source: bigquery`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM