unable to connect to postgresql instance on google cloud from a spring boot app

Viewed 57

I'm trying to connect to a postgresql instance on google cloud from a spring boot application, using beans.

I created a bean:

@Bean 
@Primary
@ConfigurationProperties(prefix = "spring.datasource")
fun createConnectionPool(): DataSource {
     val config = HikariConfig()
     config.jdbcUrl = String.format("jdbc:postgresql:///%s", DB_NAME)
     config.username = DB_USER 
     config.password = DB_PASS  
     config.addDataSourceProperty("cloudSqlInstance", INSTANCE_CONNECTION_NAME)

     return HikariDataSource(config) 
 }

and the application.yml file looks like this:

spring:
   jp:
     features:
       hibernate:
         jdbc:
           lobe:
             non_contextual_creation: true
   clouds:
     gcp:
       projectId: my-project-id
       SQL:
         instance-connection-name: "my-instance"
         databaseName: "my-database-name"

but I am getting this error:

could not obtain connection to query metadata","stack_trace":"o.p.u.PSQLException: The server requested password-based authentication, but no password was provided by plugin null\n\t

but I gave it the password :(

I want to mention that I cannot give the password in application.yml (Because the password comes from an external source and I cannot access it in the application yml file)

What am I doing wrong? Any idea is welcome. thanks

0 Answers
Related