Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add AWS SSM like variable functionality for GCP Secrets Manager #308

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

felipegenef
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant