https://pulumi.com logo
s

stale-knife-36790

04/06/2020, 8:52 AM
Can Pulumi deploy multiple folders/files /layers to GCP? (Google cloud platform, Cloud functions)? 🤔 (For some reason it only wants to deploy 'index.js' and now it doesn't recognize my (exported) functions which are in another file. (I use node.js)
l

limited-rainbow-51650

04/06/2020, 8:57 AM
Pulumi starts with
index.js
. Did you import/require your other files/folders in
index.js
?
s

stale-knife-36790

04/06/2020, 9:01 AM
@limited-rainbow-51650 Yes, I have required them within the index.js. I tried it with npm mode 'path' (__dirname) and without. With (const gs = require(path.resolve(__dirname, './crud.js')); ):
Copy code
Error: function terminated. Recommended action: inspect logs for termination reason. Details:
Cannot find module '/srv/crud.js'
Without (const gs = require('./crud.js'); ):
Copy code
Error: function terminated. Recommended action: inspect logs for termination reason. Details:
Cannot find module './crud.js'
l

limited-rainbow-51650

04/06/2020, 9:02 AM
Drop the
.js
in your import or require statement
1
import 'crud'
or
require './crud'
No file extension…
s

stale-knife-36790

04/06/2020, 9:07 AM
In that case I'm getting a serializing error.
Copy code
error: Error serializing '() => { const app = express(); ...': index.js(10,21)

    '() => { const app = express(); ...': index.js(10,21): referenced
      function 'POSTRequest': index.js(29,26): which captured
        module './crud.js' which indirectly referenced
          function 'read': crud.js(112,25): which captured
            variable 'datastore' which indirectly referenced
              function 'DatastoreRequest': request.js(51,0): which referenced
                function 'wrapper': index.js(31,29): which referenced
                  function 'slice': which could not be serialized because
                    it was a native code function.

    Function code:
      function slice() { [native code] }

    Capturing modules can sometimes cause problems.
    Consider using import('./crud.js') or require('./crud.js') inside function 'POSTRequest': index.js(29,26)

    (node:20088) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 2)
I fixed that with require in every function (const gs = require('./crud.js'); ) since my functions are called via gs.read() or gs.create() - this worked on its own
@limited-rainbow-51650
l

limited-rainbow-51650

04/06/2020, 9:45 AM
This issue is related to building the closure which needs to be deployed to Google Functions. Someone from Pulumi will have to answer that. I don’t have any experience on that.
s

stale-knife-36790

04/06/2020, 9:46 AM
Alright! Thanks for your help!
😉 1
I made the following github issue regarding the problem. https://github.com/pulumi/pulumi-gcp/issues/315