terraform: new provisioner node

This commit is contained in:
Mitchell Hashimoto 2017-01-26 21:02:55 -08:00
parent e89d738679
commit 6d731b3b46
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
3 changed files with 50 additions and 61 deletions

View File

@ -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}
}

View File

@ -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())
}

View File

@ -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