mirror of https://github.com/hashicorp/packer
When introducing the DAG for locals and datasources, we forgot to handle one limit case: if a dependency for a local or data is malformed, we didn't check that a vertex was associated to it, leading to the final DAG being malformed, and the DAG library would crash in this case. This commit fixes this problem by checking that the dependency does exist before attempting to add it to the graph as an edge for a vertex, so that it is reported accurately, and do that Packer doesn't crash.fix_hcl2_dag_missing_dependency
parent
d4ebc48b89
commit
d722d3c634
@ -0,0 +1,49 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/packer/packer_test/common/check"
|
||||
)
|
||||
|
||||
type malformedDepTestCase struct {
|
||||
name string
|
||||
command string
|
||||
templatePath string
|
||||
useSequential bool
|
||||
}
|
||||
|
||||
func genMalformedDepTestCases() []malformedDepTestCase {
|
||||
retVals := []malformedDepTestCase{}
|
||||
|
||||
for _, cmd := range []string{"build", "validate"} {
|
||||
for _, template := range []string{"./templates/malformed_data_dep.pkr.hcl", "./templates/malformed_local_dep.pkr.hcl"} {
|
||||
for _, seq := range []bool{true, false} {
|
||||
retVals = append(retVals, malformedDepTestCase{
|
||||
name: fmt.Sprintf("Malformed dep packer %s --use-sequential-evaluation=%t %s",
|
||||
cmd, seq, template),
|
||||
command: cmd,
|
||||
templatePath: template,
|
||||
useSequential: seq,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retVals
|
||||
}
|
||||
|
||||
func (ts *PackerDAGTestSuite) TestMalformedDependency() {
|
||||
pluginDir := ts.MakePluginDir()
|
||||
defer pluginDir.Cleanup()
|
||||
|
||||
for _, tc := range genMalformedDepTestCases() {
|
||||
ts.Run(tc.name, func() {
|
||||
ts.PackerCommand().UsePluginDir(pluginDir).
|
||||
SetArgs(tc.command,
|
||||
fmt.Sprintf("--use-sequential-evaluation=%t", tc.useSequential),
|
||||
tc.templatePath).
|
||||
Assert(check.MustFail())
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
data "http" "trusted_ca_certificates" {
|
||||
method = "GET"
|
||||
url = "http://example.com/ca-bundle.crt"
|
||||
}
|
||||
|
||||
locals {
|
||||
test = data.trusted_ca_certificates.url
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
data "http" "trusted_ca_certificates" {
|
||||
method = "GET"
|
||||
url = local.no_dep
|
||||
}
|
||||
Loading…
Reference in new issue