2

我正在尝试通过 terraform 测试设置 GCP Cloud Scheduler 作业,并在尝试通过 API 创建时发现问题。我还在此页面上测试 API:projects.locations.jobs/create。我看到的错误是围绕一个无效的论点:

{
  "error": {
    "code": 400,
    "message": "Job name must be formatted: \"projects/\u003cPROJECT_ID\u003e/locations/\u003cLOCATION_ID\u003e/jobs/\u003cJOB_ID\u003e\".",
    "status": "INVALID_ARGUMENT"
  }
}

然后我修改以适应该格式并看到此错误:

{
  "error": {
    "code": 400,
    "message": "Resource name should start with \"/projects/\u003cPROJECT_ID\u003e/\"",
    "status": "INVALID_ARGUMENT"
  }
}

请求正文如下所示:

{
  "name": "projects/<my-project-id>/locations/us-central1/jobs/snapshots",
  "pubsubTarget": {
    "topicName": "disk-snapshot-function-trigger",
    "attributes": {
      "num_backups": "5",
      "project": "<my-project-id>"
    }
  },
  "schedule": "0 19 * * *",
  "timeZone": "America/Los_Angeles"
}

真的没有获胜,所有请求都会得到 ERROR 400。

4

1 回答 1

2

以这种方式正确工作:

{
  "name": "projects/PROJECT_ID/locations/us-central1/jobs/snapshots",
  "pubsubTarget": {
    "topicName": "projects/PROJECT_ID/topics/disk-snapshot-function-trigger",
    "attributes": {
      "num_backups": "5",
      "project": "PROJECT_ID"
    }
  },
  "schedule": "0 19 * * *",
  "timeZone": "America/Los_Angeles"
}

或使用 Terraform:

resource "google_cloud_scheduler_job" "snapshot_schedule" {
  provider  = "google-beta"
  name      = "snapshots"
  schedule  = "${var.snapshot_schedule}"
  time_zone = "America/Los_Angeles"
  project   = "${var.project_id}"

  pubsub_target {
    topic_name = "projects/${var.project_id}/topics/${google_pubsub_topic.trigger_disk_snapshot_function_pubsub.name}"
    data       = "${base64encode("{\"project\":\"${var.project_id}\", \"num_backups\":\"${var.num_backups}\"}")}"
  }
}
于 2019-03-12T19:57:35.013 回答