terraform: missing providers need to do dependencies

This commit is contained in:
Mitchell Hashimoto 2015-05-01 18:08:06 -07:00
parent 7fd432b076
commit 8f58367680
4 changed files with 104 additions and 0 deletions

View File

@ -69,6 +69,18 @@ func (g *Graph) Remove(v dag.Vertex) dag.Vertex {
return g.Graph.Remove(v)
}
// Replace is the same as dag.Graph.Replace
func (g *Graph) Replace(o, n dag.Vertex) bool {
// Go through and update our lookaside to point to the new vertex
for k, v := range g.dependableMap {
if v == o {
g.dependableMap[k] = n
}
}
return g.Graph.Replace(o, n)
}
// ConnectDependent connects a GraphNodeDependent to all of its
// GraphNodeDependables. It returns the list of dependents it was
// unable to connect to.

View File

@ -136,6 +136,22 @@ func TestBuiltinGraphBuilder_cbdDepNonCbd_errorsWhenVerbose(t *testing.T) {
}
}
func TestBuiltinGraphBuilder_fuck(t *testing.T) {
b := &BuiltinGraphBuilder{
Providers: []string{"aws"},
Root: testModule(t, "validate-module-pc-inherit-unused"),
Validate: true,
}
g, err := b.Build(RootModulePath)
if err != nil {
t.Fatalf("err: %s", err)
}
println(g.String())
t.FailNow()
}
/*
TODO: This exposes a really bad bug we need to fix after we merge
the f-ast-branch. This bug still exists in master.

View File

@ -33,6 +33,49 @@ func (t *ModuleInputTransformer) Transform(g *Graph) error {
return nil
}
// ModuleDestroyTransformer is a GraphTransformer that adds a node
// to the graph that will just mark the full module for destroy in
// the destroy scenario.
type ModuleDestroyTransformer struct{}
func (t *ModuleDestroyTransformer) Transform(g *Graph) error {
// Create the node
n := &graphNodeModuleDestroy{Path: g.Path}
// Add it to the graph
g.Add(n)
// Connect the inputs to the bottom of the graph so that it happens
// first.
for _, v := range g.Vertices() {
if v == n {
continue
}
if g.DownEdges(v).Len() == 0 {
g.Connect(dag.BasicEdge(v, n))
}
}
return nil
}
type graphNodeModuleDestroy struct {
Path []string
}
func (n *graphNodeModuleDestroy) Name() string {
return "module destroy (for plan)"
}
// GraphNodeEvalable impl.
func (n *graphNodeModuleDestroy) EvalTree() EvalNode {
return &EvalOpFilter{
Ops: []walkOperation{walkPlanDestroy},
Node: &EvalDiffDestroyModule{Path: n.Path},
}
}
type graphNodeModuleInput struct {
Variables map[string]string
}

View File

@ -190,6 +190,21 @@ func (n *graphNodeDisabledProvider) DotOrigin() bool {
return true
}
// GraphNodeDependable impl.
func (n *graphNodeDisabledProvider) DependableName() []string {
return []string{"provider." + n.ProviderName()}
}
// GraphNodeProvider impl.
func (n *graphNodeDisabledProvider) ProviderName() string {
return n.GraphNodeProvider.ProviderName()
}
// GraphNodeProvider impl.
func (n *graphNodeDisabledProvider) ProviderConfig() *config.RawConfig {
return n.GraphNodeProvider.ProviderConfig()
}
type graphNodeMissingProvider struct {
ProviderNameValue string
}
@ -264,3 +279,21 @@ func (n *graphNodeMissingProviderFlat) ProviderName() string {
"%s.%s", modulePrefixStr(n.PathValue),
n.graphNodeMissingProvider.ProviderName())
}
func (n *graphNodeMissingProviderFlat) 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.graphNodeMissingProvider.Name()))
}
return result
}