opentofu/terraform/node_provisioner.go
Martin Atkins ad6bb4a1d5 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.
2018-10-16 18:48:28 -07:00

52 lines
1.2 KiB
Go

package terraform
import (
"fmt"
"github.com/hashicorp/terraform/addrs"
"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 addrs.ModuleInstance
// 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
}
var (
_ GraphNodeSubPath = (*NodeProvisioner)(nil)
_ GraphNodeProvisioner = (*NodeProvisioner)(nil)
_ GraphNodeEvalable = (*NodeProvisioner)(nil)
)
func (n *NodeProvisioner) Name() string {
result := fmt.Sprintf("provisioner.%s", n.NameValue)
if len(n.PathValue) > 0 {
result = fmt.Sprintf("%s.%s", n.PathValue.String(), result)
}
return result
}
// GraphNodeSubPath
func (n *NodeProvisioner) Path() addrs.ModuleInstance {
return n.PathValue
}
// GraphNodeProvisioner
func (n *NodeProvisioner) ProvisionerName() string {
return n.NameValue
}
// GraphNodeEvalable impl.
func (n *NodeProvisioner) EvalTree() EvalNode {
return &EvalInitProvisioner{Name: n.NameValue}
}