Git Product home page Git Product logo

serverless-import-config-plugin's People

Contributors

kryskruk avatar krzysztofgenge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

serverless-import-config-plugin's Issues

imports functions but not resources

I have two imported files. One only contains resources, prefixed by Resources:. The other contains functions and resources (with the appropriate prefixes). sls print shows the resources in the root serverless.yml and the function from the imported file, but not the imported resources.

values not parsed/fetched when imported

my serverless.environment.yml

provider:
  environment:
    AWS_PROFILE: papaya
    SERVICE: ${self:service}
    REGION: ${self:provider.region}
    STAGE: ${self:provider.stage}
    APPLE_ENDPOINT: ${ssm:/APPLE_ENDPOINT~true}
    APPLE_SECRET: ${ssm:/APPLE_SECRET~true}
    ADMIN_SECRET: ${ssm:/ADMIN_SECRET~true}
    APOLLO_KEY: ${ssm:/APOLLO_KEY~true}
    APOLLO_GRAPH_ID: Apple-oir31
    APOLLO_GRAPH_VARIANT: ${file(../../env.${opt:stag, 'dev'}.json):APOLLO_GRAPH_VARIANT}

my serverless.yml

service: papaya-berry-id
app: papaya
org: papaya

provider:
  name: aws
  profile: papaya
  runtime: nodejs12.x
  stage: ${opt:stage, 'dev'}
  region: "ap-southeast-1"
  tracing:
    lambda: true

package:
  individually: true
  excludeDevDependencies: true

plugins:
  - serverless-bundle
  - serverless-offline
  - serverless-import-config-plugin

custom:
  import:
    - ../../serverless.common.yml
    - ../../serverless.environment.yml
    - ./serverless.own.yml

functions:
  - ${file(./functions/graphql/config.yml)}

On runtime, values are:

AWS_PROFILE: 'papaya',
  SERVICE: '${self:service}',
  REGION: '${self:provider.region}',
  STAGE: '${self:provider.stage}',
  APPLE_ENDPOINT: '${ssm:/APPLE_ENDPOINT~true}',
  APPLE_SECRET: '${ssm:/APPLE_SECRET~true}',
  ADMIN_SECRET: '${ssm:/ADMIN_SECRET~true}',
  APOLLO_KEY: '${ssm:/APOLLO_KEY~true}',
  APOLLO_GRAPH_ID: 'Apple-oir31',
  APOLLO_GRAPH_VARIANT: "${file(../../env.${opt:stag, 'dev'}.json):APOLLO_GRAPH_VARIANT}",

Incorrect path to handler generated on win32 platform

Hello.
First of all thanks a lot for this plugin. I discovered a small issue which affects Windows platform.

On Windows platform the generated path to handler:

functions:
  myfeature-myaction:
    handler: actions/myaction/handler.handler

includes Windows path separator (\) instead of posix separator (/). This results in an error on AWS Lambda.
Screenshot 2020-08-25 at 9 11 10 AM

Could you kindly accept my PR with the proposed fix and publish a new version to npm repository?

Overwriting imported values

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?

values are not merged between yml files

serverless.yml

service: papaya-berry-id
app: papaya
org: papaya

provider:
  name: aws
  profile: papaya
  runtime: nodejs12.x
  stage: ${opt:stage, 'dev'}
  region: "ap-southeast-1"
  tracing:
    lambda: true
  environment: ${file(../../serverless.environment.yml)}

package:
  individually: true
  excludeDevDependencies: true

plugins:
  - serverless-bundle
  - serverless-offline
  - serverless-import-config-plugin

custom:
  import:
    - ../../serverless.common.yml
    - ./serverless.own.yml

functions:
  - ${file(./functions/graphql/config.yml)}

serverless.own.yml

provider:
  environment:
    SOME_VAR: SOME_VALUE

serverless.own.yml

AWS_PROFILE: papaya
SERVICE: ${self:service}
REGION: ${self:provider.region}
STAGE: ${self:provider.stage}
APPLE_ENDPOINT: ${ssm:/APPLE_ENDPOINT~true}
APPLE_SECRET: ${ssm:/APPLE_SECRET~true}
ADMIN_SECRET: ${ssm:/ADMIN_SECRET~true}
APOLLO_KEY: ${ssm:/APOLLO_KEY~true}
APOLLO_GRAPH_ID: Apple-oir31
APOLLO_GRAPH_VARIANT: ${file(../../env.${opt:stag, 'dev'}.json):APOLLO_GRAPH_VARIANT}

results: SOME_VAR does not exists/undefined

Working with sls3?

i dont know how to use this plugin, here is my use case:

the to be imported config:

# sls.provider.go.yml
provider:
  name: aws
  runtime: go1.x
  region: ${opt:region, 'eu-central-1'}
  stage: ${opt:stage, 'int'}
  logRetentionInDays: 90
  memorySize: 256
  lambdaHashingVersion: "20201221"
  timeout: 60
  vpc:
    securityGroupIds: ${self:custom.ENV_CONFIG.SECURITY_GROUP_IDS}
    subnetIds: ${self:custom.ENV_CONFIG.PRIVATE_SUBNET_IDS}
  stackTags: ${self:provider.tags}
  tags:
    PROJECT: 'jhps-dx'
    STACK: '${self:service}'
    REGION: '${self:provider.region}'
    STAGE: '${self:provider.stage}'
