Go lang service connecting to Google Cloud SQL Postgres with IAM service accounts and without password
Problem Statement
We are having postgres database in cloud sql in Google cloud
Our application is developed in Go lang and it need to connect to postgres
database using service account IAM authentication and without password
Step 1:
Configure Cloud SQL for IAM Authentication
Use this google documentation link_to_google_documentation for configuring cloud sql for iam authentication
Step 2:
Adding service account user to cloud sql
Use google documentation link for adding service account user to the database having correct rights and privilege's
Step 3:
Sample code connecting to postgres cloud sql with service account authentication.
Here one need to replace placeholders dbUserName, dbName, instanceConnectionName as per their environment.