amplify-education / serverless-vpc-discovery

Serverless plugin for discovering VPC / Subnet / Security Group configuration by name.
MIT License
38 stars 15 forks source link

Turn off for a stage #28

Closed wduminy closed 3 years ago

wduminy commented 4 years ago

When I try to exclude the vpc section for a stage that does not need it, I get the error below.
Would it not be better to print a warning? If this was done, I would be effectively able to "turn off" the plugin for a stage.

This idea might have worked before, judging from this blog

Serverless: Updating VPC config...

  Type Error ---------------------------------------------

  TypeError: Cannot read property 'vpcName' of undefined
      at VPCPlugin.updateVpcConfig (/Users/willem/projects/gitlab/webhooks/webhooks-infra/node_modules/serverless-vpc-discovery/index.js:36:28)
      at /usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:490:55
      at tryCatcher (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23)
      at Object.gotValue (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/reduce.js:168:18)
      at Object.gotAccum (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/reduce.js:155:25)
      at Object.tryCatcher (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:547:31)
      at Promise._settlePromise (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:729:18)
      at _drainQueueStep (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:93:12)
      at _drainQueue (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:86:9)
      at Async._drainQueues (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:102:5)
      at Immediate.Async.drainQueues [as _onImmediate] (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:15:14)
      at processImmediate (internal/timers.js:456:21)
      at process.topLevelDomainCallback (domain.js:137:15)
rddimon commented 3 years ago

@wduminy Hey, thank you for your request!

It looks no longer relevant, but anyway

Could you please try the latest version of the plugin?

I'm closing the issue You can rereopen it in case any questions

wduminy commented 2 years ago

Hello @rddimon

I played around with the new plug-in version but could not get a null VPC for a stage.

I hope I a missing something. Please help.

custom:
  defaultStage: sandbox # Other stages: dev, staging, prod
  vpc: ${self:custom.config.vpc.${self:provider.stage},null}
  config:
    vpc:
      sandbox: ~
      prod:
        vpcName: "aVPC"
        subnetNames:
          - 'net-001'
          - 'net-002'
          - 'net-003'
        securityGroupNames:
          - 'mysql-egress'
          - 'https-egress'

Then I get this error:

TypeError: Cannot read property 'vpcName' of null
    at VPCPlugin.updateVpcConfig (node_modules/serverless-vpc-discovery/index.js:36:28)
    at PluginManager.runHooks (node_modules/serverless/lib/classes/plugin-manager.js:520:41)
    at PluginManager.invoke (/node_modules/serverless/lib/classes/plugin-manager.js:549:20)
wduminy commented 2 years ago

@rddimon I am unable to re-open this request.

From elsewhere:

you cannot re-open your own issues if a repo collaborator closed them

rddimon commented 2 years ago

Hi @wduminy

Your custom config structure is not correct

Please read the README carefully and take a look at the example: https://github.com/amplify-education/serverless-vpc-discovery/blob/master/test/integration-tests/basic/basic-example/serverless.yml#L30

wduminy commented 2 years ago

Thank you @rddimon,

I appreciate your input.

I made a change to my code, but get the same error.

The problem is with the line sandbox: false.

In the docs, I do not see a way to specify that a specific stage must not do any VPC config. The example you supplied does not mention stages.

The config here (and above) works perfectly for the prod stage, but not for the sandbox stage. It is just a snippet.

custom:
  defaultStage: sandbox # Other stages: dev, staging, prod
  vpcDiscovery: ${self:custom.config.vpc.${self:provider.stage}}
  config:
    vpc:
      sandbox: false
      prod:
        vpcName: "aVPC"
        subnetNames:
          - 'net-001'
          - 'net-002'
          - 'net-003'
        securityGroupNames:
          - 'mysql-egress'
          - 'https-egress'
rddimon commented 2 years ago

The vpcDiscovery structure is still not correct:

custom:
  defaultStage: sandbox # Other stages: dev, staging, prod
### The main point is here, the `vpcDiscovery` structure should be like below:
  vpcDiscovery: 
    vpcName: "aVPC"
    subnetNames:
      - 'net-001'
      - 'net-002'
      - 'net-003'
    securityGroupNames:
      - 'mysql-egress'
      - 'https-egress'
###
  config:
    vpc:
      sandbox: false
      ...        
wduminy commented 2 years ago

hmm -- this is the same that i have. ${self:custom.config.vpc.${self:provider.stage}} is the structure. But I just found an embarrassing mistake; I am working with an old version. WIll let you know if it works now.

wduminy commented 2 years ago

Ok, sorry about that.

For the record here is what works.

In custom, I configure per stage

custom:
  defaultStage: sandbox # Other stages: dev, staging, prod
  config:
    vpc:
      sandbox: false
      prod:
        vpcName: "aVPC"
        subnetNames:
          - 'net-001'
          - 'net-002'
          - 'net-003'
        securityGroupNames:
          - 'mysql-egress'
          - 'https-egress'

Then for each function, I added this

functions:
  function001:
    vpcDiscovery: ${self:custom.config.vpc.${self:provider.stage}}

This is good enough for me.

rddimon commented 2 years ago

Does it work for you? Have you solved the issue Cannot read property 'vpcName' of null?

wduminy commented 2 years ago

The original suggestion as described in the blog I quoted when posting this issue is a cleaner way to do it.

If I follow the pattern described there, I get a new error. Something like: Error: 'vpcDiscovery.vpcName' is not specified. VPC not configured. Please see the README for the proper setup.

I did not write the blog; and I imagine something like that worked before. So, you might still want to do it.

But I am happy in the sense that I have a work-around for my config problem.

Thank you very much for helping.