Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hcl2template: only iterate on known HCP datasource #11883

Merged
merged 1 commit into from
Jul 20, 2022

Conversation

lbajolet-hashicorp
Copy link
Contributor

When we try to validate a build that contains references to
hcp_packer_image, the data is not fetched, and the value is therefore
unknown.

However, during the decoding phase for the build blocks, we attempt to
fetch the ancestry information for the current build, from the
information previously fetched from HCP.

Since we're validating, there's no way this is set, and attempting to
cast without checking causes Packer to crash on the conversion.

To avoid this, we only attempt this conversion if the value is known.

Closes #11870

When we try to validate a build that contains references to
hcp_packer_image, the data is not fetched, and the value is therefore
unknown.

However, during the decoding phase for the build blocks, we attempt to
fetch the ancestry information for the current build, from the
information previously fetched from HCP.

Since we're validating, there's no way this is set, and attempting to
cast without checking causes Packer to crash on the conversion.

To avoid this, we only attempt this conversion if the value is known.
@lbajolet-hashicorp lbajolet-hashicorp requested a review from a team as a code owner July 18, 2022 18:49
Copy link
Contributor

@nywilken nywilken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fix the issue. Let's hold until we can get the acceptance test in place. I think there might be some bugs that pop up as we test that might require moving things around a little.

Comment on lines +274 to +276
// TODO: maybe move this HCP-related logic outside that
// decode block so it's only executed during build?
if !value.IsKnown() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The information needed to deduce this association is currently only within the PackerConfig which is not directly accessible to the build command step. Originally I had this logic further up in the call stack but opted to place it here as it is dependent on the hcp packer bucket bits being available.

Not the best location for sure but hoping the code next to it provides some relevance.

@devashish-patel devashish-patel merged commit 6794c60 into main Jul 20, 2022
@devashish-patel devashish-patel deleted the fix_hcp_image_crash_unknown_value branch July 20, 2022 14:46
@github-actions
Copy link

github-actions bot commented Sep 1, 2022

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HCP Packer data sources causes Packer to crash on validate
3 participants