GCP VPC-Peering setup for CloudSQL fails with "INVALID_ARGUMENT: The resource id 917163699144/global/networks/projects/barbarus-game is invalid"

Viewed 358

I am following this guide https://cloud.google.com/sql/docs/mysql/configure-private-services-access#gcloud to setup a VPC private peering connection so my GKE nodes can connect to the CloudSQL instance.

However when following the steps I receive an error that stops me from continuing. Here are the steps I take:

#1 Check if addresses exist

➜  google-cloud-sdk gcloud compute addresses list                                  
Listed 0 items.

#2 Setup an new address range

➜  google-cloud-sdk gcloud compute addresses create google-managed-services-default \
--global \
--purpose=VPC_PEERING \
--prefix-length=16 \
--network=projects/barbarus-game/global/networks/default
Created [https://www.googleapis.com/compute/v1/projects/barbarus-game/global/addresses/google-managed-services-default].

#3 Assert success

➜  google-cloud-sdk gcloud compute addresses list                                    
NAME                             ADDRESS/RANGE  TYPE      PURPOSE      NETWORK  REGION  SUBNET  STATUS
google-managed-services-default  10.77.0.0/16   INTERNAL  VPC_PEERING  default                  RESERVED

#4 Continue with next stop of creating a private connection

➜  google-cloud-sdk gcloud services vpc-peerings connect \
--service=servicenetworking.googleapis.com \
--ranges=google-managed-services-default \
--network=projects/barbarus-game/global/networks/default \
--project=barbarus-game
ERROR: (gcloud.services.vpc-peerings.connect) INVALID_ARGUMENT: The resource id 917163699144/global/networks/projects/barbarus-game is invalid.
Help Token: Ae-hA1NzWbuVH5BSUV2Fn4IdzVTSjiWy2a10u_PyDO5qRIWbTeWzT7-2ybQxgtW_RojO1_XzicJW-NW80qKFglNlqLZKmym7S8A1mp_d2UGfwsP8
- '@type': type.googleapis.com/google.rpc.PreconditionFailure
  violations:
  - subject: ?error_code=210001&resource_id=917163699144/global/networks/projects/barbarus-game
    type: googleapis.com
- '@type': type.googleapis.com/google.rpc.ErrorInfo
  domain: servicenetworking.googleapis.com
  metadata:
    resource_id: 917163699144/global/networks/projects/barbarus-game
  reason: RESOURCES_INVALID_RESOURCE_ID

To verify I use the proper project id:

➜  google-cloud-sdk gcloud projects list
PROJECT_ID            NAME                  PROJECT_NUMBER
barbarus-game         Barbarus              917163699144

Also additionally here is the VPC network description:

➜  google-cloud-sdk gcloud compute networks describe default
autoCreateSubnetworks: false
creationTimestamp: '2021-12-01T00:17:59.241-08:00'
description: Default network for the project
id: '1930871717275275608'
kind: compute#network
name: default
peerings:
- autoCreateRoutes: true
  exchangeSubnetRoutes: true
  exportCustomRoutes: false
  exportSubnetRoutesWithPublicIp: false
  importCustomRoutes: false
  importSubnetRoutesWithPublicIp: false
  name: servicenetworking-googleapis-com
  network: https://www.googleapis.com/compute/v1/projects/m3b741e040bfc8610p-tp/global/networks/servicenetworking
  state: ACTIVE
  stateDetails: '[2021-12-09T07:56:58.748-08:00]: Connected.'
routingConfig:
  routingMode: REGIONAL
selfLink: https://www.googleapis.com/compute/v1/projects/barbarus-game/global/networks/default
subnetworks:
- [...]
x_gcloud_bgp_routing_mode: REGIONAL
x_gcloud_subnet_mode: CUSTOM

As you can see here the magic stops and I have no idea why. The project name is equivalent in the previous step (and any gcloud commands I've used before) so I have no idea why it fails.

Note The error message is kind of confusing

The resource id 1071923183712/global/networks/projects/barbarus-game is invalid.

I've never seen the network url to have projects path segment in between. It should look like this I expect (just how I passed the argument to the command):

071923183712/global/networks/barbarus-game
2 Answers

From what you posted, it looks like you are entering the PROJECT_NAME instead of the PROJECT_ID.

You should make sure to enter the PROJECT_ID, as mentioned in the guideline.

==============

The following are used to identify your project:

Project name: A human-readable name for your project.

The project name isn't used by any Google APIs. You can edit the project name at any time during or after project creation. Project names do not need to be unique.

Project ID: A globally unique identifier for your project.

A project ID is a unique string used to differentiate your project from all others in Google Cloud.

Reference

So it seems that the documentation is a bit wrong.

Instead of using this argument:

--network=projects/barbarus-game/global/networks/default

I could get it to work with simply giving the network name with the project as a separate argument

--network=default
--project=barbarus
Related