GCP 部署管理器未创建网络对等互连

GCP Deployment Manger not creating network peerings

我有一个 deploymgr 模板,它创建了一堆网络资产和虚拟机,它运行良好,没有报告任何错误,但是从来没有创建过 VPC 对等互连。如果我通过控制台或通过 glcoud

在 cli 上创建对等互连,它工作正常

对等连接失败(没有错误消息):

# Create the required routes to talk to prod project
- name: mytest-network
  type: compute.v1.network
  properties:
    name: mytest
    autoCreateSubnetworks: false
    peerings:
    - name: mytest-to-prod
      network: projects/my-prod-project/global/networks/default
      autoCreateRoutes: true

对等工作:

$ gcloud compute networks peerings create mytest-to-prod --project=myproject --network=default --peer-network=projects/my-prod-project/global/networks/default --auto-create-routes

gcloud 按预期工作,请更新您的 YAML 文件以在指定对等网络资源列表时使用“peerings[].network”。

无法根据 the API reference 在网络创建时完成对等互连。 首先需要创建网络,一旦创建成功,需要调用 the addPeering 方法。 这解释了为什么您的 YAML 定义创建了网络而不是对等互连,并且它在 运行 它调用 addPeering 方法的 gcloud 命令之后起作用。

可以使用 Deployment manager 操作在一个 YAML 文件上创建和执行对等互连:

resources:
- name: mytest-network1
  type: compute.v1.network
  properties:
    name: mytest1
    autoCreateSubnetworks: false

- name: mytest-network2
  type: compute.v1.network
  properties:
    name: mytest2
    autoCreateSubnetworks: false

- name: addPeering2-1
  action: gcp-types/compute-v1:compute.networks.addPeering
  metadata:
    runtimePolicy:
    - CREATE
  properties:
    network: mytest-network2
    name: vpc-2-1
    autoCreateRoutes: true
    peerNetwork: $(ref.mytest-network1.selfLink)
  metadata:
    dependsOn:
    - mytest-network1
    - mytest-network2

- name: addPeering1-2
  action: gcp-types/compute-v1:compute.networks.addPeering
  metadata:
    runtimePolicy:
    - CREATE
  properties:
    network: mytest-network1
    name: vpc-1-2
    autoCreateRoutes: true
    peerNetwork: $(ref.mytest-network2.selfLink)
  metadata:
    dependsOn:
    - mytest-network1
    - mytest-network2

您可以复制粘贴上面的 YAML,创建部署并完成对等互连。操作使用 dependsOn option to make sure the network are created first and when deleting the deployment the peerings would be deleted by calling the removePeering method 然后网络将被删除。

注意:部署管理器操作尚未记录,但 GoogleCloudPlatform/deploymentmanager-samples repository such as this and this 中有几个示例。