如何为地形资源“ google_cloud_scheduler_job”修复“错误400:'job.pubsub_target.data'(TYPE_BYTES)处的无效值”

时间:2019-05-02 21:09:18

标签: google-cloud-platform terraform terraform-provider-gcp google-cloud-scheduler

我对Google Cloud Scheduler具有以下gcloud函数,该函数运行良好。但是,我不能仅仅因为pubsub_target { data = ""字段下的一个参数就知道如何将其放入terraform中。

这是我不断遇到的错误。 google_cloud_scheduler_job.c4c_intel_sources_scheduler: Error creating Job: googleapi: Error 400: Invalid value at 'job.pubsub_target.data' (TYPE_BYTES), Base64 decoding failed for "{"scheduler".......

不知道如何解决此错误

Terraform definition

resource "google_cloud_scheduler_job" "c4c_sources_scheduler" {
  name    = "${var.cluster}-sources-scheduler"
  description = "Creating Sources Scheduler Job"
  count = "${var.c4c_intel_sources_enabled ? 1 : 0}"
  provider = "google-beta"
  project = "${var.project}"
  schedule = "${var.c4c_intel_sources_schedule}"
  region="us-east1"
  pubsub_target {
    topic_name = "${google_pubsub_topic.c4c_sources_topic.id}"
    data = "{\"scheduler\": [ {\"__type\":  \"processors.google_cloud.scheduler\",\"state_bucket\": \"$STATE_BUCKET\",\"state_path\": \"scheduler_state.json\",\"config_bucket\": \"$CONFIG_BUCKET\",\"topic\": \"$TOPIC\"}]}"


等效的gcloud definition

gcloud beta scheduler jobs create pubsub shoaib-test-c4c-intel-sources-scheduler \
--schedule="0 * * * *" \
--topic="projects/eng-node-163913/topics/test-intel-sources"\
--message-body="{\"scheduler\":\ [ {\"__type\": \"processors.google_cloud.scheduler\",\\"state_bucket\": \"$STATE_BUCKET\",\"state_path\": \\"scheduler_state.json\",\\"config_bucket\": \"$CONFIG_BUCKET\",\\"topic\": \"$TOPIC\"}]}" \
--description="C4C Intel Sources Scheduler" \
--project=engineering-node

1 个答案:

答案 0 :(得分:0)

我认为您必须对pubsub_target.data元素进行Base64Encode,如其文档所示:https://www.terraform.io/docs/providers/google/r/cloud_scheduler_job.html

resource "google_cloud_scheduler_job" "job" {
  name     = "test-job"
  description = "test job"
  schedule = "*/2 * * * *"

  pubsub_target {
    topic_name = "${google_pubsub_topic.topic.id}"
    data = "${base64encode("test")}"
  }
}