Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Overwriting imported values #2

Open
PatrykMilewski opened this issue Feb 1, 2020 · 5 comments
Open

Overwriting imported values #2

PatrykMilewski opened this issue Feb 1, 2020 · 5 comments

Comments

@PatrykMilewski
Copy link

Hey!

I was testing this plugin and it works great, but I found one use case, that is not supported.

I would like to import common base serverless.yml file in each stack and in some cases, I may want to overwrite some of the imported keys values. Example:
/serverless.yml

provider:
  aws: aws
  runtime: nodejs10.x
  memory: 128

/childStack/serverless.yml

custom:
  import: ../serverless.yml

provider:
  memory: 256

Is this possible to achieve this using this plugin?

@KrysKruk
Copy link
Owner

Hi @PatrykMilewski !

All already existing parameters will not be overwritten, so your example should work just fine and the final config would be:

provider:
  aws: aws
  runtime: nodejs10.x
  memory: 256

Let me know if that works for you. If not, that would be a bug.

I guess README should be more precise, sorry for that.

@PatrykMilewski
Copy link
Author

Thank you for response @KrysKruk

I can't get it to work, there is another example with outputs:

/tmp/serverless.yml

provider:
  name: aws
  stackName: ${self:custom.baseName}
  runtime: nodejs12.x
  memory: 128

/tmp/child/serverless.yml

service: example-service

plugins:
  - serverless-import-config-plugin

custom:
  baseName: baseName-example
  import: ../serverless.yml

provider:
  memorySize: 256

Then trying to check, if it works:

cd /tmp/child/
sls print

It outputs:

Serverless: Importing ../serverless.yml
service: example-service
plugins:
  - serverless-import-config-plugin
custom:
  baseName: baseName-example
  import: ../serverless.yml
provider:
  memorySize: 256

Is this expected or I'm doing something wrong?

@KrysKruk
Copy link
Owner

@PatrykMilewski I think the issue is with sls print and not the plugin itself.

sls print as coded here https://github.com/serverless/serverless/blob/master/lib/plugins/print/print.js#L100 loads config file and perform some modifications on it, but unfortunately it doesn't apply other plugins.

The log Serverless: Importing ../serverless.yml is really misleading here, but is refers to the phase when Serverless loads all plugins.

Let me know if the generated config contains informations you need. You can run sls package and then check the generated json file.

@PatrykMilewski
Copy link
Author

So I was experimenting a little bit and it looks like, you must provide provider: name: aws to make it work, otherwise Serverless won't generate json files for CloudFormation.

After adding it to child stack, it worked, but still values for provider may cause problems, for example: - - memory is overwritten correctly, but if not provided, the value from parent stack is ignored and replaced with default (1024) value

  • deploymentBucket: blockPublicAccess: true in parent stack causes package to fail with Serverless Error: Bucket name cannot contain uppercase letters. [object Object]
  • runtime works as expected and can be overwritten in child stack

And probably there are much more edge cases for provider.

@KrysKruk Do you think it would be possible to hook with your plugin to different Serverless phase? Having sls print working for checking if imports works would be extremely helpful.

I will check if it works correctly for custom key and if other plugins still work after importing then let you know, what are the results.

@PatrykMilewski
Copy link
Author

memory is overwritten correctly, but if not provided, the value from parent stack is ignored and replaced with default (1024) value

Actually it doesn't, I had typo in memorySize tag name. It works correctly.

The only problems that I've found are with provider: name and provider: deploymentBucket. There may be a lot more problems about import provider tag.

Maybe it's worth to check and mention those problems?

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

No branches or pull requests

2 participants