google-cloud-platformgoogle-apigoogle-api-python-clientgoogle-deployment-manager

How to send a http patch method for a Google Cloud Deployment Manager resource using a python template


I'm creating a HA VPN using Google Cloud Deployment Manager using the following guide:

https://cloud.google.com/network-connectivity/docs/vpn/how-to/creating-ha-vpn#api_4

As part of the guide there is a requirement to send a Patch to the existing cloud router already created, however I haven't been able to find a way to set a patch request in my python template.

The resource is currently setup as below in my python template:

resources.extend([
        {
        # Cloud Router resource for HA VPN.
        'name': 'cloud_router',
        # https://cloud.google.com/compute/docs/reference/rest/v1/routers
        'type': 'gcp-types/compute-v1:routers',
        'properties':
            {
                'router': cloud_router,
                'name': cloud_router,
                'project': project_id,
                'network': network,
                'region': context.properties['region'],
                'interfaces': [{
                "name": f"{cloud_router}-bgp-int-0",
                "linkedVpnTunnel": "vpn_tunnel",
                "ipRange":
context.properties[f"bgp_ip_0"]+context.properties[f"subnet_mask_0"]
                }],
            },
            'metadata': {
                    'dependsOn': [
                        f"{vpn_tunnel}0",
                        f"{vpn_tunnel}1",
                        cloud_router,
                        ]
                    }
    }
}
)]

The rest of the resources (vpn_tunnel, vpnGateway, ExternalVPNGateway, cloud router) all create fine as a post request on the Deployment Manager console.

The error I receive is related to the "linkedVPNTunnel" value which is the name of the VPNTunnel used as per the How to guide. If I remove this field the resource is recreated via the POST request, however the bgp peer isn't associated to the tunnel as required because of the missing field.


Solution

  • Found the problem.

    The methods listed on the API site can be appended directly to the end of the 'type' field or alternatively the 'action' field can be used but isn't recommended.

    This allowed me to send a http PACT request:

    'type': 'gcp-types/compute-v1:compute.routers.patch'

    Previously I had the below which resulted in a POST:

    'type': 'gcp-types/compute-v1:routers'