Unable to read environment variable from Cloud Foundry MySql service instance

Hi Guys,

I am trying to read connection url environment variable of CF MySql service inside application.conf file like below:

${?cloud.services.dev5.connection.url}

Note: dev5 is my service name.

Problem: It looks like none of the system provided environment variable are being read whereas if I create user provided environment variable then those are getting read.

Any idea what could be an issue?

Thanks!

PS: It is Play framework with Scala trying to connect to MySql CF service.

I am following this article
https://www.playframework.com/documentation/2.6.x/Deploying-CloudFoundry

My CF env output is like below:

“VCAP_SERVICES”: {
“user-provided”: [
{
“binding_name”: null,
“credentials”: {
“uri”: “someurl”
},
“instance_name”: “somename”,
“label”: “user-provided”,
“name”: “somename”,
“syslog_drain_url”: “”,
“tags”: [],
“volume_mounts”: []
}
]
}
}
I have tried below format to read configuration:
slick.dbs.default.db.url = “jdbc:mysql://x.x.x.x:3306/dev5?serverTimezone=UTC” slick.dbs.default.db.user = {?cloud.services.dev5.connection.username} slick.dbs.default.db.password = {?cloud.services.dev5.connection.password}

any help please?

What sort of errors do you get ?

Are you sure you’ve binded the db service to your application?

Have you tried just using the uri directly ?

And are you making sure that the app you push to your cf environment uses the correct config?

1 Like

Hi Arnbak,

Thanks for reply.

I get error for connection string being empty. Since ${?cloud.services…} environment variables are not getting resolved, connection string gets empty value and database connection fails.

If I do cf env my-app and copy paste connection url in application.conf file then database connection works fine.

I have also created custom environment variable using cf set-env command and it is getting resolved in application.conf file.

So only system provided environment variables are not getting resolved.

Any idea where should I look more closely?

Thanks!

Hi All,

What was the conclusion on this?

I’m encountering the same problem, but with PostgreSQL. Configuration keys “cloud.services…” doesn’t seem to be present.