hashicorp / hashicorp/packer

Non-zero exit code despite successful image builds

Open
#12,473 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
15.8k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

#### Community Note

* Please vote on this issue by adding a 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to the original issue to help the community and maintainers prioritize this request
* Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
* If you are interested in working on this issue or have submitted a pull request, please leave a comment

#### Overview of the Issue

When running packer build with Packer version 1.9.1 using the provided core-images.pkr.hcl template and pkvars variable file, the following errors are displayed in the log, even though the images are successfully built:
```
Error: 7 error(s) occurred:

* A capture_container_name, managed_image_name or shared_image_gallery_destination must be specified
* A capture_name_prefix, managed_image_resource_group_name or shared_image_gallery_destination must be specified
* An image_offer must be specified
* An image_sku must be specified
* Specify either a VHD (storage_account and resource_group_name), a Managed Image (managed_image_resource_group_name and managed_image_name) or a Shared Image Gallery (shared_image_gallery_destination) output (Managed Images can also be published to Shared Image Galleries)
* A storage_account must be specified
* A resource_group_name must be specified

on core-images.pkr.hcl line 16:
(source code not available)

....
PS C:\Users\NACXARESProd> $?
False
```
However when I inlcude the `only` argument - it works without errors and exit code is 0:
```
packer build -var client_id="xxx" -var client_secret="xxx" -var subscription_id=xxx -var tenant_id=xxx -var winrm_pass="xxx" -var-file core.pkvars.hcl -only 'azure-arm.win10-multi-pooled'
```
I know how to get over this issue, but the idea behind the usage of my type of structure and logic is to eliminate possible errors and code duplication in the template. Using the core_images variable I am able to quickly remove unwanted images from the build, add customizations like custom choco/msix packages installations or to have some of the images with secure_boot enabled etc. Of course, I am also open for some other suggestions/hints which can implement the desired state!

Since this is part of a pipeline - the successive jobs are dependent on the exit code of the packer build

#### Reproduction Steps
```
packer build -var client_id="xxx" -var client_secret="xxx" -var subscription_id=xxx -var tenant_id=xxx -var winrm_pass="xxx" -var-file core.pkvars.hcl
$?
```

### Packer version

1.9.1

### Simplified Packer Template

[core-images.pkr.hcl](https://gist.github.com/strasho/ce3ee208b373d170996905efce8f4c03)

### Pkvars, locals, variable definition files

[core.pkvars.hcl](https://gist.github.com/strasho/930092852f7a791142b3e5d68a9f7013)
[locals.pkr.hcl](https://gist.github.com/strasho/ffd8e49e871e5a5096421908e14fef74)
[vars-definition.pkr.hcl](https://gist.github.com/strasho/2c821da89f481ba7f05cb7445d5c7bb9)

### Operating system and Environment details
Name : Microsoft Windows Server 2019 Datacenter
OSArchitecture : 64-bit
Version : 10.0.17763
PowershellVersion : 5.1.17763.3770

### Log Fragments and crash.log files

Log file from parallel builds>
[packer-parallel.log](https://gist.github.com/strasho/ccb9b9d64ae72703b2c493660ffa6c92)

Log file from -only 'azure-arm.win10-multi-pooled' build>
[packer-single.log](https://gist.github.com/strasho/3efb442f369b0ec068b738a45cd6d801)

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the command from the issue with core-images.pkr.hcl and core.pkvars.hcl, then compare the parallel and single-build logs. Trace how the Azure image selections are validated and how the build command determines its exit code; done means the configured multi-image build completes without validation errors and returns exit code 0.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
build-system, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.