local-exec vs. command-line

967 views
Skip to first unread message

Sam Darwin

unread,
Aug 3, 2018, 2:48:43 AM8/3/18
to Terraform
Hi,

Here is an interesting problem we have encountered. The summary is: when running a command within a standard bash terminal, it succeeds. When running it in a Terraform local-exec, it fails. Yet, shouldn't these be the same?

More details: the company has a legacy codebase running on an old version of nodejs 7. Node packages are out-of-date. Of course, that is real source of the problem: nodejs, npm, and the packages should be upgraded. But still, consider this. You can run "npm install" normally, and it completes. It succeeds. Great.

Then, run the same "npm install" in terraform local-exec. It gets to a part of the install where it's trying to build local extensions for websockets or something like that, it fails, and then instead of just continuing the way it typically does on the command-line, it completely crashes. The "npm install" does not finish.   
Maybe npm is correct to stop the build. Or maybe it's correct to continue further, because the websockets local extensions are not expected to always succeed. But either way, shouldn't the results be the same in local-exec versus a regular bash session?  At least the results should be consistent.
How can I have local-exec run exactly the same as a normal login session?

Terraform 0.11.7 
Ubuntu 16.04

provisioner "local-exec" {
    interpreter = ["/bin/bash", "-c"]
    command = <<EOT
      set -e -x
      cd somepath
      npm install || true
EOT

Graham Lyons

unread,
Aug 4, 2018, 6:00:33 AM8/4/18
to Terraform
Could you attach any error messages or debug logs which come from the failing command?

Sam Darwin

unread,
Aug 21, 2018, 3:46:59 PM8/21/18
to Terraform


On Saturday, August 4, 2018 at 5:00:33 AM UTC-5, Graham Lyons wrote:
Could you attach any error messages or debug logs which come from the failing command?

Hi Graham,

Both local-exec and command-line show these same errors:

command line output:

make: Entering directory '/opt/the_app/node_modules/karma/node_modules/ws/build'
  CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
bufferutil.target.mk:96: recipe for target 'Release/obj.target/bufferutil/src/bufferutil.o' failed
make: Leaving directory '/opt/the_app/node_modules/karma/node_modules/ws/build'

builderror.log:

make: *** [Release/obj.target/bufferutil/src/bufferutil.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:194:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Linux 4.4.0-1062-aws
gyp ERR! command "/usr/bin/nodejs" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /opt/the_app/node_modules/karma/node_modules/ws
gyp ERR! node -v v7.10.1
gyp ERR! node-gyp -v v3.5.0
gyp ERR! not ok

However, while terraform local-exec crashes at this point, a standard bash shell outside of terraform will continue and finish the rest of the "npm install", and exit without error, status 0.  As mentioned above, it appears the node module is attempting to build native extensions. If those fail, it's supposed to continue, since they are an optimization rather than being a requirement. Overall, the real solution is to upgrade npm and node, etc. because they are quite out-of-date. The mystery is why terraform isn't identical to bash. Ok, checking the output of commands "shopt" and "set -o", the options appear to be slightly different. Could be a reason. Neither the operating system (Ubuntu 16.04) or Terraform (v0.11.3) have been customized with respect to those bash shell options.
 
Reply all
Reply to author
Forward
0 new messages