hashicorp / packer-plugin-googlecompute

Packer plugin for Google Compute Builder
https://www.packer.io/docs/builders/googlecompute
Mozilla Public License 2.0
23 stars 51 forks source link

[HPR-864] Error on wrapped startup script errors #135

Closed nywilken closed 1 year ago

nywilken commented 1 year ago

By default the googlecompute builder will wrap any provided startup_script_file with a custom wrapper script controlled by the plugin. Users wishing to no use the wrapper can set wrap_startup_script = false.

When using the wrapped startup script helper the results of the script is written to the instance metadata upon the completion of the startup script; the status is set to done. If the wrapper script fails or does not execute it will timeout, and cause the build to fail.

This change updates the logic for the wrapper script so that it sets the metadata status to "error", when the startup_script_file exits with a non-zero exit code. Since this is treated as an error the builder will fail the build.

It is an open question if the failed startup script should fail the build or if it should just set the metadata to error and let the user act on the status however they choose.

Closes #45

Changes Made

Testing Results

> make testacc
--- PASS: TestStepWaitStartupScript_withWrapStartupScript (0.01s)
--- PASS: TestStepWaitStartupScript_withWrapStartupScript/no-_wrapped_startup_script (0.00s)
--- PASS: TestStepWaitStartupScript_withWrapStartupScript/good_-_wrapped_startup_script (0.00s)
--- PASS: TestStepWaitStartupScript_withWrapStartupScript/failed_-_wrapped_startup_script (0.00s)
PASS
>  make test
?       github.com/hashicorp/packer-plugin-googlecompute        [no test files]
ok      github.com/hashicorp/packer-plugin-googlecompute/builder/googlecompute  12.291s
ok      github.com/hashicorp/packer-plugin-googlecompute/post-processor/googlecompute-export    0.755s
ok      github.com/hashicorp/packer-plugin-googlecompute/post-processor/googlecompute-import    0.608s
?       github.com/hashicorp/packer-plugin-googlecompute/version        [no test files]

Tests on Main

> make test
2022/12/07 15:21:09 ui: Disk has been deleted!
2022/12/07 15:21:09 ui: Waiting for any running startup script to finish...
2022/12/07 15:21:09 ui: Startup script successfully finished.
2022/12/07 15:21:09 ui: Startup script, if any, has finished running.
2022/12/07 15:21:09 ui: Waiting for any running startup script to finish...
2022/12/07 15:21:09 ui: Startup script successfully finished.
2022/12/07 15:21:09 ui: Startup script, if any, has finished running.
2022/12/07 15:21:09 ui: Waiting for any running startup script to finish...
2022/12/07 15:21:09 ui: Startup script not finished yet. Waiting...
2022/12/07 15:21:09 Retryable error: Startup script not done.
2022/12/07 15:21:19 ui: Startup script not finished yet. Waiting...
2022/12/07 15:21:19 Retryable error: Startup script not done.
2022/12/07 15:21:39 ui: Startup script not finished yet. Waiting...
2022/12/07 15:21:39 Retryable error: Startup script not done.
2022/12/07 15:22:19 ui: Startup script not finished yet. Waiting...
2022/12/07 15:22:19 Retryable error: Startup script not done.
2022/12/07 15:23:19 ui: Startup script not finished yet. Waiting...
2022/12/07 15:23:19 Retryable error: Startup script not done.
panic: test timed out after 3m0s