I have been deploying my Go app on Google App Engine and that is nice. Then I created a Postgresql database on a Computing Engine with this beautiful setup document of Google: https://cloud.google.com/solutions/setup-postgres
And I have created my Database and tables and thats all very nice.. The only thing I still don't know is, how do I connect to this Computing Engine from my App engine app?
In my Go code the following connection is made like this:
package core
import (
"database/sql"
"log"
_ "github.com/lib/pq"
)
var db *sql.DB
func ConnectDB(connectStr string) {
var err error
db, err = sql.Open("postgres", ("host=???? user=user password=pw
dbname=dbtest sslmode=disable")
err = db.Ping()
checkErr(err)
...
Now I see thats Google nicely explains how this can be done for cloud SQL in here:https://cloud.google.com/appengine/docs/go/cloud-sql/reference
But I want to know how I make this work for my Compute Engine with my PostgreSQL database aswell :(
UPDATE 21-03-16:
Yes I already changed it to the external ip address as host and now I see it actually connects with the database on the compute engine, HOWEVER I see why I was confused, the log and the site still show a Server error, this time saying the following in the log from the db.Ping error:
panic: dial tcp [external ip address]:5432: operation not permitted
There are already several standard firewalls with: 0.0.0.0/0 and a port numbers :80, :443 etc
Do I need to add an extra rule? And how should this rule look like? Is there more information somewhere where I can see how I should do this correctly?
UPDATE 23-03
To summarize: I want to be "authorize" my Google App Engine app on the Compute Engine to connect to my Database. How do I do this?
Somehow, this is not very clear from the google websites, eventhough this should be something trivial. I would expect clear information on the google compute\app engine site..
Now I am pretty much forced to work with CloudSQL
Conclusion:
I think it is required to use OAuth as is explained in the link provided in my own comment below