mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-25 08:21:07 -06:00
terraform: new provisioner node
This commit is contained in:
parent
e89d738679
commit
6d731b3b46
44
terraform/node_provisioner.go
Normal file
44
terraform/node_provisioner.go
Normal 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}
|
||||
}
|
@ -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())
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user