Reputation: 41
I am trying to test setting up GCP Cloud Scheduler Jobs via terraform and am discovering issues when trying to create via the API. I am also testing the API in on this page: projects.locations.jobs/create. The errors I am seeing are around an invalid argument:
{
"error": {
"code": 400,
"message": "Job name must be formatted: \"projects/\u003cPROJECT_ID\u003e/locations/\u003cLOCATION_ID\u003e/jobs/\u003cJOB_ID\u003e\".",
"status": "INVALID_ARGUMENT"
}
}
I then modify to fit that format and see this error:
{
"error": {
"code": 400,
"message": "Resource name should start with \"/projects/\u003cPROJECT_ID\u003e/\"",
"status": "INVALID_ARGUMENT"
}
}
Here's what the request body looks like:
{
"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"
}
There's really no winning, all requests get ERROR 400.
Upvotes: 2
Views: 4485
Reputation: 41
Worked correctly this way:
{
"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"
}
or with 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}\"}")}"
}
}
Upvotes: 2