terraform: basic sub-module walks work
Lots broken still, but its a start.
This commit is contained in:
parent
c164839ed1
commit
8dcc4528fc
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 = <not created>
|
||||
Tainted ID 1 = foo
|
||||
Tainted ID 1 = bar
|
||||
|
||||
module.child:
|
||||
aws_instance.web:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue