2023-05-02 10:33:06 -05:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2023-09-20 07:16:53 -05:00
|
|
|
package tofu
|
2015-02-27 21:18:04 -06:00
|
|
|
|
2022-03-22 18:17:56 -05:00
|
|
|
// TransitiveReductionTransformer is a GraphTransformer that
|
2015-02-27 21:18:04 -06:00
|
|
|
// finds the transitive reduction of the graph. For a definition of
|
2022-03-22 18:17:56 -05:00
|
|
|
// transitive reduction, see [Wikipedia](https://en.wikipedia.org/wiki/Transitive_reduction).
|
2015-02-27 21:18:04 -06:00
|
|
|
type TransitiveReductionTransformer struct{}
|
|
|
|
|
|
|
|
func (t *TransitiveReductionTransformer) Transform(g *Graph) error {
|
|
|
|
// If the graph isn't valid, skip the transitive reduction.
|
2023-09-26 12:09:27 -05:00
|
|
|
// We don't error here because OpenTofu itself handles graph
|
2015-02-27 21:18:04 -06:00
|
|
|
// validation in a better way, or we assume it does.
|
|
|
|
if err := g.Validate(); err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do it
|
|
|
|
g.TransitiveReduction()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|