diff --git a/terraform/node_provisioner.go b/terraform/node_provisioner.go new file mode 100644 index 000000000..bb117c1d6 --- /dev/null +++ b/terraform/node_provisioner.go @@ -0,0 +1,44 @@ +package terraform + +import ( + "fmt" + + "github.com/hashicorp/terraform/config" +) + +// NodeProvisioner represents a provider that has no associated operations. +// It registers all the common interfaces across operations for providers. +type NodeProvisioner struct { + NameValue string + PathValue []string + + // The fields below will be automatically set using the Attach + // interfaces if you're running those transforms, but also be explicitly + // set if you already have that information. + + Config *config.ProviderConfig +} + +func (n *NodeProvisioner) Name() string { + result := fmt.Sprintf("provisioner.%s", n.NameValue) + if len(n.PathValue) > 1 { + result = fmt.Sprintf("%s.%s", modulePrefixStr(n.PathValue), result) + } + + return result +} + +// GraphNodeSubPath +func (n *NodeProvisioner) Path() []string { + return n.PathValue +} + +// GraphNodeProvisioner +func (n *NodeProvisioner) ProvisionerName() string { + return n.NameValue +} + +// GraphNodeEvalable impl. +func (n *NodeProvisioner) EvalTree() EvalNode { + return &EvalInitProvisioner{Name: n.NameValue} +} diff --git a/terraform/transform_provisioner.go b/terraform/transform_provisioner.go index 5bd3f65a1..b5945261e 100644 --- a/terraform/transform_provisioner.go +++ b/terraform/transform_provisioner.go @@ -107,7 +107,10 @@ func (t *MissingProvisionerTransformer) Transform(g *Graph) error { } // Build the vertex - var newV dag.Vertex = &graphNodeProvisioner{ProvisionerNameValue: p} + var newV dag.Vertex = &NodeProvisioner{ + NameValue: p, + PathValue: path, + } if len(path) > 0 { // If we have a path, we do the flattening immediately. This // is to support new-style graph nodes that are already @@ -178,7 +181,8 @@ func provisionerVertexMap(g *Graph) map[string]dag.Vertex { m := make(map[string]dag.Vertex) for _, v := range g.Vertices() { if pv, ok := v.(GraphNodeProvisioner); ok { - m[pv.ProvisionerName()] = v + key := provisionerMapKey(pv.ProvisionerName(), v) + m[key] = v } } @@ -212,50 +216,3 @@ func (n *graphNodeCloseProvisioner) EvalTree() EvalNode { func (n *graphNodeCloseProvisioner) CloseProvisionerName() string { return n.ProvisionerNameValue } - -type graphNodeProvisioner struct { - ProvisionerNameValue string -} - -func (n *graphNodeProvisioner) Name() string { - return fmt.Sprintf("provisioner.%s", n.ProvisionerNameValue) -} - -// GraphNodeEvalable impl. -func (n *graphNodeProvisioner) EvalTree() EvalNode { - return &EvalInitProvisioner{Name: n.ProvisionerNameValue} -} - -func (n *graphNodeProvisioner) ProvisionerName() string { - return n.ProvisionerNameValue -} - -// GraphNodeFlattenable impl. -func (n *graphNodeProvisioner) Flatten(p []string) (dag.Vertex, error) { - return &graphNodeProvisionerFlat{ - graphNodeProvisioner: n, - PathValue: p, - }, nil -} - -// Same as graphNodeMissingProvisioner, but for flattening -type graphNodeProvisionerFlat struct { - *graphNodeProvisioner - - PathValue []string -} - -func (n *graphNodeProvisionerFlat) Name() string { - return fmt.Sprintf( - "%s.%s", modulePrefixStr(n.PathValue), n.graphNodeProvisioner.Name()) -} - -func (n *graphNodeProvisionerFlat) Path() []string { - return n.PathValue -} - -func (n *graphNodeProvisionerFlat) ProvisionerName() string { - return fmt.Sprintf( - "%s.%s", modulePrefixStr(n.PathValue), - n.graphNodeProvisioner.ProvisionerName()) -} diff --git a/terraform/transform_provisioner_test.go b/terraform/transform_provisioner_test.go index db361ec0f..b3d7d4b66 100644 --- a/terraform/transform_provisioner_test.go +++ b/terraform/transform_provisioner_test.go @@ -159,18 +159,6 @@ func TestCloseProvisionerTransformer(t *testing.T) { t.Fatalf("bad:\n\n%s", actual) } } -func TestGraphNodeProvisioner_impl(t *testing.T) { - var _ dag.Vertex = new(graphNodeProvisioner) - var _ dag.NamedVertex = new(graphNodeProvisioner) - var _ GraphNodeProvisioner = new(graphNodeProvisioner) -} - -func TestGraphNodeProvisioner_ProvisionerName(t *testing.T) { - n := &graphNodeProvisioner{ProvisionerNameValue: "foo"} - if v := n.ProvisionerName(); v != "foo" { - t.Fatalf("bad: %#v", v) - } -} const testTransformMissingProvisionerBasicStr = ` aws_instance.web