I'm trying to connect from Google Cloud Run to MongoDB using VPC and peer networking but I can't seem to establish a connection. The goal is to be able to connect from Cloud Run to Atlas while only allowing a certain IP range.
My setup is:
- MongoDB Atlas running on Google Cloud.
- A Google Cloud Run container running a NodeJS server on the same region as MongoDB atlas (although that shouldn't matter as far as I can tell).
I have taken the following steps:
Create a VPC on the Google Cloud side following instructions from https://cloud.google.com/vpc/docs/using-vpc.
Setup a network peering between my VPC and the MongoDB Atlas VPC: https://docs.atlas.mongodb.com/security-vpc-peering/
Setup serverless VPC access using a connector: https://cloud.google.com/vpc/docs/configure-serverless-vpc-access
Re-deployed cloud run container using the connector above: https://cloud.google.com/run/docs/configuring/connecting-vpc
Added the CIDR range from step 3 to the whitelist in MongoDB atlas and removed the previous open range 0.0.0.0/0.
All steps succeed (green dots etc) but when I try to connect after step 5 the connection fails. What am I missing?