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