diff --git a/terraform/context.go b/terraform/context.go index 300b5a6d36..47d8772f4c 100644 --- a/terraform/context.go +++ b/terraform/context.go @@ -16,7 +16,7 @@ import ( // This is a function type used to implement a walker for the resource // tree internally on the Terraform structure. -type genericWalkFunc func(*Resource) error +type genericWalkFunc func(*walkContext, *Resource) error // Context represents all the context that Terraform needs in order to // perform operations on infrastructure. This structure is built using @@ -498,7 +498,7 @@ func (c *walkContext) Refresh() error { } func (c *walkContext) applyWalkFn() depgraph.WalkFunc { - cb := func(r *Resource) error { + cb := func(c *walkContext, r *Resource) error { var err error diff := r.Diff @@ -649,7 +649,7 @@ func (c *walkContext) planWalkFn(result *Plan) depgraph.WalkFunc { // Initialize the result result.init() - cb := func(r *Resource) error { + cb := func(c *walkContext, r *Resource) error { if r.Flags&FlagTainted != 0 { // We don't diff tainted resources. return nil @@ -749,7 +749,7 @@ func (c *walkContext) planWalkFn(result *Plan) depgraph.WalkFunc { } func (c *walkContext) refreshWalkFn() depgraph.WalkFunc { - cb := func(r *Resource) error { + cb := func(c *walkContext, r *Resource) error { is := r.State if is == nil || is.ID == "" { @@ -807,8 +807,9 @@ func (c *walkContext) genericWalkFn(cb genericWalkFunc) depgraph.WalkFunc { switch m := n.Meta.(type) { case *GraphNodeModule: - // TODO - return nil + // Build another walkContext for this module and walk it. + wc := c.Context.walkContext(m.Path) + return m.Graph.Walk(wc.genericWalkFn(cb)) case *GraphNodeResource: // Continue, we care about this the most case *GraphNodeResourceMeta: @@ -859,10 +860,11 @@ func (c *walkContext) genericWalkFn(cb genericWalkFunc) depgraph.WalkFunc { // Call the callack log.Printf( - "[INFO] Walking: %s (Graph node: %s)", + "[INFO] Module %s walking: %s (Graph node: %s)", + strings.Join(c.Path, "."), rn.Resource.Id, n.Name) - if err := cb(rn.Resource); err != nil { + if err := cb(c, rn.Resource); err != nil { log.Printf("[ERROR] Error walking '%s': %s", rn.Resource.Id, err) return err } diff --git a/terraform/context_test.go b/terraform/context_test.go index 7f561b8796..01dc00b690 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -2180,9 +2180,6 @@ func TestContextRefresh_hook(t *testing.T) { } func TestContextRefresh_modules(t *testing.T) { - // TODO: uncomment when we get it going - t.Skip() - p := testProvider("aws") m := testModule(t, "refresh-modules") state := &State{ @@ -2543,7 +2540,7 @@ root const testContextRefreshModuleStr = ` aws_instance.web: (1 tainted) ID = - Tainted ID 1 = foo + Tainted ID 1 = bar module.child: aws_instance.web: diff --git a/terraform/graph.go b/terraform/graph.go index bd999d2c16..6c3746f476 100644 --- a/terraform/graph.go +++ b/terraform/graph.go @@ -142,7 +142,7 @@ func Graph(opts *GraphOpts) (*depgraph.Graph, error) { modState = opts.State.ModuleByPath(opts.ModulePath) } - log.Printf("[DEBUG] Creating graph...") + log.Printf("[DEBUG] Creating graph for path: %v", opts.ModulePath) g := new(depgraph.Graph) @@ -214,7 +214,8 @@ func Graph(opts *GraphOpts) (*depgraph.Graph, error) { } log.Printf( - "[DEBUG] Graph created and valid. %d nouns.", + "[DEBUG] Graph %v created and valid. %d nouns.", + opts.ModulePath, len(g.Nouns)) return g, nil