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

Add the ability to define a default value for undefined parameters #6

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

hschimpf
Copy link

@hschimpf hschimpf commented Sep 15, 2023

Hello!

I'm thinking about the possibility to define a default value for parameters that don't exist on SSM.

  • I'll be making the required changes on this PR.

Just have one question:

  • What character we could define as separator for the parameter name and the default value?

  • Since the name can't have the colon symbol in it, you think that it could be the separator @mnapoli?

    image

@hschimpf hschimpf marked this pull request as ready for review September 15, 2023 18:55
@mnapoli
Copy link
Member

mnapoli commented Sep 29, 2023

Thanks for the PR! I'm afraid this is extra logic to maintain, and the feature doesn't have great DX (creating a special syntax) 🤔

What is the use case for you? Where have you seen that need?

@hschimpf
Copy link
Author

hschimpf commented Oct 2, 2023

What is the use case for you? Where have you seen that need?

As serverless allows to set default values on variables, I already have some variables that have a default value when it's not present on the .env file.

For example, these are my current serverless.yml environment variables:

serverless.yml

provider:
  environment:
    DB_HOST: ${env:SLS_DB_HOST}
    DB_DATABASE: ${env:SLS_DB_DATABASE, self:custom.UUID}
    DB_USERNAME: ${env:SLS_DB_USERNAME, self:custom.UUID}
    DB_PASSWORD: ${env:SLS_DB_PASSWORD}

custom:
  UUID: ${self:service}-${self:provider.stage}

The UUID is generated using the service name and the current deployment stage. So when I deploy to production, the username and database is generated from the UUID. And if in the CI/CD the SLS_DB_DATABASE or SLS_DB_USERNAME is set, it will be used instead of the default value.

I want to update those values to bref-ssm to store them on AWS SSM Parameters, and if they don't exist, use the generated value using UUID like this:

serverless.yml

provider:
  environment:
    DB_HOST: bref-ssm:/${param:UUID}/DB_HOST
    DB_PORT: bref-ssm:/${param:UUID}/DB_PORT,3306
    DB_DATABASE: bref-ssm:/${param:UUID}/DB_DATABASE,${self:custom.UUID}
    DB_USERNAME: bref-ssm:/${param:UUID}/DB_USERNAME,${self:custom.UUID}
    DB_PASSWORD: bref-ssm:/${param:UUID}/DB_PASSWORD

custom:
  UUID: ${self:service}-${self:provider.stage}

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.

None yet

2 participants