terraform: orphan module should flatten

This commit is contained in:
Mitchell Hashimoto 2015-05-14 20:54:33 -07:00
parent 7eccc72dd0
commit b251afb5af
3 changed files with 57 additions and 22 deletions

View File

@ -2628,6 +2628,52 @@ func TestContext2Validate_moduleProviderInherit(t *testing.T) {
} }
} }
func TestContext2Validate_moduleProviderInheritOrphan(t *testing.T) {
m := testModule(t, "validate-module-pc-inherit-orphan")
p := testProvider("aws")
c := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
State: &State{
Modules: []*ModuleState{
&ModuleState{
Path: []string{"root", "child"},
Resources: map[string]*ResourceState{
"aws_instance.bar": &ResourceState{
Type: "aws_instance",
Primary: &InstanceState{
ID: "bar",
},
},
},
},
},
},
})
p.ValidateFn = func(c *ResourceConfig) ([]string, []error) {
v, ok := c.Get("set")
if !ok {
return nil, []error{fmt.Errorf("not set")}
}
if v != "bar" {
return nil, []error{fmt.Errorf("bad: %#v", v)}
}
return nil, nil
}
w, e := c.Validate()
if len(w) > 0 {
t.Fatalf("bad: %#v", w)
}
if len(e) > 0 {
t.Fatalf("bad: %s", e)
}
}
func TestContext2Validate_moduleProviderVar(t *testing.T) { func TestContext2Validate_moduleProviderVar(t *testing.T) {
m := testModule(t, "validate-module-pc-vars") m := testModule(t, "validate-module-pc-vars")
p := testProvider("aws") p := testProvider("aws")

View File

@ -0,0 +1,9 @@
variable "foo" {
default = "bar"
}
provider "aws" {
set = "${var.foo}"
}
resource "aws_instance" "foo" {}

View File

@ -1,7 +1,6 @@
package terraform package terraform
import ( import (
"fmt"
"log" "log"
"github.com/hashicorp/terraform/dag" "github.com/hashicorp/terraform/dag"
@ -61,25 +60,6 @@ func (n *GraphNodeBasicSubgraph) Subgraph() *Graph {
return n.Graph return n.Graph
} }
func (n *GraphNodeBasicSubgraph) Flatten(p []string) (dag.Vertex, error) { func (n *GraphNodeBasicSubgraph) FlattenGraph() *Graph {
return &graphNodeBasicSubgraphFlat{ return n.Graph
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
} }