Commit graph

27 commits

Author SHA1 Message Date
Radek Simko
0fe906fa8c make copyrightfix 2026-02-17 13:56:34 +00:00
Samsondeen
2a79f5fa53
Use iterators for graph vertices (#36558)
* Use iterators for graph vertices

* use func filter

* use type param instead of function filter

One type parameter seem to be enough instead of 2
2025-06-03 13:57:13 +02:00
Samsondeen
c0a7ff235b
Apply some new go collection features (#36818) 2025-04-02 16:20:16 +02:00
Samsondeen
2f0f537e69
Terraform test: Execute eligible test runs in parallel (#36300) 2025-02-05 15:18:38 +01:00
Samsondeen Dare
f41ce87644 update comments 2024-12-11 09:04:14 +01:00
Samsondeen Dare
77c362b414 Skip graph cycle validation when using the graph command 2024-12-10 13:45:14 +01:00
James Bardin
e86a357388 FirstAncestorsWith and MatchAncestor
Add ancestor equivalents of FirstDescendantsWith and MatchDescendant
2024-10-17 10:09:39 -04:00
James Bardin
a5a8f4b16a Ancestors cannot return an error
Just like Descendants, Ancestors doesn't need to return an error.
2024-10-14 09:45:49 -04:00
James Bardin
24de4a31bd new dag FirstDescendantsWith and MatchDescendant
Some new graph traversal methods to help with finding key descendants
for various graph transformers.
2024-10-09 15:12:40 -04:00
James Bardin
38804946e7 Descendants should not return an error 2024-10-09 14:37:45 -04:00
James Bardin
626a1a4cc1 Descendants should only take a single arg 2024-10-09 11:11:22 -04:00
James Bardin
3a1a9408d9 fix Descendants spelling
this has proliferated everywhere
2024-10-09 11:09:02 -04:00
James Bardin
d3b1586572 make Ancestors and Descendents variadic
A walk can start from multiple roots, so making the Ancestors and
Descendents methods variadic is the easiest way to add access to that
via the API with no changes in existing callers. We can use this from
terraform to avoid repeatedly walking overlapping sets of nodes.
2024-05-14 14:13:33 -04:00
Martin Atkins
1358245617 dependencies: Remove all non-legacy uses of hashicorp/go-multierror
This functionality is now provided by the "errors" package in the standard
library, so the HashiCorp-specific library is obsolete.

This also removed our one direct use of github.com/pkg/errors, which we
were using in a way that was totally redundant with the stdlib package
errors. However, it lives on as an indirect dependency through the Consul
backend's dependency on the Consul SDK, which uses that library.
2024-03-08 07:54:34 -08:00
komisan19
e3a9dce998 fix: delete min function 2023-12-17 15:45:46 +09:00
hashicorp-copywrite[bot]
53c34ff49c
Update copyright file headers to BUSL-1.1 2023-08-10 23:43:27 +01:00
hashicorp-copywrite[bot]
325d18262e [COMPLIANCE] Add Copyright and License Headers 2023-05-02 15:33:06 +00:00
Nick Fagerlund
ccd7bd017e Clarify some comments in internal/dag
When reading this code to check Terraform's graph sorting behavior, I got very
confused about the direction of traversal for several methods. Although some of
these methods would also probably benefit from renames, this commit only updates
their doc comments to use the same directional terminology that we use in the
`Edge` interface (source/target).
2022-10-06 15:10:33 -07:00
Martin Atkins
2e177cd632 core: Eliminate NodePlannableResource indirection
We previously did two levels of DynamicExpand to go from ConfigResource to
AbsResource and then from AbsResource to AbsResourceInstance.

We'll now do the full expansion from ConfigResource to AbsResourceInstance
in a single DynamicExpand step inside nodeExpandPlannableResource.

The new approach is essentially functionally equivalent to the old except
that it fixes a bug in the previous implementation: we will now call
checkState.ReportCheckableObjects only once for the entire set of
instances for a particular resource, which is what the checkable objects
infrastructure expects so that it can always mention all of the checkable
objects in the check report even if we bail out partway through due to
a downstream error.

This is essentially the same code but now turned into additional methods
on nodeExpandPlannableResource instead of having the extra graph node
type. This has the further advantage of this now being straight-through
code with standard control flow, instead of the unusual inversion of
control we were doing before bouncing in and out of different Execute and
DynamicExpand implementations to get this done.
2022-09-26 13:46:25 -07:00
James Bardin
ca272b2107 Add methods for topological sorts
A topological walk was previously only done in Terraform via the
concurrent method used for walking the primary dependency graph in core.
Sometime however we want a dependency ordering without the overhead of
instantiating the concurrent walk with the channel-based edges.

Add TopologicalOrder and ReverseTopologicalOrder to obtain a list of
nodes which can be used to visit each while ensuring that all
dependencies are satisfied.
2022-07-22 13:57:16 -04:00
James Bardin
95019e3d02 Implement breadth-first walks and add tests
Make DAG walks test-able, and add tests for more complex graph ordering.
We also add breadth-first for comparison, though it's not used currently
in Terraform.
2022-07-22 11:01:29 -04:00
Katy Moe
f8fdb6de3f
do not use pointer addr strings as map keys in set
When creating a Set of BasicEdges, the Hashcode function is used to determine
map keys for the underlying set data structure.

The string hex representation of the two vertices' pointers is unsafe to use
as a map key, since these addresses may change between the time they are added
to the set and the time the set is operated on.

Instead we modify the Hashcode function to maintain the references to the
underlying vertices so they cannot be garbage collected during the lifetime
of the Set.
2022-01-05 11:28:47 +00:00
James Bardin
344adb6c50 clarify dag comments
TransitiveReduction does not rely on having a single root, and only
must be free of cycles.

DepthFirstWalk and ReverseDepthFirstWalk do not do a topological sort,
so if order matters TransitiveReduction must be run first.
2022-01-04 10:07:31 -05:00
James Bardin
fae68f166f Remove sorted walk functions
These two functions were left during a refactor to ensure the old
behavior of a sorted walk was still accessible in some manner. The
package has since been removed from any public API, and the sorted
versions are no longer called, so we can remove them.
2022-01-04 09:37:53 -05:00
James Bardin
863963e7a6 de-linting 2021-09-01 11:36:21 -04:00
Martin Atkins
05caff2ca3 Move tfdiags/ to internal/tfdiags/
This is part of a general effort to move all of Terraform's non-library
package surface under internal in order to reinforce that these are for
internal use within Terraform only.

If you were previously importing packages under this prefix into an
external codebase, you could pin to an earlier release tag as an interim
solution until you've make a plan to achieve the same functionality some
other way.
2021-05-17 14:09:07 -07:00
Martin Atkins
70eebe3521 Move dag/ to internal/dag/
This is part of a general effort to move all of Terraform's non-library
package surface under internal in order to reinforce that these are for
internal use within Terraform only.

If you were previously importing packages under this prefix into an
external codebase, you could pin to an earlier release tag as an interim
solution until you've make a plan to achieve the same functionality some
other way.
2021-05-17 14:09:07 -07:00