Merge pull request #1944 from hashicorp/b-flatten-orphan-modules

core: flatten orphan modules
This commit is contained in:
Paul Hinze 2015-05-13 11:57:58 -05:00
commit 725f66796b
2 changed files with 77 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package terraform
import (
"fmt"
"log"
"github.com/hashicorp/terraform/dag"
@ -59,3 +60,26 @@ func (n *GraphNodeBasicSubgraph) Name() string {
func (n *GraphNodeBasicSubgraph) Subgraph() *Graph {
return n.Graph
}
func (n *GraphNodeBasicSubgraph) Flatten(p []string) (dag.Vertex, error) {
return &graphNodeBasicSubgraphFlat{
GraphNodeBasicSubgraph: n,
PathValue: p,
}, nil
}
// Same as GraphNodeBasicSubgraph, but for flattening
type graphNodeBasicSubgraphFlat struct {
*GraphNodeBasicSubgraph
PathValue []string
}
func (n *graphNodeBasicSubgraphFlat) Name() string {
return fmt.Sprintf(
"%s.%s", modulePrefixStr(n.PathValue), n.GraphNodeBasicSubgraph.Name())
}
func (n *graphNodeBasicSubgraphFlat) Path() []string {
return n.PathValue
}

View File

@ -173,6 +173,14 @@ func (n *graphNodeDisabledProvider) EvalTree() EvalNode {
}
}
// GraphNodeFlattenable impl.
func (n *graphNodeDisabledProvider) Flatten(p []string) (dag.Vertex, error) {
return &graphNodeDisabledProviderFlat{
graphNodeDisabledProvider: n,
PathValue: p,
}, nil
}
func (n *graphNodeDisabledProvider) Name() string {
return fmt.Sprintf("%s (disabled)", dag.VertexName(n.GraphNodeProvider))
}
@ -205,6 +213,51 @@ func (n *graphNodeDisabledProvider) ProviderConfig() *config.RawConfig {
return n.GraphNodeProvider.ProviderConfig()
}
// Same as graphNodeDisabledProvider, but for flattening
type graphNodeDisabledProviderFlat struct {
*graphNodeDisabledProvider
PathValue []string
}
func (n *graphNodeDisabledProviderFlat) Name() string {
return fmt.Sprintf(
"%s.%s", modulePrefixStr(n.PathValue), n.graphNodeDisabledProvider.Name())
}
func (n *graphNodeDisabledProviderFlat) Path() []string {
return n.PathValue
}
func (n *graphNodeDisabledProviderFlat) ProviderName() string {
return fmt.Sprintf(
"%s.%s", modulePrefixStr(n.PathValue),
n.graphNodeDisabledProvider.ProviderName())
}
// GraphNodeDependable impl.
func (n *graphNodeDisabledProviderFlat) DependableName() []string {
return []string{n.Name()}
}
func (n *graphNodeDisabledProviderFlat) DependentOn() []string {
var result []string
// If we're in a module, then depend on our parent's provider
if len(n.PathValue) > 1 {
prefix := modulePrefixStr(n.PathValue[:len(n.PathValue)-1])
if prefix != "" {
prefix += "."
}
result = append(result, fmt.Sprintf(
"%s%s",
prefix, n.graphNodeDisabledProvider.Name()))
}
return result
}
type graphNodeMissingProvider struct {
ProviderNameValue string
}