我目前正在使用 terraform 在 GCP 上部署 Node js API 和数据库 我需要一个特定的环境来从 gcp 存储桶执行 sql 文件。 一周以来一切都很好,用于使用 terraform 进行部署的 CI 作业也正常。 但现在我在 CI 上收到此错误:
│ Error: local-exec provisioner error
│
│ with null_resource.database_eer_run_preprod_dump,
│ on cloudsql.tf line 77, in resource "null_resource" "database_db_run_preprod_sql_file":
│ 77: provisioner "local-exec" {
│
│ Error running command 'if [ "qa" = "qa" ];
│ then
│ gcloud sql import sql "cloud-sql-name"
│ gs://path/file.sql --database=db --user=user
│ --impersonate-service-account="[email protected]"
│ -q
│ fi
│ ': exit status 1. Output: WARNING: This command is using service account
│ impersonation. All API calls will be executed as
│ [[email protected]].
│ WARNING: This command is using service account impersonation. All API calls
│ will be executed as
│ [[email protected]].
│ ERROR: (gcloud.sql.import.sql) HTTPError 403: The service account does not
│ have the required permissions for the bucket.
一切都让我觉得我的服务帐户权限或从存储桶运行sql文件的命令出了问题。 但我没有改变任何东西,真正的区别就在这里,在云 sql 日志中:
{
insertId: "id"
labels: {
INSTANCE_UID: "uid"
LOG_BUCKET_NUM: "55"
}
logName: "projects/projet-name/logs/cloudsql.googleapis.com%2Fpostgres.log"
receiveTimestamp: "2023-12-14T08:49:41.092044870Z"
resource: {
labels: {
database_id: "project-name:cloud-sql-name"
project_id: "project-name"
region: "europe"
}
type: "cloudsql_database"
}
severity: "ERROR"
textPayload: "2023-12-14 08:49:40.262 UTC [27]: [1-1] db=cloudsqladmin,user=cloudsqladmin ERROR: relation "public.heartbeat" does not exist at character 13"
timestamp: "2023-12-14T08:49:40.262943Z"
}
我是 terraform 和 GCP 的新手,所以我尽力找到有关此错误的信息,据我了解,public.heartbeat 应该由 gcp 创建。
希望清楚,我的英语真的很糟糕,提前抱歉。 这是我第一次问有关堆栈溢出的问题,这对我来说是新问题,请宽容
已识别问题:
--impersonate-service-account="[email protected]"
选项,但此服务帐户没有足够的权限在 SQL 数据库上执行 SQL 命令。建议的操作(也许有效):
provisioner "local-exec"
无法直接在数据库中执行 SQL。