2

I just started to study GCP deployment-manager and I'm creating a file to create one network and one subnetwork. I did a test using 2 different files (one for each) and worked fine. Now, when I combine the creation of network and subnetwork, there's 2 problems:

  1. During creation, when network finish the creation and the step of subnetwork starts, looks like that network info is not yet created and I got an error of resource not found. But If I run an update again, the subnet is created.

  2. During the delete, deployment-manager tries to delete first the network before the subnetwork and I got the message "resource is in use, you can't delete".

So,m I would like to get a help here with best practices about this. Many thanks.

My config:

main.yml

imports:
  - path: network.jinja
  - path: subnetwork.jinja

resources:
  - name: network
    type: network.jinja

  - name: subnetwork
    type: subnetwork.jinja

network.jinja

resources:
  - type: gcp-types/compute-v1:networks
    name: network-{{ env["deployment"] }}
    properties:
      routingConfig:
      routingMode: REGIONAL
      autoCreateSubnetworks: false

subnetwork.jinja

resources:
- type: gcp-types/compute-v1:subnetworks
  name: subnetwork-{{ env["deployment"] }}
  properties:
    region: us-central1
    network: https://www.googleapis.com/compute/v1/projects/XXXXXXXX/global/networks/network-{{ env["deployment"] }}
    ipCidrRange: 10.10.10.0/24
    privateIpGoogleAccess: false

1 Answers1

1

It is likely your issue resulted because Deployment Manager didn't recognize that there were dependencies between your resources. Here is a working YAML that I used:

resources:
  - type: gcp-types/compute-v1:networks
    name: network-mynet
    properties:
      routingConfig:
        routingMode: REGIONAL
      autoCreateSubnetworks: false
  - type: gcp-types/compute-v1:subnetworks
    name: subnetwork-mynet
    properties:
      region: us-central1
      network: $(ref.network-mynet.selfLink)
      ipCidrRange: 10.10.10.0/24
      privateIpGoogleAccess: false

I believe that the major difference is that in this example, the network element within the subnetworks definition uses a Deployment Manager references. By leverarging this technique, we have more of a declarative solution and relationships can be deduced.

Kolban
  • 13,794
  • 3
  • 38
  • 60
  • Thank you so much, @Kolban!!! This solves. Just tested here and the creation and delete worked fine. In fact, makes sense the reference. :) – Marcelo Marques Feb 24 '20 at 19:28