mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
d2e9c35007
Fixes #9840 The new apply graph wasn't properly nesting provisioners. This resulted in reading the provisioners being nil on apply in the shadow graph which caused the crash in the above issue. The actual cause of this is that the new graphs we're moving towards do not have any "flattening" (they are flat to begin with): all modules are in the root graph from the beginning of construction versus building a number of different graphs and flattening them. The transform that adds the provisioners wasn't modified to handle already-flat graphs and so was only adding provisioners to the root module, not children. The change modifies the `MissingProvisionerTransformer` (primarily) to support already-flat graphs and add provisioners for all module levels. Tests are there to cover this as well. **NOTE:** This PR focuses on fixing that specific issue. I'm going to follow up this PR with another PR that is more focused on being robust against crashing (more nil checks, recover() for shadow graph, etc.). In the interest of focus and keeping a PR reviewable this focuses only on the issue itself.
116 lines
2.4 KiB
Go
116 lines
2.4 KiB
Go
package terraform
|
|
|
|
import (
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestApplyGraphBuilder_impl(t *testing.T) {
|
|
var _ GraphBuilder = new(ApplyGraphBuilder)
|
|
}
|
|
|
|
func TestApplyGraphBuilder(t *testing.T) {
|
|
diff := &Diff{
|
|
Modules: []*ModuleDiff{
|
|
&ModuleDiff{
|
|
Path: []string{"root"},
|
|
Resources: map[string]*InstanceDiff{
|
|
// Verify noop doesn't show up in graph
|
|
"aws_instance.noop": &InstanceDiff{},
|
|
|
|
"aws_instance.create": &InstanceDiff{
|
|
Attributes: map[string]*ResourceAttrDiff{
|
|
"name": &ResourceAttrDiff{
|
|
Old: "",
|
|
New: "foo",
|
|
},
|
|
},
|
|
},
|
|
|
|
"aws_instance.other": &InstanceDiff{
|
|
Attributes: map[string]*ResourceAttrDiff{
|
|
"name": &ResourceAttrDiff{
|
|
Old: "",
|
|
New: "foo",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
|
|
&ModuleDiff{
|
|
Path: []string{"root", "child"},
|
|
Resources: map[string]*InstanceDiff{
|
|
"aws_instance.create": &InstanceDiff{
|
|
Attributes: map[string]*ResourceAttrDiff{
|
|
"name": &ResourceAttrDiff{
|
|
Old: "",
|
|
New: "foo",
|
|
},
|
|
},
|
|
},
|
|
|
|
"aws_instance.other": &InstanceDiff{
|
|
Attributes: map[string]*ResourceAttrDiff{
|
|
"name": &ResourceAttrDiff{
|
|
Old: "",
|
|
New: "foo",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
b := &ApplyGraphBuilder{
|
|
Module: testModule(t, "graph-builder-apply-basic"),
|
|
Diff: diff,
|
|
Providers: []string{"aws"},
|
|
Provisioners: []string{"exec"},
|
|
DisableReduce: true,
|
|
}
|
|
|
|
g, err := b.Build(RootModulePath)
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
if !reflect.DeepEqual(g.Path, RootModulePath) {
|
|
t.Fatalf("bad: %#v", g.Path)
|
|
}
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
expected := strings.TrimSpace(testApplyGraphBuilderStr)
|
|
if actual != expected {
|
|
t.Fatalf("bad: %s", actual)
|
|
}
|
|
}
|
|
|
|
const testApplyGraphBuilderStr = `
|
|
aws_instance.create
|
|
provider.aws
|
|
aws_instance.other
|
|
aws_instance.create
|
|
provider.aws
|
|
meta.count-boundary (count boundary fixup)
|
|
aws_instance.create
|
|
aws_instance.other
|
|
module.child.aws_instance.create
|
|
module.child.aws_instance.other
|
|
module.child.provider.aws
|
|
module.child.provisioner.exec
|
|
provider.aws
|
|
module.child.aws_instance.create
|
|
module.child.provider.aws
|
|
module.child.provisioner.exec
|
|
module.child.aws_instance.other
|
|
module.child.aws_instance.create
|
|
module.child.provider.aws
|
|
module.child.provider.aws
|
|
provider.aws
|
|
module.child.provisioner.exec
|
|
provider.aws
|
|
`
|