首页 > 解决方案 > 无法为主题创建订阅

问题描述

我正在尝试使用 Google 部署管理器。

我创建了一个 YAML 文件,我在其中创建了一个主题和该主题的推送订阅。

resources:
  - name: pubsub-topic
    type: gcp-types/pubsub-v1:projects.topics
    properties:
      topic: "topic-01"
  - name: pubsub-sub
    type: gcp-types/pubsub-v1:projects.subscriptions
    properties:
      subscription: "gcf-01"
      topic: "projects/my-project/topics/topic-01"
      pushConfig: 
        pushEndpoint: "https://us-central1-my-project.cloudfunctions.net/helloWorld/"
      ackDeadlineSeconds: 600
      expirationPeriod:

当我运行命令时

cloud deployment-manager deployments create google-pub-sub --config C:\Development\GCP\DeploymentManager.yaml

我收到以下错误

部署的指纹为 xxxxxxxxxxxx== Waiting for create [operation-xxxxxxxx-xxxxxx-xxxx-xxxx]...失败。错误:(gcloud.deployment-manager.deployments.create)操作错误 [operation-xxxxx-xxxx-xxxx-xxxx]:错误:- 代码:RESOURCE_ERROR 位置:/deployments/google-pub-sub/resources/pubsub-sub消息:'{"ResourceType":"gcp-types/pubsub-v1:projects.subscriptions","ResourceErrorCode":"404","ResourceErrorMessage":{"code":404,"message":"找不到资源 ( resource=topic-01).","status":"NOT_FOUND","details":[],"statusMessage":"Not Found","re​​questPath":" https://pubsub.googleapis.

现在如果我运行命令

gcloud deployment-manager deployments update google-pub-sub --config C:\Development\GCP\DeploymentManager.yaml

有用。这是否意味着操作不是顺序的,并且系统正在尝试在创建主题之前创建订阅。

此外,我仍然无法将 ExpirationPeriod 设置为 Never。如果有人知道,请告诉我。

谢谢!!!

标签: google-cloud-platformgoogle-deployment-manager

解决方案


好吧,我通过使用 YAML 文件中的引用解决了第一个问题,所以更改后的文件看起来像

resources:
  - name: pubsub-topic
    type: gcp-types/pubsub-v1:projects.topics
    properties:
      topic: "topic-01"
  - name: pubsub-sub
    type: gcp-types/pubsub-v1:projects.subscriptions
    properties:
      subscription: "gcf-01"
      topic: $(ref.pubsub-topic.name)
      pushConfig: 
        pushEndpoint: "https://us-central1-my-project.cloudfunctions.net/helloWorld/"
      ackDeadlineSeconds: 600
      expirationPolicy: {}

推荐阅读