terraform: refactor NodeApplyableProvider to use NodeAbstractProvider
This is important so that the graph looks correct.
This commit is contained in:
parent
8a9e1c1527
commit
26ac58bc97
|
@ -50,10 +50,9 @@ func (b *ApplyGraphBuilder) Build(path []string) (*Graph, error) {
|
|||
// See GraphBuilder
|
||||
func (b *ApplyGraphBuilder) Steps() []GraphTransformer {
|
||||
// Custom factory for creating providers.
|
||||
providerFactory := func(name string, path []string) GraphNodeProvider {
|
||||
concreteProvider := func(a *NodeAbstractProvider) dag.Vertex {
|
||||
return &NodeApplyableProvider{
|
||||
NameValue: name,
|
||||
PathValue: path,
|
||||
NodeAbstractProvider: a,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,7 +89,7 @@ func (b *ApplyGraphBuilder) Steps() []GraphTransformer {
|
|||
),
|
||||
|
||||
// Create all the providers
|
||||
&MissingProviderTransformer{Providers: b.Providers, Factory: providerFactory},
|
||||
&MissingProviderTransformer{Providers: b.Providers, Concrete: concreteProvider},
|
||||
&ProviderTransformer{},
|
||||
&DisableProviderTransformer{},
|
||||
&ParentProviderTransformer{},
|
||||
|
|
|
@ -2,6 +2,7 @@ package terraform
|
|||
|
||||
import (
|
||||
"github.com/hashicorp/terraform/config/module"
|
||||
"github.com/hashicorp/terraform/dag"
|
||||
)
|
||||
|
||||
// ImportGraphBuilder implements GraphBuilder and is responsible for building
|
||||
|
@ -38,10 +39,9 @@ func (b *ImportGraphBuilder) Steps() []GraphTransformer {
|
|||
}
|
||||
|
||||
// Custom factory for creating providers.
|
||||
providerFactory := func(name string, path []string) GraphNodeProvider {
|
||||
concreteProvider := func(a *NodeAbstractProvider) dag.Vertex {
|
||||
return &NodeApplyableProvider{
|
||||
NameValue: name,
|
||||
PathValue: path,
|
||||
NodeAbstractProvider: a,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ func (b *ImportGraphBuilder) Steps() []GraphTransformer {
|
|||
&ImportStateTransformer{Targets: b.ImportTargets},
|
||||
|
||||
// Provider-related transformations
|
||||
&MissingProviderTransformer{Providers: b.Providers, Factory: providerFactory},
|
||||
&MissingProviderTransformer{Providers: b.Providers, Concrete: concreteProvider},
|
||||
&ProviderTransformer{},
|
||||
&DisableProviderTransformerOld{},
|
||||
&PruneProviderTransformer{},
|
||||
|
|
|
@ -48,10 +48,9 @@ func (b *PlanGraphBuilder) Build(path []string) (*Graph, error) {
|
|||
// See GraphBuilder
|
||||
func (b *PlanGraphBuilder) Steps() []GraphTransformer {
|
||||
// Custom factory for creating providers.
|
||||
providerFactory := func(name string, path []string) GraphNodeProvider {
|
||||
concreteProvider := func(a *NodeAbstractProvider) dag.Vertex {
|
||||
return &NodeApplyableProvider{
|
||||
NameValue: name,
|
||||
PathValue: path,
|
||||
NodeAbstractProvider: a,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,7 +97,7 @@ func (b *PlanGraphBuilder) Steps() []GraphTransformer {
|
|||
&TargetsTransformer{Targets: b.Targets},
|
||||
|
||||
// Create all the providers
|
||||
&MissingProviderTransformer{Providers: b.Providers, Factory: providerFactory},
|
||||
&MissingProviderTransformer{Providers: b.Providers, Concrete: concreteProvider},
|
||||
&ProviderTransformer{},
|
||||
&DisableProviderTransformer{},
|
||||
&ParentProviderTransformer{},
|
||||
|
|
|
@ -1,61 +1,8 @@
|
|||
package terraform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform/config"
|
||||
)
|
||||
|
||||
// NodeApplyableProvider represents a provider during an apply.
|
||||
//
|
||||
// NOTE: There is a lot of logic here that will be shared with non-Apply.
|
||||
// The plan is to abstract that eventually into an embedded abstract struct.
|
||||
type NodeApplyableProvider struct {
|
||||
NameValue string
|
||||
PathValue []string
|
||||
Config *config.ProviderConfig
|
||||
}
|
||||
|
||||
func (n *NodeApplyableProvider) Name() string {
|
||||
result := fmt.Sprintf("provider.%s", n.NameValue)
|
||||
if len(n.PathValue) > 1 {
|
||||
result = fmt.Sprintf("%s.%s", modulePrefixStr(n.PathValue), result)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// GraphNodeSubPath
|
||||
func (n *NodeApplyableProvider) Path() []string {
|
||||
return n.PathValue
|
||||
}
|
||||
|
||||
// GraphNodeReferencer
|
||||
func (n *NodeApplyableProvider) References() []string {
|
||||
if n.Config == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return ReferencesFromConfig(n.Config.RawConfig)
|
||||
}
|
||||
|
||||
// GraphNodeProvider
|
||||
func (n *NodeApplyableProvider) ProviderName() string {
|
||||
return n.NameValue
|
||||
}
|
||||
|
||||
// GraphNodeProvider
|
||||
func (n *NodeApplyableProvider) ProviderConfig() *config.RawConfig {
|
||||
if n.Config == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return n.Config.RawConfig
|
||||
}
|
||||
|
||||
// GraphNodeAttachProvider
|
||||
func (n *NodeApplyableProvider) AttachProvider(c *config.ProviderConfig) {
|
||||
n.Config = c
|
||||
*NodeAbstractProvider
|
||||
}
|
||||
|
||||
// GraphNodeEvalable
|
||||
|
|
|
@ -7,6 +7,10 @@ import (
|
|||
"github.com/hashicorp/terraform/dag"
|
||||
)
|
||||
|
||||
// ConcreteProviderNodeFunc is a callback type used to convert an
|
||||
// abstract provider to a concrete one of some type.
|
||||
type ConcreteProviderNodeFunc func(*NodeAbstractProvider) dag.Vertex
|
||||
|
||||
// NodeAbstractProvider represents a provider that has no associated operations.
|
||||
// It registers all the common interfaces across operations for providers.
|
||||
type NodeAbstractProvider struct {
|
||||
|
|
|
@ -114,15 +114,15 @@ type MissingProviderTransformer struct {
|
|||
// Providers is the list of providers we support.
|
||||
Providers []string
|
||||
|
||||
// Factory, if set, overrides how the providers are made.
|
||||
Factory func(name string, path []string) GraphNodeProvider
|
||||
// Concrete, if set, overrides how the providers are made.
|
||||
Concrete ConcreteProviderNodeFunc
|
||||
}
|
||||
|
||||
func (t *MissingProviderTransformer) Transform(g *Graph) error {
|
||||
// Initialize factory
|
||||
if t.Factory == nil {
|
||||
t.Factory = func(name string, path []string) GraphNodeProvider {
|
||||
return &graphNodeProvider{ProviderNameValue: name}
|
||||
if t.Concrete == nil {
|
||||
t.Concrete = func(a *NodeAbstractProvider) dag.Vertex {
|
||||
return &graphNodeProvider{ProviderNameValue: a.NameValue}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,10 @@ func (t *MissingProviderTransformer) Transform(g *Graph) error {
|
|||
}
|
||||
|
||||
// Add the missing provider node to the graph
|
||||
v := t.Factory(p, path).(dag.Vertex)
|
||||
v := t.Concrete(&NodeAbstractProvider{
|
||||
NameValue: p,
|
||||
PathValue: path,
|
||||
}).(dag.Vertex)
|
||||
if len(path) > 0 {
|
||||
if fn, ok := v.(GraphNodeFlattenable); ok {
|
||||
var err error
|
||||
|
|
Loading…
Reference in New Issue