1

我有以下gcloud谷歌云调度程序的功能,它工作得很好。但是,由于字段下的一个参数,我无法弄清楚如何将其放入 terraform 中pubsub_target { data = ""

这是我不断收到的错误。 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
4

1 回答 1

1

我认为您必须对 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")}"
  }
}
于 2019-06-20T07:07:08.917 回答