Skip to content

terraform test: refactor graph edge calculation #37357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 23, 2025

Conversation

liamcervante
Copy link
Member

@liamcervante liamcervante commented Jul 22, 2025

This PR uses the newly introduced priorRuns concept to simply connecting edges between runs within the Terraform Test graph. In turn, we can now simply the edges calculation between cleanup nodes as the dependencies (including references and parallelisation information) are now embedded into the graph already, and we can retrieve this from the dependency information instead of recalculating it.

In addition, we simplify the state key logic by precomputing it during the config parsing. This in turn let's users actually write into the main state from modules which might be something they want to do.

@liamcervante liamcervante added the no-changelog-needed Add this to your PR if the change does not require a changelog entry label Jul 22, 2025
@liamcervante liamcervante requested a review from a team as a code owner July 22, 2025 12:36
Comment on lines -130 to -133
// will be handled later.
if node.parallel && refNode.parallel {
g.Connect(dag.BasicEdge(refNode, node))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the sequential order of cleanup nodes also important?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, but I think that's all included in the depStateKeys metadata and doesn't need to be handled separately.

You definitely know this, but for other potential readers: If the run blocks creating the to-be-destroyed resources executed in sequence, then we want to destroy them in sequence as well (but reversed).

I think those run blocks will have had edges between them in the original graph indicating the sequential nature of operation that would have also been captured in the depStateKeys map. That map is built here, and it just uses the edges in the original graph. Those edges will contain both the requirements for sequential execution and parallel execution, I don't think we need to compute the sequential edges separately - we just want to reverse what was in the original graph and all of those edges are captured together.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also the parallel attribute of the NodeStateCleanup struct

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I hadn't noticed it was only referenced there. Done!

@liamcervante liamcervante requested a review from dsa0x July 23, 2025 10:09
Copy link
Member

@dsa0x dsa0x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@liamcervante liamcervante merged commit 0a7701f into main Jul 23, 2025
8 checks passed
@liamcervante liamcervante deleted the liamcervante/terraform-test-simplification branch July 23, 2025 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog-needed Add this to your PR if the change does not require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants