You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Terraform配置MySQL到BigQuery数据传输时遇参数缺失及语法问题

解决Google Cloud Terraform MySQL到BigQuery数据传输的两个问题

问题1:Missing parameter: connector.endpoint.host 错误

该错误源于MySQL数据源的BigQuery传输配置必须指定数据库主机地址,且当前params中的参数键名未遵循MySQL传输的规范(需使用connector.前缀的嵌套参数名)。

修复步骤:

  1. 在params中添加connector.endpoint.host参数,值为你的MySQL数据库主机地址(例如公网域名、内网IP)
  2. 可选补充connector.endpoint.port(默认3306,若数据库端口非默认需指定)
  3. 将原有username、password替换为规范参数键名:connector.authentication.username、connector.authentication.password

问题2:Terraform误识别connector.authentication.password为资源引用

Terraform会将未加引号的带点键名解析为资源/属性引用,因此需将这类含点的参数键名用双引号包裹,让Terraform将其视为字符串键而非引用。

完整修复后的配置示例:

resource "google_bigquery_data_transfer_config" "mysql_to_bq_transfer" {
  display_name           = "TABLE_NAME"
  location               = "EU"
  data_source_id         = "mysql"
  destination_dataset_id = google_bigquery_dataset.bq_dataset.dataset_id
  schedule               = "every 24 hours"
  service_account_name   = google_bigquery_connection.bq_mysql_connection.connection_id

  params = {
    destination_table_name_template = "TABLE_NAME"
    write_disposition               = "APPEND"
    query                           = "SELECT * FROM `TABLE_NAME`;"  # SQL表名用反引号而非单引号
    database_name                  = "DB_NAME"
    data_path                       = "TABLE_NAME"
    "connector.endpoint.host"       = "YOUR_MYSQL_HOST"  # 引号包裹带点键名
    "connector.endpoint.port"       = "3306"             # 可选,默认3306
    "connector.authentication.username" = "USERNAME"
    "connector.authentication.password" = data.google_secret_manager_secret_version.mysql_password.secret_data
  }
}

额外提示:

  • SQL查询中的表名需用反引号(`)包裹,避免语法错误
  • 确保关联的google_bigquery_connection资源已完成MySQL访问授权配置

内容的提问来源于stack exchange,提问作者devops on the road

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 15:41:11