Add AWS SSM like variable functionality for GCP Secrets Manager
The Idea here is to make an alternative like AWS SSM variables from AWS provider on GCP provider.
How to use it
Add a variable to your GCP Secrets Manager and call gcp-sm passing key value and a default value (optional).
Example of serverless.yml:
service: serverless-gcp-js
provider:
name: google
runtime: nodejs18
region: ${file(./config/config.json):region}
project: ${file(./config/config.json):project}
credentials: ${file(./config/config.json):creds-file-path}
environment:
VAR1: ${gcp-sm(VAR1)} # Simplest way. Throw error if not found
VAR2: ${gcp-sm(VAR2,"Default Var")} # Uses "Default Var" as value if not found
VAR3: ${gcp-sm(VAR3-${opt:stage},"Default Var")} # Search for VAR3- + your stage passed on --stage (error if not passed). If value not found , uses "Default Var" as value
VAR4: ${gcp-sm(VAR4-${opt:stage,"dev"},"Default Var")} # Search for VAR4- + your stage passed on --stage. If stage not found, uses VAR4-dev as default
# If value above not found , uses "Default Var" as value
frameworkVersion: "3"
plugins:
- serverless-google-cloudfunctions
package:
exclude:
- node_modules/**
- .gitignore
- .git/**
functions:
first:
handler: http
events:
- http: path
second:
handler: http
environment:
VAR1: ${gcp-sm(VAR1)} # Simplest way. Throw error if not found
VAR2: ${gcp-sm(VAR2,"Default Var")} # Uses "Default Var" as value if not found
VAR3: ${gcp-sm(VAR3-${opt:stage},"Default Var")} # Search for VAR3- + your stage passed on --stage (error if not passed). If value not found , uses "Default Var" as value
VAR4: ${gcp-sm(VAR4-${opt:stage,"dev"},"Default Var")} # Search for VAR4- + your stage passed on --stage. If stage not found, uses VAR4-dev as default
# If value above not found , uses "Default Var" as value
events:
- http: path
Add AWS SSM like variable functionality for GCP Secrets Manager
The Idea here is to make an alternative like AWS SSM variables from AWS provider on GCP provider.
How to use it
Add a variable to your GCP Secrets Manager and call
gcp-sm
passing key value and a default value (optional).Example of serverless.yml
: