core: NodeProvisioner.Name update for new address types
This function was previously checking for a path length greater than one because the older path format included an always present "root" element at the start. We now need to check for a totally-empty list, because otherwise we fail to add the expected prefix to the front of a path with only one element. This also includes some adjustments to the related tests and transforms that do not change behavior but do make the test results easier to understand and debug.
This commit is contained in:
parent
e40e3b9ad8
commit
ad6bb4a1d5
|
@ -28,7 +28,7 @@ var (
|
|||
|
||||
func (n *NodeProvisioner) Name() string {
|
||||
result := fmt.Sprintf("provisioner.%s", n.NameValue)
|
||||
if len(n.PathValue) > 1 {
|
||||
if len(n.PathValue) > 0 {
|
||||
result = fmt.Sprintf("%s.%s", n.PathValue.String(), result)
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package terraform
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/hashicorp/terraform/addrs"
|
||||
"github.com/hashicorp/terraform/config/configschema"
|
||||
|
@ -57,6 +58,7 @@ func (t *ProvisionerTransformer) Transform(g *Graph) error {
|
|||
continue
|
||||
}
|
||||
|
||||
log.Printf("[TRACE] ProvisionerTransformer: %s is provisioned by %s (%q)", dag.VertexName(v), key, dag.VertexName(m[key]))
|
||||
g.Connect(dag.BasicEdge(v, m[key]))
|
||||
}
|
||||
}
|
||||
|
@ -120,6 +122,7 @@ func (t *MissingProvisionerTransformer) Transform(g *Graph) error {
|
|||
|
||||
// Add the missing provisioner node to the graph
|
||||
m[key] = g.Add(newV)
|
||||
log.Printf("[TRACE] MissingProviderTransformer: added implicit provisioner %s, first implied by %s", key, dag.VertexName(v))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -86,6 +86,7 @@ func TestMissingProvisionerTransformer_module(t *testing.T) {
|
|||
if err := tf.Transform(&g); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
t.Logf("graph after StateTransformer:\n%s", g.StringWithNodeTypes())
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -100,6 +101,7 @@ func TestMissingProvisionerTransformer_module(t *testing.T) {
|
|||
if err := transform.Transform(&g); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
t.Logf("graph after MissingProvisionerTransformer:\n%s", g.StringWithNodeTypes())
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -107,12 +109,13 @@ func TestMissingProvisionerTransformer_module(t *testing.T) {
|
|||
if err := transform.Transform(&g); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
t.Logf("graph after ProvisionerTransformer:\n%s", g.StringWithNodeTypes())
|
||||
}
|
||||
|
||||
actual := strings.TrimSpace(g.String())
|
||||
expected := strings.TrimSpace(testTransformMissingProvisionerModuleStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad:\n\n%s", actual)
|
||||
t.Fatalf("wrong result\n\ngot:\n%s\n\nwant:\n%s", actual, expected)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue