How to connect Cloud Run to a Private Cloud SQL Instance
Connecting Google Cloud Run to a private Cloud SQL instance requires careful networking configuration to ensure secure, private communication between your containerised application and database. This guide walks through the essential steps using Terraform infrastructure as code.
Overview
A private Cloud SQL instance provides enhanced security by eliminating public IP addresses and restricting access to only resources within your VPC network. This approach is ideal for production workloads where database security is paramount.
Source Code
You could find all code related to this post in Github.
Implementation
For connecting Cloud run to a private Cloud SQL instance we are going to follow these 5 steps:
- Create a Private VPC Network – Set up a custom VPC network with dedicated subnets for your resources
- Configure VPC Peering for Cloud SQL – Establish private service networking connection to allow Cloud SQL access
- Deploy Private Cloud SQL Instance – Create the database instance with private IP only (no public access)
- Configure Cloud Run with VPC Access – Connect your Cloud Run job to the private network and mount Cloud SQL volumes
- Set Up Service Account Permissions – Grant necessary IAM roles for Cloud SQL client access
1. Private VPC Network Setup
First, let’s create a dedicated VPC network with custom subnets:
resource "google_compute_network" "private_network" {
name = "private-network"
project = var.project
auto_create_subnetworks = false
}
resource "google_compute_subnetwork" "default" {
project = var.project
name = "test-subnetwork"
ip_cidr_range = "10.2.0.0/16"
region = var.region
network = google_compute_network.private_network.id
}
2. VPC Peering for Cloud SQL
Configure VPC peering to allow Cloud SQL to communicate within your private network:
resource "google_compute_global_address" "private_ip_address" {
name = "private-ip-address"
project = var.project
purpose = "VPC_PEERING"
address_type = "INTERNAL"
prefix_length = 16
network = google_compute_network.private_network.id
}
resource "google_service_networking_connection" "private_vpc_connection" {
network = google_compute_network.private_network.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_address.name]
}
3. Private Cloud SQL Instance
Create the Cloud SQL instance with private networking enabled:
resource "google_sql_database_instance" "postgres_instance" {
name = var.instance_name
database_version = var.database_version
region = var.region
project = var.project
deletion_protection = false
depends_on = [google_service_networking_connection.private_vpc_connection]
settings {
tier = var.tier
ip_configuration {
ipv4_enabled = false
private_network = google_compute_network.private_network.id
}
disk_size = var.disk_size
disk_type = var.disk_type
disk_autoresize = false
}
}
Key configuration points:
– Set `ipv4_enabled = false` to disable public IP access
– Reference your private network in `private_network`
4. Cloud Run Job with VPC Access
Configure your Cloud Run job to connect to the private network:
resource "google_cloud_run_v2_job" "k6" {
project = var.project
name = "k6-test"
location = var.region
depends_on = [docker_image.k6, docker_registry_image.k6]
template {
parallelism = 1
task_count = 1
template {
service_account = google_service_account.k6.email
timeout = "86400s"
max_retries = 1
vpc_access {
network_interfaces {
network = google_compute_network.private_network.name
subnetwork = google_compute_subnetwork.default.name
}
}
containers {
env {
name = "DB_USER"
value = var.db_user
}
env {
name = "DB_PASSWORD"
value = var.db_password
}
env {
name = "DB_HOST"
value = google_sql_database_instance.postgres_instance.private_ip_address
}
env {
name = "DB_NAME"
value = var.database_name
}
image = "${local.docker-image}:latest"
args = ["/k6", "run", "script.js"]
volume_mounts {
name = "cloudsql"
mount_path = "/cloudsql"
}
}
volumes {
name = "cloudsql"
cloud_sql_instance {
instances = [google_sql_database_instance.postgres_instance.connection_name]
}
}
}
}
}
Key configuration points:
- Create a Cloud SQL connector by mounting the cloud sql volume
- Run Cloud Run in the network created in step 1
5. Service Account Permissions
Ensure your Cloud Run service account has the necessary permissions:
resource "google_service_account" "k6" {
project = var.project
account_id = "ksix-sa"
display_name = "Service Account"
}
resource "google_project_iam_member" "k6_sql_client" {
project = var.project
role = "roles/cloudsql.client"
member = "serviceAccount:${google_service_account.k6.email}"
}
Connection Methods
To connect from Cloud Run to your Cloud SQL instance you can use the private IP address of your Cloud SQL instance:
const connectionString = `postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/${DB_NAME}?sslmode=disable`;
Where `DB_HOST` is the private IP address from `google_sql_database_instance.postgres_instance.private_ip_address`.
Summary
This configuration provides a secure, scalable foundation for connecting Cloud Run applications to private Cloud SQL instances while maintaining network isolation and following Google Cloud security best practices.
Mass comment blasting: $10 for 100k comments. All from unique blog domains, zero duplicates. I will provide a full report and guarantee Ahrefs picks them up. Email mailto:helloboy1979@gmail.com for payment info.If you received this, you know Ive got the skills.
Hey,
Here is the best Video generator for eCommerce websites like ignaciosuay.com.
If video ads feel out of reach — this changes that.
Letstok turns your existing product links into professional-looking videos in seconds.
No video team, no extra cost.
Try it free + Black Friday 50% off: https://bit.ly/LetstokAI
Best,
Kirby Ford
Letstok
香港服务器,4G8核18M宽带80G硬盘,只要一元钱!网址:host.993899.com
Hey,
I used to feel tired and low on energy after eating, and I thought it was normal.
But then I found out it could be related to blood sugar balance.
I came across a simple explanation and something that helped me feel more stable during the day.
So I shared it here if you want to check it out:
https://sites.google.com/view/bloodsugarwellnessguide/gluco-shield-pro-review
Best Regards.
wish you best and best
色即是空,空即是色
Hi,
I was just looking at ignaciosuay.com and really liked what you’re doing. Have you ever considered adding a short explainer video to help visitors understand your services faster?
We specialize in creating high-conversion videos that keep people on your page longer. I’ve actually worked on a few projects in your industry recently—would you be open to seeing a couple of samples?
Best regards,
Julian
To unsubscribe, simply reply with “unsubscribe” in the subject line.
Hi,
I was reviewing Ignaciosuay Com and noticed a few things that might be hurting your Google rankings.
Speed and SEO go hand in hand — I found some quick wins.
Check out this tool I created that shows your full speed and SEO report:
→ https://webscorecheck.com/scan/cp66974176
Quick scan — see your results instantly.
Best,
Emilie
Hi, Are You Hiring Full Time or Part Time For Your Company?
Please Let Me Know.
Thanks, Tom West
So dive in, have fun
Üsküdar Garantili Su Kaçağı Tespiti Tadilat sonrası kontrol için çağırdım, tüm tesisatı incelediler. https://naya.social/read-blog/7647
Appreciate the effort you put into this.
Hey,
I’m handing out something actually valuable for free
No hidden stuff.
Open this to join before it’s full:
https://suniljaindvg.systeme.io/6850adaf
Done in about 10 seconds.
Could land with you.
Jump in now.
If you’d like to stop receiving any further emails from me, please complete the form on my website
Hey there,
Static websites are becoming obsolete
Many companies still treat their website like a digital brochure.
Customers don’t.
Visitors now arrive expecting interaction, not just information.
They arrive with intent. Questions. Urgency.
And when they don’t get answers instantly, they leave.
No long consideration process. Just gone.
Just revenue that could have been captured but was not.
The hard truth is simple:
A website with no AI interaction is going to feel as outdated as a company that never adapted to mobile.
That transition has already started.
The newer standard is conversation. The old standard is passive pages.
See it in action now: https://theollehai.com
Thanks,
Nancee Tribolet
OllehAI
If you decide not to receive subsequent notifications from our side, please fill the form at bit. ly/fillunsubform with your domain address (URL).
Bjorkvagen 38, Dobbs Ferry, CA, USA, 91234
Hey there,
We came across your store and it looks great.
LetsTok AI allows you to generate product creatives, ads, and visuals designed for performance. It also analyzes competitor campaigns and creates similar ads tailored to your products.
If you’d like to give it a try, you can start here:
https://letstokvideo.com
Best Regards,
Kenneth Perrin
Letstok AI
Whenever you no longer want to receive future messages from our side, feel free to fill the form at bit. ly/fillunsubform with your domain address (URL).
72 Boulevard Bryas, Irondequoit, CA, USA, 95328
Hi, Hiring IT Support Admin For Your Company?
Tom West · tomwest754@gmail.com
Education: Cornell University, NY — BS / AS, Information Technology / Computer Science
Role: IT Support / Systems Administrator
Summary: Foundational IT professional managing a company’s internal technology infrastructure and employee hardware/software needs end-to-end. Handles everything from network security and cloud administration to day-to-day troubleshooting.
Key Skills: Windows / macOS / Linux Administration · M365 & Google Workspace Admin · Networking (TCP/IP, VPN, DNS) · MDM (Intune, Jamf) · Endpoint Security · Active Directory · Okta / SSO
Tools: Jira Service Desk · Zendesk · Splunk · Datadog · Powershell · Bash · Wireshark · PRTG
Hey,
Plain websites are starting to feel outdated
Many companies still treat their website like a digital brochure.
Customers don’t.
Customers treat websites like conversations now.
They come with a goal, a question, and a reason to act now.
And when they don’t get answers instantly, they leave.
No long consideration process. Just gone.
Just lost revenue.
The uncomfortable reality is this:
Very soon, websites that cannot talk back will feel old in the same way non-mobile websites felt old.
That shift is already underway.
The newer standard is conversation. The old standard is passive pages.
Leave your competitors behind: https://theollehai.com
Best,
Adrianne Saxton
OllehAI
If you choose to opt-out of any more communications from us, feel free to fill the form at bit. ly/fillunsubform with your domain address (URL).
Meininger Strasse 95, Canajoharie, CA, USA, 94498
Hi there,
We came across your WooCommerce store and really liked what you’re building.
With LetsTok AI, you can turn your product listings into ready-to-use ad creatives and videos. It also helps you find and recreate competitor ads tailored to your products.
If you’d like to explore it, you can start here:
https://letstokvideo.com
Thanks,
Louis Whited
Letstok AI
Should you choose to opt-out of subsequent emails from this campaign, just fill the form at bit. ly/fillunsubform with your domain address (URL).
4859 Bailey Drive, Cooperstown, CA, USA, 93962
Hey,
The market is quickly splitting into two groups:
Businesses using AI.
And companies slowly being pushed behind by them.
The speed of this shift is easy to underestimate until customers start expecting it everywhere.
Customers now expect websites to answer quickly, recommend clearly, and interact without making them dig through pages.
A static website is becoming weaker against an interactive AI experience.
That’s why companies are moving from: Navigation → Conversation
Olleh AI helps companies turn their websites into AI voice and chat experiences trained on their actual services, workflows, and customer questions.
The companies moving fastest are not waiting for a perfect moment.
They’re implementing AI now.
Check it now:
https://theolleh.com
Many Thanks,
Brigitte Alison
Olleh
If at any point you no longer want to receive additional messages from this message, just fill the form at bit. ly/fillunsubform with your domain address (URL).
Hauptstrasse 108, Fayetteville, CA, USA, 96132
Hi there,
We came across your store and thought it looks great.
LetsTok AI helps you create product ads and visuals without shooting or production. It also studies competitor ads and generates similar creatives tailored to your store.
If you’d like to explore it, you can start here:
https://letstalkugc.com
Best regards,,
Glinda Farrelly
Letstok AI
Should you decide not to receive subsequent emails from our side, simply fill the form at bit. ly/fillunsubform with your domain address (URL).
Rossmarkt 1, Allegany, CA, USA, 91345
Hello there,
There are only two types of businesses now:
Companies already using AI.
And businesses that will look outdated beside them.
This shift is happening faster than most companies understand.
Customers already expect instant answers. Fast recommendations. Instant interaction.
Plain websites are starting to lose against sites that can answer, guide, and qualify visitors in real time.
The shift is simple: from clicking around to asking and getting answers.
With Olleh AI, businesses can add AI voice + chat agents that understand their offer, answer visitors, capture intent, and support real workflows.
Your competitors are not waiting for “the right time.”
They’re implementing AI now.
See it in action now:
https://theolleh.com
Regards,
Darcy Hardey
Olleh
Whenever you choose to opt-out of additional emails from us, feel free to fill the form at bit. ly/fillunsubform with your domain address (URL).
4956 Ashton Lane, Fulton, CA, USA, 95913
Hello http://ignaciosuay.com/fekal0911 Owner
Hey,
Your website stood out to us, so we wanted to share something that could help.
Create AI ads, connect your social channels, and schedule content — all from one place with a free plan.
You can also scan competitor ads and recreate them for your business in seconds.
It’s completely optional, but we thought it could be useful.
Take a look here:
https://letstalkugc.com
Many Thanks,
Miles Cardenas
Letstok AI
In case you no longer want to receive further correspondence from me, please fill the form at brnd .li/delist url with your domain address (URL).
66 Stroud Rd, Dolgeville, CA, USA, 92205
Hey,
Your market is being trained into AI
Across industries, companies are already training AI systems to:
– Respond to customer questions the moment visitors ask
– Turn visitor intent into captured leads automatically
– Identify serious buyers faster
– Handle repetitive support
– Remove the friction created by old website flows
Meanwhile most websites still depend on:
– “Browse pages”
– Click menus and hope they find the right thing
– Fill out a form before getting any useful response
That way of handling visitors is becoming outdated fast.
Businesses that teach AI their services today will be harder to compete with tomorrow.
Visitors do not want to hunt through a website. They want to ask and get answers.
The business that responds first, clearly, and intelligently gets the advantage.
See it in action:
https://theolleh.com
Best Regards,
— Debbra Puglisi
OllehAI
In case you choose to opt-out of further messages from me, just fill the form at brnd .li/delist URL with your domain address (URL).
Horner Strasse 83, Liverpool, CA, USA, 94277
PcMLDuDmnPeLFGfRYnOR
https://shorturl.fm/WU7t9
Hi,
Your competitors are teaching AI their business
Right now, businesses in every industry are training AI to:
– Answer customer questions instantly
– Collect qualified interest without forcing people through static forms
– Qualify buyers
– Handle repetitive support
– Replace friction on websites
Meanwhile most websites still depend on:
– Browse page after page
– “Click menus”
– Submit forms and wait
That way of handling visitors is becoming outdated fast.
The companies training AI now are building tomorrow’s customer-attention advantage.
Customers are not patient browsers anymore. They ask direct questions.
And companies that cannot answer instantly will lose attention to the ones that can.
* See what an AI-powered website looks like:
https://theolleh.com
Best,
— Boyd Mather
The Olleh
If you no longer want to receive further messages from this campaign, kindly fill the form at brnd .li/delist webpage with your domain address (URL).
44 Rue Du Faubourg National, Chester, CA, USA, 91126
Hi there,
Waiting on AI has a real cost
A lot of teams still put AI in the “later” category.
That is the wrong read.
It is a live competitive advantage, not a future feature.
While some businesses wait, early adopters are collecting:
– More real customer questions and interaction data
– Faster response systems
– Better lead qualification
– Less wasted human time on repetitive questions
– Stronger conversion paths
The advantage builds on itself.
Quickly.
We have seen this movie before with:
– Businesses that adapted early to mobile
– E-commerce
– Search visibility
– Social distribution
Businesses that moved early built momentum while others were still debating.
AI will be bigger than all of them.
The businesses training AI on their services today are making tomorrow’s competition more difficult for everyone else.
See it in action now: https://theollehai.com
Regards,
— Bryon Barreras
OllehAI
If you wish to stop getting additional correspondence from this message, just fill the form at brnd .li/delist url with your domain address (URL).
Budapester Strasse 79, Peekskill, CA, USA, 90910
https://shorturl.fm/usWGj
Improve page rankings, increase your google standings and generate powerful backlinks!
Dailyseolinks.com – we build daily backlinks and improve google rankings every day:
1000 seo backlinks every day
Organic google traffic
Price cheap as $1
Up to 85% discount:
https://tiny.cc/daily-85deals
Dailyseolinks.com – daily backlink plans to boost your website’s backlinks everyday
Hi Sir/Madam,
With all due respect. We need you to serve as our Spokesperson/Financial Coordinator for our company and its clients in USA or Canada It’s a part-time job with a minimum salary of $5k and will only take few minutes of your time daily and it will not bring any conflict of interest in case you are working with another company. If interested email us:
representative@rohtopharmacy.org
Thanks,
Yasuhiro Yamada
Senior Executive Officer
ROHTO Pharmaceutical Co., Ltd
When you wish to stop getting further notifications from this message, kindly fill the form at brnd .li/delist URL with your domain address (URL).
Quadra 30, Chittenango, CA, USA, 92412
Hello Sir/Madam,
With all due respect. We need you to serve as our Spokesperson/Financial Coordinator for our company and its clients in USA or Canada It’s a part-time job with a minimum salary of $5k and will only take few minutes of your time daily and it will not bring any conflict of interest in case you are working with another company. If interested email us:
representative@rohtopharmacy.org
Warm regards,
Yasuhiro Yamada
Senior Executive Officer
ROHTO Pharmaceutical Co., Ltd
If you wish to stop getting further correspondence from this message, just fill the form at brnd .li/delist URL with your domain address (URL).
83 Villeneuve Street, Mayville, CA, USA, 93783
Dear Sir/Madam,
With all due respect. We need you to serve as our Spokesperson/Financial Coordinator for our company and its clients in USA or Canada It’s a part-time job with a minimum salary of $5k and will only take few minutes of your time daily and it will not bring any conflict of interest in case you are working with another company. If interested email us:
representative@rohtopharmacy.org
Regards,
Yasuhiro Yamada
Senior Executive Officer
ROHTO Pharmaceutical Co., Ltd
If you wish to stop getting any more emails from me, just fill the form at brnd .li/delist url with your domain address (URL).
Heinrich Heine Platz 35, Cherry Valley, CA, USA, 90112
Hi,
We recently tried reaching out via Instagram but aren’t sure our message got through.
After reviewing Ignaciosuay Com, we thought your brand could be a strong fit for Grace Belgravia and wanted to personally extend an early access invitation.
Founded in London, Grace Belgravia is a new influencer and creator management platform designed to help brands discover creators, organise campaigns, protect content rights and measure results from one place.
Brands can invite influencers both on and off platform, manage collaborations, automate agreements, oversee content delivery and track campaign performance through a single dashboard.
As part of our early beta launch, you can use code EARLYACCESS to get the Self Service plan completely free for your first 2 months. The voucher is valid for the next 30 days.
Create your free early access account here:
https://gracebelgravia.com
If creator partnerships, influencer marketing or social media collaborations are handled by another member of your team, we’d be grateful if you could forward this invitation to them.
Best regards,
Grace Belgravia
Assalamu Alaikum,
We are a financial services and advisory firm in Saudi Arabia, representing a network of investors who have a mandate to identify viable business opportunities and projects for potential investment and debt financing.
Our investors, based in the Gulf region, are actively seeking opportunities to expand their global portfolio by investing in well-structured, commercially viable businesses and projects, whether currently operational or in the planning and development stages.
We would be pleased to learn more about your business, ongoing projects, or future expansion plans, and to explore potential areas of collaboration. We are open to discussing this opportunity via any communication channel that is most convenient for you.
Please feel free to contact me at your earliest convenience.
We look forward to the possibility of working together.
Yours faithfully,
Ahmed Mohammed
Please Reply to: info@ahmedconsultant.org
Dear Beloved,
My name is Mr. Andrew Walters. I have been battling cancer for the past four years, and my condition has continued to deteriorate. As I face these circumstances, I am seeking a trustworthy individual to help fulfil a final charitable wish that is deeply important to me.
I wish to entrust you with the oversight of a humanitarian project valued at $25,000,000, intended to support the less privileged. I understand that receiving such a message from someone you have never met may seem unusual, and perhaps even concerning, but I have reached a point where I must rely on goodwill and integrity.
I am in need of a reliable confidant who can assist in ensuring that this act of generosity is carried out honourably. If you are willing and able to support this cause, your assistance would be sincerely appreciated.
Due to my health, time is of great importance. I kindly request your prompt response.
Kind regards,
Mr. Andrew Walters
Contact: andrew.walters@thevanguardgroups.org