mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
checks: don't iterate through all the nodes when there is nothing to search for (#32927)
This commit is contained in:
parent
5f97f88025
commit
c06db2aadd
@ -70,23 +70,28 @@ func (t *checkTransformer) transform(g *Graph, cfg *configs.Config, allNodes []d
|
|||||||
// actual checks.
|
// actual checks.
|
||||||
g.Connect(dag.BasicEdge(expand, report))
|
g.Connect(dag.BasicEdge(expand, report))
|
||||||
|
|
||||||
// This part ensures we report our checks before our nested data
|
if check.DataResource != nil {
|
||||||
// block executes and attempts to report on a check.
|
// If we have a nested data source, we need to make sure we
|
||||||
for _, other := range allNodes {
|
// also report the check before the data source executes.
|
||||||
if resource, isResource := other.(GraphNodeConfigResource); isResource {
|
//
|
||||||
resourceAddr := resource.ResourceAddr()
|
// We loop through all the nodes in the graph to find the one
|
||||||
if !resourceAddr.Module.Equal(moduleAddr) {
|
// that contains our data source and connect it.
|
||||||
// This resource isn't in the same module as our check
|
for _, other := range allNodes {
|
||||||
// so skip it.
|
if resource, isResource := other.(GraphNodeConfigResource); isResource {
|
||||||
continue
|
resourceAddr := resource.ResourceAddr()
|
||||||
}
|
if !resourceAddr.Module.Equal(moduleAddr) {
|
||||||
|
// This resource isn't in the same module as our check
|
||||||
|
// so skip it.
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
resourceCfg := cfg.Module.ResourceByAddr(resourceAddr.Resource)
|
resourceCfg := cfg.Module.ResourceByAddr(resourceAddr.Resource)
|
||||||
if resourceCfg != nil && resourceCfg.Container != nil && resourceCfg.Container.Accessible(check.Addr()) {
|
if resourceCfg != nil && resourceCfg.Container != nil && resourceCfg.Container.Accessible(check.Addr()) {
|
||||||
// Make sure we report our checks before we execute any
|
// Make sure we report our checks before we execute any
|
||||||
// embedded data resource.
|
// embedded data resource.
|
||||||
g.Connect(dag.BasicEdge(other, report))
|
g.Connect(dag.BasicEdge(other, report))
|
||||||
continue
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user