Cloud run service is unable to connect to MongodbAtlas after whitelisting nat-auto-ip-xxxxxx config

I am trying to connect to Serverless Mongodb from a service in GCP cloud run. Right now connection is only successful if I allow all IP(0..0.0.0).

I followed Serverless VPC access + NAT creation @ https://cloud.google.com/run/docs/configuring/static-outbound-ip and few other online resources. The external IP in nat config is not allowed to connect by Mongodb even after whitelisting it.

Am I missing anything?

Thanks in advance.

Hi,

With very limited information it is very hard to pinpoint what is causing this concern. However I would like to suggest enabling Firewall Logs[1] when creating a Firewall Rule using 0.0.0.0/0 and also the external IP in your NAT config.

After that, test the connection, be mindful of the error message then check the logs[2]. From the logs you will see what might be causing the issue.

[1]https://cloud.google.com/firewall/docs/using-firewall-rules-logging?_ga=2.130981004.-247269382.1694444994&_gac=1.192702296.1696375281.CjwKCAjw9-6oBhBaEiwAHv1QvMYpOOqvrgh_byAg5_NzztEpQASR0bnAEeHKQKT5BlY77ntAngK2JhoCyfIQAvD_BwE#enable
[2]https://cloud.google.com/firewall/docs/using-firewall-rules-logging?_ga=2.130981004.-247269382.1694444994&_gac=1.192702296.1696375281.CjwKCAjw9-6oBhBaEiwAHv1QvMYpOOqvrgh_byAg5_NzztEpQASR0bnAEeHKQKT5BlY77ntAngK2JhoCyfIQAvD_BwE#view-logs