Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get values from Secret Manager GCP with spring boot

Does anyone have an example of how to get values from the secret manager on GCP in a .yaml file (application.yaml or bootstrap.yaml)? Thanks!

application.yml:

spring:
 datasource:
  password: ${sm://projects/my-project/secrets/password/versions/1}

bootstrap.yml:

spring:
  cloud:
   gcp:
    secretmanager:
      enabled: true
      secret-name-prefix: 'sm://'

Unfortunately I am getting this value: projects/my-project/secrets/password/versions/1 for password :( What I am doing wrong?

like image 321
Ramona R Avatar asked Nov 01 '25 19:11

Ramona R


2 Answers

You should wrap with double quotes in your first solution and that should do it. Example:

spring:
 datasource:
  password: "${sm://projects/my-project/secrets/password/versions/1}"

If you want to get the latest version, you can just pass:

spring:
 datasource:
  password: "${sm://projects/my-project/secrets/password}"
like image 80
CaioT Avatar answered Nov 03 '25 09:11

CaioT


I used this dependency: implementation("com.google.cloud:spring-cloud-gcp-starter-secretmanager:3.2.1") and it worked

like image 33
Ramona R Avatar answered Nov 03 '25 09:11

Ramona R