-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Support passing variables via CLI #9817
Comments
If I understand correctly, the problem is for Powershell users (worsened developer experience due to environment variables being hard to use in that shell). Since we are talking about significant changes, it might be worth considering how many users are actually impacted. Do we have a way to get an estimate of the percentage of users who face this issue? So far what I have: 4% of users use extra CLI options to pass variables (i.e. they get the |
Nice to know this was taken into consideration. Really appreciate it 👍 I like the option of being able to pass either |
That is correct @mnapoli - I believe there also might be issues where given env var is already used, but that can be circumvented by just using different variable name.
These are very good points - I believe not a lot of people are impacted and I fully agree that we should wait for more feedback and interest from community. I've created this issue for feedback/discussion purposes mostly 👍 |
@pgrzesik great proposal! My feedback:
@lehmat it's a good point, still this is rather specific to terminal (and differentiates between them), so I'm not sure weather it really belongs to our docs. Still e.g AWS documents how to quote vars and we may consider to do same. |
Just a thought: what about adding It is different topic should you use only camelCase since AWS supports that in resources names etc, but letting people choose would give some freedom if it does not bring any pain on implementation side? |
@lehmat that's a good point. I've initially proposed to restrict it for two reasons (1) settle on one naming convention (2) follow convention of JS variables. But I don't have a strong opinion on that, also I'm aware that Serverless Framework is not used just by JS devs and in CLI environment it's more natural to use hyphenated strings, not camel case, so we definitely can relax that. |
Thanks @medikoo 🙇
👍
Sounds good to me 👍
I was thinking about
Sounds good to me, along with @lehmat proposal to also support |
Maybe then name it a
Totally 👍 |
Is there any update / resolution to this? I see that the https://www.serverless.com/framework/docs/providers/aws/guide/variables#referencing-cli-options documentation still exists and doesn't mention the deprecation as from #9371 |
@dls314 it is still possible to reference CLI options that are supported/documented (e.g. By the way, on the back of my head I was thinking this feature could integrate pretty naturally with parameters (
This would set (and possibly override) any WDYT? |
I see now; I saw |
I'm making use of the The alternative here for me is that I can spend the effort migrating for currency in the serverless framework (when it is unavoidably necessary), or I can spend that effort migrating IaC to CDK and minimizing the serverless framework footprint. |
The original reason was that you want to prevent typos. Wouldn't that be solvable by declaring a list of known cli options in the serverless.yml file? I am using serverless on Windows (dev) an Linux (CI) and using env vars sucks. I've considered adding cross-env as dep, or even building my own plugin that extends the cli with options and re-exposes them as a variable source. |
I think it makes a lot of sense, however, the actual use would be something like this:
as we want to assign both key and value at the same time. @mnapoli Does that sound/look good to you? @medikoo What do you think about scoping these under |
Currently this uses the |
I think that would be a bit problematic @dls314 - currently |
|
Please note my answers below @mnapoli and let me know what do you think
If I understand correctly, you mean something like that:
if that's the case then yes, user will be able to pass multiple parameters this way.
I don't think we should support something like that - I think we should support flat
I think it should work this way as params passed via CLI should be used as "overrides" essentially. |
Sounds good, it's future-proof anyway. If we decide to relax that later we always have the option 👍 LGTM! |
Sounds like a really good idea to me. Concerning multiple input, settling on It also definitely should override eventual config and dashboard settings. |
Hello everyone, this has now been released as a part of |
The newly added param value is typed as a string array, see serverless/serverless#9817
I probably missed it somewhere. Does using --param require using Serverless Dashboard? The parameters documentation (https://www.serverless.com/framework/docs/guides/parameters) is not that explicit about this requirement, it mentions that you can create the params in either serverless.yml or in Dashboard but does not say explicitly that you have to use Dashboard. But if I add something like this in the
and then does a print:
i get this error:
|
@frjtrifork It doesn't require a dashboard. If |
Thank you for getting back so quickly. It was an error on my part. I had two different serverless projects and the one I got the error about "can only be used in services deployed with Serverless Dashboard" the serverless version had been pinned to 2.72.3. In the other repository I have, I use version 3.22.0 of serverless and I get no error when using the |
The newly added param value is typed as a string array, see serverless/serverless#9817
Background
When introducing CLI options schema, we made a decision to deprecate/remove support for custom CLI options and recommended to replace their use with envrionment variables. However, it seems like environment variables can be problematic e.g. for PowerShell users (#9371 (comment)). Given that, we would like to consider adding a mechanism that would allow passing custom variables via CLI options.
Potential solutions - passing variables via CLI
Pass custom variables with single CLI option
One potential option to pass variables would be to use a single CLI option, e.g.
--variables
, in form like below:The potential problem with this approach is that the separator might introduce parsing errors if such separator should also be a part of passed variable's value.
Pass custom variables with multiple CLI options
Another potential solution would be to pass each variable separately with
--variable
flag, in form like below:This solution does not have the problem of single CLI option, but is a bit more verbose.
Accessing variables in the configuration
Separate variable source
When it comes to accessing these variables as a part of configuration file, I believe the most reasonable solution would be to access them via new variable source, e.g.
cli
orclivars
. It could look like this:The potential downside here is that
cli
orclivars
names are very similar to existingopt
source, which might cause confusion.Populate values into
options
Alternative approach would be to populate
options
that are accessible via existingopt
variable sources. The issue with this approach that it might introduce name clashes and does not seem "clean" as it will no longer have only explicit options as directly passed via CLI.Summary
In my opinion, the combination of passing such variables with multiple CLI options and having separate variable source such as
cli
would be the best way to move forward with this initiative, however, all feedback is welcome 🙇 @medikoo & @mnapoli - I would also love to hear your opinion on the listed approaches.Notes:
Multiple variable options approach has been inspired by
terraform
-var
flag for CLI variables (https://www.terraform.io/docs/language/values/variables.html)The text was updated successfully, but these errors were encountered: