Skip to content

Conversation

@romuloslv
Copy link

@romuloslv romuloslv commented Nov 23, 2025

what

This pull request enables destroy_execution_order_group

why

To support reverse execution order during destroy operations atlantis plan/apply -- -destroy. Currently, Atlantis supports execution_order_group for both resource creation and destruction. However, when hierarchical dependencies orchestrated by Terragrunt are present, resource destruction must be performed in reverse order, ensuring that child resources are removed before their parent resources. The implementation adds automatic detection of the -destroy flag, calculates effective execution groups based on operation type, and maintains backward compatibility with existing configurations. Both destructive and non-destructive global plan/apply operations work correctly in the same PR - regular operations use execution_order_group while destroy operations use destroy_execution_order_group, allowing users to safely test both creation and destruction workflows before merging.

tests

Tests added in

  • server/core/config/raw/project_test.go
  • server/events/apply_command_runner_test.go
  • server/events/plan_command_runner_test.go
  • server/events/project_command_pool_executor_test.go

references

Add DestroyExecutionOrderGroup field to Project configuration structs
to support reverse execution order during destroy operations.

- Add field to raw.Project with YAML parsing
- Propagate through valid.Project and MergedProjectCfg
- Update configuration merge and validation pipeline

Signed-off-by: Rômulo Silva <[email protected]>
Implement core logic to detect -destroy flag and respect
destroy_execution_order_group during destroy operations.

- Add IsDestroy, EffectiveExecutionOrderGroup fields to ProjectContext
- Detect -destroy flag in comment parser
- Implement assignEffectiveExecutionGroups function
- Update splitByExecutionOrderGroup to use effective groups
- Modify runProjectCmdsParallelGroups to handle destroy mode

Signed-off-by: Rômulo Silva <[email protected]>
Prevent PRs from being blocked by obsolete policy check status
from previous plan executions.

- Add resetPolicyStatus function to clear pending policies
- Apply reset in both runAutoplan and run methods
- Reload PullStatus after reset to update context
- Preserve existing plan/apply status during reset

Signed-off-by: Rômulo Silva <[email protected]>
Add comprehensive unit tests to validate destroy_execution_order_group
functionality and policy status reset behavior.

- Update 10 existing tests with EffectiveExecutionOrderGroup field
- Add 4 unit tests for assignEffectiveExecutionGroups scenarios
- Add parametrized tests for destroy order (Partial, AllDefined, NoneDefined)
- Add 2 tests for policy status reset (manual and autoplan)
- Validate correct execution order for plan and apply commands

Signed-off-by: Rômulo Silva <[email protected]>
Fix commit SHA extraction when git outputs warnings alongside
the commit hash (e.g., 'warning: refname HEAD is ambiguous').

- Use regex to extract valid SHA from git output
- Ignore warning lines in rev-parse output
- Add fallback to old behavior if parsing fails
- Update test to validate sanitized output

Signed-off-by: Rômulo Silva <[email protected]>
Add comprehensive documentation for destroy operations with
execution order groups in atlantis.yaml configuration.

- Add 'Order of destroying' section with usage examples
- Document destroy_execution_order_group field specification
- Provide workflow examples for Terraform, OpenTofu, and Terragrunt
- Explain fallback rules and execution behavior
- Improve -destroy flag usage documentation

Signed-off-by: Rômulo Silva <[email protected]>
@romuloslv romuloslv marked this pull request as ready for review November 23, 2025 02:33
@dosubot dosubot bot added feature New functionality/enhancement go Pull requests that update Go code labels Nov 23, 2025
@github-actions github-actions bot added the docs Documentation label Nov 23, 2025
@matheuslisboa-pp
Copy link

Very welcome contribution @romuloslv! looking forward to use it!!

@dawittbarbara
Copy link

This contribution is very important for various resources. RDS is very complex to destroy. It will certainly help many people.

Congratulations @romuloslv , may it be approved soon and go into production.

@lukemassa
Copy link
Contributor

There has been some discussion of order groups vs depends on, and how we might want to try to collapse those two concepts into one, I'm not sure if/how that's relevant here, thoughts @jamengual ?

@jamengual
Copy link
Contributor

yes, anything related to execution groups or sequence of executions needs to wait until we figure out the best approach.

@romuloslv
Copy link
Author

@lukemassa, @jamengual

I agree regarding the integration between the two concepts execution_order_group/depends_on. Even though I understand that the intention is a 1:N relationship for one and 1:1 for the other, this can still create some difficulty for certain users.

Currently, for Terragrunt-based workflows, we can configure the following keys in atlantis.yaml:

  • Only depends_on: Does not respect plan/apply ordering (everything starts at the same time).
  • Only execution_order_group: Respects the group ordering 0,1,2. (Creation works, but destructive plan/apply does not, since it follows the same creation order.)
  • Both execution_order_group and depends_on: Respects the group ordering 0,1,2. (The dependency is created, but Atlantis will not apply the dependent projects, always returning the message: Can't apply your project unless you apply its dependencies)

In an ideal scenario, I would like to define the key(s) in atlantis.yaml and successfully execute, within a PR, the following commands: atlantis plan, atlantis apply, atlantis plan -- -destroy, atlantis apply -- -destroy.

@jamengual you mentioned that not all maintainers are able to use Terragrunt for testing, and that PRs are welcome. I can contribute, including running tests, if there is any guidance on how we should handle dependency scenarios within Atlantis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation feature New functionality/enhancement go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants