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

HCP Packer data sources causes Packer to crash on validate #11870

Closed
nywilken opened this issue Jul 8, 2022 · 1 comment · Fixed by #11883
Closed

HCP Packer data sources causes Packer to crash on validate #11870

nywilken opened this issue Jul 8, 2022 · 1 comment · Fixed by #11883

Comments

@nywilken
Copy link
Contributor

nywilken commented Jul 8, 2022

Community Note

  • Please vote on this issue by adding a 👍 reaction 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

Running packer validate on an otherwise validate build template the contains an hcp-packer-image data source block causes Packer to crash. Running a build on the template does not result in the same error.

This issue does not exist in v1.8.0 - main culprit for this issue is likely #11832

Reproduction Steps

  1. Run packer validate on template.

Packer version

v1.8.2

Simplified Packer Template

data "hcp-packer-iteration" "centos7-base" {
  bucket_name = var.hcp_bucket_name
  channel          = var.hcp_channel_name
}
data "hcp-packer-image" "centos7-base" {
  bucket_name    = data.hcp-packer-iteration.centos7-base.bucket_name
  iteration_id   = data.hcp-packer-iteration.centos7-base.id
  cloud_provider = "aws"
  region         = var.region
}
source "amazon-ebs" "centos7-web" {
  ami_name      = "${var.prefix}-centos7-web-${local.timestamp}"
  ami_regions   = ["${var.region}", "eu-west-1", "eu-north-1"]
  instance_type = "t2.micro"
  region        = var.region
  source_ami = data.hcp-packer-image.centos7-base.id
  ssh_username         = var.ssh_username
  ssh_private_key_file = var.ssh_private_key_file
  ssh_keypair_name     = var.ssh_keypair_name
}
build {
  hcp_packer_registry {
    bucket_name = "centos7-web-aws"
    description = "This is a CentOS7-based build that has been prepared as a web server in AWS."
    bucket_labels = {
      "build-version" = "0.0.1",
      "service"       = "aws"
    }
    build_labels = {
      "os"      = "centos7",
      "version" = "web"
    }
  }

  sources = ["source.amazon-ebs.centos7-web"]
}

Operating system and Environment details

All

Log Fragments and crash.log files

 packer validate .
panic: can't use ElementIterator on unknown value

goroutine 1 [running]:
github.com/zclconf/go-cty/cty.Value.ElementIterator({{{0x69f8348, 0xc000dd1860}}, {0x535f020, 0xa692de0}})
        /Users/runner/go/pkg/mod/github.com/zclconf/go-cty@v1.10.0/cty/value_ops.go:1118 +0xd8
github.com/zclconf/go-cty/cty.Value.AsValueMap({{{0x69f8348, 0xc000dd1860}}, {0x535f020, 0xa692de0}})
        /Users/runner/go/pkg/mod/github.com/zclconf/go-cty@v1.10.0/cty/value_ops.go:1324 +0xa5
github.com/hashicorp/packer/hcl2template.(*Parser).decodeBuildConfig(0x53bb660, 0xc000de91e0, 0xc00037b040)
        /Users/runner/work/packer/packer/hcl2template/types.build.go:267 +0x1b14
github.com/hashicorp/packer/hcl2template.(*Parser).parseConfig(0xc00037b040, 0xc0006ba160, 0xc00037b040)
        /Users/runner/work/packer/packer/hcl2template/parser.go:373 +0x1eb
github.com/hashicorp/packer/hcl2template.(*PackerConfig).Initialize(0xc00037b040, {0x0})
        /Users/runner/work/packer/packer/hcl2template/parser.go:326 +0x59a
github.com/hashicorp/packer/command.(*ValidateCommand).RunContext(0xc000810840, {0xc0001181a0, 0x1}, 0xc000a04000)
        /Users/runner/work/packer/packer/command/validate.go:59 +0x82
github.com/hashicorp/packer/command.(*ValidateCommand).Run(0xc000810840, {0xc0001181a0, 0x1, 0x1})
        /Users/runner/work/packer/packer/command/validate.go:25 +0xc5
github.com/mitchellh/cli.(*CLI).Run(0xc000152140)
        /Users/runner/go/pkg/mod/github.com/mitchellh/cli@v1.1.2/cli.go:262 +0x5f8
main.wrappedMain()
        /Users/runner/work/packer/packer/main.go:262 +0xaf2
main.realMain()
        /Users/runner/work/packer/packer/main.go:49 +0xf3
main.main()
        /Users/runner/work/packer/packer/main.go:35 +0x19



!!!!!!!!!!!!!!!!!!!!!!!!!!! PACKER CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Packer crashed! This is always indicative of a bug within Packer.
A crash log has been placed at "crash.log" relative to your current
working directory. It would be immensely helpful if you could please
report the crash with Packer[1] so that we can fix this.

[1]: https://github.com/hashicorp/packer/issues
@nywilken nywilken added the bug label Jul 8, 2022
@github-actions github-actions bot added the crash label Jul 8, 2022
@sylviamoss sylviamoss self-assigned this Jul 8, 2022
devashish-patel pushed a commit that referenced this issue Jul 20, 2022
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
@github-actions
Copy link

I'm going to lock this issue 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 similar to this, 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 Aug 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@nywilken @sylviamoss and others