# serverless.yml
service: my-service-name

package:
  individually: true

plugins:
  - serverless-import-config-plugin

custom:
  ENV_CONFIG: ${file(serverless.${self:provider.stage}.conf.yml)}
  import:
    - ./sls.provider.go.yml

functions:
# ...

the output is this:

$ serverless deploy --verbose --conceal -s int --region eu-central-1

Environment: darwin, node 17.5.0, framework 3.2.1, plugin 6.0.0, SDK 4.3.1
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
Invalid service configuration: "provider.name" property is missing

so how is this plugin supposed to work? reading all the other issues or the docs wasnt helpful et all...

.js modules not found

Trying to import a .js file as this

  import:
    - module: config/dynamic.js
      inputs:
        var: test

will throw the following error.

Error: Cannot import config/dynamic.js
Cause: Cannot find module 'config/dynamic.js'

The problem seems to be with the import path, the issue seems to be in this check that will not fail

if (tryOrUndefined(() => statSync(pathToImport))) {

but the subsequent require will.
const importExports = require(importPath)

Removing the check fixes the problem.
A solution would be to bypass the check if the file has a .js ext or completely removing the check but don't know if that impacts something else, didn't dig too much into the code.

Cannot resolve variable Deprecation warnings with serverless 2.25.1

I'm seeing lots of deprecation warnings like below with serverless 2.25.1.

The stack actually works and did not warn with earlier versions

The variables that are warning, are actually defined AFTER the plugin is processed. It seems that the new serverless version is
emitting the warnings before running the import-config plugin.

How can I suppress the warnings?

Serverless: Deprecation warning: Variables resolver reports following resolution errors:
              - Cannot resolve variable at "provider.environment.DB_TABLE": Value not found at "self" source,

My serverless.yml looks like this:

plugins:
- serverless-import-config-plugin

custom:
  import:
    - '../include/base.yml'

provider:
  name: aws

  environment:
    DB_TABLE: ${self:custom.tableName}

Here are my deps:

├── @babel/[email protected]
├── @babel/[email protected]
├── @babel/[email protected]
├── @babel/[email protected]
├── @babel/[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

Variables not working

I have this:

forwarderArn: arn:aws:lambda:us-west-2:${self:custom.awsAccountId.${env:CI_COMMIT_BRANCH}}:function:datadog-forwarder

Works totally fine in one file but if I try to move this to another file and import it using this plugin it does not work

Could not perform GetFunction on arn:aws:lambda:us-west-2:${self:custom.awsAccountId.${env:CI_COMMIT_BRANCH}}:function:datadog-forwarder

The variables are no longer resolved

Dynamic list of imported resources

Is there a way to dinamically provide the list of resources to include depending on some other value (eg: provider.region) ?

I've tried several approaches but none of them worked.

  1. Use a variable in path
custom:
  import:
    - resources/resource.${self:provider.region}.yml

cannot find the file. I think is trying to import it before variable value expansion.

Cannot import resources/resource.${self:provider.region}.yml: the given file doesn't exist
  1. Relying on serverless variable expansion (it works well with other config elements)
custom:
  import: ${file(resources/resource.${self:provider.region}.yml):import}

cannot find the file either. I think it is the same reason.

Cannot import ${file(resources/resource.${self:provider.region}.yml):import}: the given module cannot be resolved
  Tried: 
   - ${file(resources/resource.${self:provider.region}.yml):import}/serverless.yml
   - ${file(resources/resource.${self:provider.region}.yml):import}/serverless.yaml
   - ${file(resources/resource.${self:provider.region}.yml):import}/serverless.js
  1. Finally I've tried using .js import (despite having to workaround #10)
custom:
  import: 
    - module: resources.js
      inputs:
        region: ${self:provider.region}

and resources.js being:

module.exports = ({region}) => {
    return {
        custom: {
            import: [
                `resources/resource.${region}.yml`
            ]
        }
    }
}

with the same result:

 Cause: Cannot import resources/resource.${self:provider.region}.yml: the given file doesn't exist

Does anyone know how to workaround this issue?

When merging configurations array elements comparison function is shallow

Hi there !
Thank you for supporting the plugin it's really great.
Unfortunately currently I have an issue with merging configuration fragments that contain elements in array which are objects. Take the 2 logically identical fragments for merging:

- DomainName:
    'Fn::Join':
        - ''
        - - Ref: componentsBucket
           - '.s3.${opt:region,self:provider.region}.amazonaws.com'
- DomainName:
    'Fn::Join':
        - ''
        - - Ref: componentsBucket
           - '.s3.${opt:region,self:provider.region}.amazonaws.com'

Due to the fact that uniqueness of the array elements is shallow the {Ref: componentsBucket} element will be added to the merged array which is not what we expect. current code in merge.ts:10 :

if (Array.isArray(target) && Array.isArray(source)) {
    // add unique elements of source into target
    return target.concat(source.filter(elem => !target.includes(elem)))
  }

To make it work not only for string elements you could consider using lodash differenceWith and isEqual functions to perform a deep array elements comparison. proposed solution:

if (Array.isArray(target) && Array.isArray(source)) {
    // add unique elements of source into target with deep elements equality comparison
    return target.concat(differenceWith(source, target, isEqual));
  }

If you agree with the proposed solution, could you kindly accept the PR and publish a new version to npm repository?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.