Help: Cloud compute connection setup
I’m currently dealing with a somewhat complex setup and need guidance on the correct approach.
I’ve migrated my database from Google Cloud SQL to a PostgreSQL instance running inside a Docker container on a Compute Engine VM.
My application is hosted on a separate Compute Engine VM.
Additionally, my infrastructure is provisioned using Terraform, and the VM running the PostgreSQL container:
- Does not have a public IP
- Uses Cloud NAT for outbound internet access
Now I need to connect my application (running on another VM) to this PostgreSQL database.
I’m unsure about the correct setup for:
- Network configuration between the two VMs (private VPC communication)
- Which host/IP should be used (internal vs external)
- How to correctly construct the DATABASE_URL
- Firewall rules and port exposure (e.g., PostgreSQL on 5432)
- Any edge cases or best practices (security, private networking, IAM, latency, etc.)
What is the recommended way to securely and reliably connect my app VM to the PostgreSQL container running on another private VM within the same GCP environment?