hashicorp / hashicorp/packer-plugin-googlecompute
Default behavior of build variable `-on-error=cleanup` is not being respected
- Dominant language
- Go
- Stars
- 33
- Forks
- 72
- Avg merge
- 6h 47m
- Merged PRs (30d)
- 3
Description
#### Overview of the Issue
The documented default behavior of the `-on-error` variable is `cleanup`. That means that on failure of a packer build, the VM and disk that is created should also be deleted. However, without specifying anything for the `-on-error` variable in your build, a failure will keep the VM running and disk resource allocated. This leads to resource leakage in the default case, which is in conflict with the documentation:
```website/content/docs/commands/build.mdx:- `-on-error=cleanup` (default), `-on-error=abort`, `-on-error=ask`, `-on-error=run-cleanup-provisioner` -```
It seems the default behavior is actually `abort`. I am running the plugin as part of a GitHub action pipeline.
#### Reproduction Steps
Create a build that errors out. Any error will do that causes the build step to fail without creating any resources (i.e. see the message `==> Builds finished but no artifacts were created.`)
### Plugin and Packer version
`Installed plugin github.com/hashicorp/googlecompute v1.0.15 in "/github/home/.config/packer/plugins/github.com/hashicorp/googlecompute/packer-plugin-googlecompute_v1.0.15_x5.0_linux_amd64"`
### Operating system and Environment details
My GitHub actions specify unbuntu:
```
Current runner version: '2.295.0'
Operating System
Ubuntu
20.04.4
LTS
Runner Image
Image: ubuntu-20.04
Version: 20220821.1
Included Software: https://github.com/actions/runner-images/blob/ubuntu20/20220821.1/images/linux/Ubuntu2004-Readme.md
Image Release: https://github.com/actions/runner-images/releases/tag/ubuntu20%2F20220821.1
```
### Log Fragments and crash.log files
Here is the log if you don't specify `-on-error=cleanup`:
```
==> aoc-gcp.googlecompute.aoc-gcp: Error: initializing source docker://nogood.redhat.io/rhel8/redis-6@sha256:d7c7852338717308cbb59e9303e1ea35cc8e5c01ceb2818569be20c15f3f943d: pinging container registry nogood.redhat.io: Get "https://nogood.redhat.io/v2/": dial tcp: lookup nogood.redhat.io on 169.254.169.254:53: no such host
==> aoc-gcp.googlecompute.aoc-gcp: Script exited with non-zero exit status: 125. Allowed exit codes are: [0]
==> aoc-gcp.googlecompute.aoc-gcp: Step "StepProvision" failed, aborting...
==> aoc-gcp.googlecompute.aoc-gcp: aborted: skipping cleanup of step "StepConnect"
==> aoc-gcp.googlecompute.aoc-gcp: aborted: skipping cleanup of step "StepStartTunnel"
==> aoc-gcp.googlecompute.aoc-gcp: aborted: skipping cleanup of step "StepInstanceInfo"
==> aoc-gcp.googlecompute.aoc-gcp: aborted: skipping cleanup of step "StepCreateWindowsPassword"
==> aoc-gcp.googlecompute.aoc-gcp: aborted: skipping cleanup of step "StepCreateInstance"
==> aoc-gcp.googlecompute.aoc-gcp: aborted: skipping cleanup of step "StepImportOSLoginSSHKey"
==> aoc-gcp.googlecompute.aoc-gcp: aborted: skipping cleanup of step "nullStep"
==> aoc-gcp.googlecompute.aoc-gcp: aborted: skipping cleanup of step "StepSSHKeyGen"
==> aoc-gcp.googlecompute.aoc-gcp: aborted: skipping cleanup of step "StepCheckExistingImage"
Build 'aoc-gcp.googlecompute.aoc-gcp' errored after 9 minutes 13 seconds: Script exited with non-zero exit status: 125. Allowed exit codes are: [0]
```
Here is the log if you explicitly specify `-on-error=cleanup`:
```
==> aoc-gcp.googlecompute.aoc-gcp: Error: initializing source docker://nogood.redhat.io/rhel8/redis-6@sha256:d7c7852338717308cbb59e9303e1ea35cc8e5c01ceb2818569be20c15f3f943d: pinging container registry nogood.redhat.io: Get "https://nogood.redhat.io/v2/": dial tcp: lookup nogood.redhat.io on 169.254.169.254:53: no such host
==> aoc-gcp.googlecompute.aoc-gcp: Provisioning step had errors: Running the cleanup provisioner, if present...
==> aoc-gcp.googlecompute.aoc-gcp: Deleting instance...
aoc-gcp.googlecompute.aoc-gcp: Instance has been deleted!
==> aoc-gcp.googlecompute.aoc-gcp: Deleting disk...
aoc-gcp.googlecompute.aoc-gcp: Disk has been deleted!
Build 'aoc-gcp.googlecompute.aoc-gcp' errored after 8 minutes 56 seconds: Script exited with non-zero exit status: 125. Allowed exit codes are: [0]
```
Contributor guide
Assessment
This issue has not been assessed yet.