atlantis icon indicating copy to clipboard operation
atlantis copied to clipboard

Auto plan if `atlantis apply` fails

Open nitrocode opened this issue 3 years ago • 1 comments

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Searching for pre-existing feature requests helps us consolidate datapoints for identical requirements into a single place, thank you!
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Describe the user story

If a plan has 5 resources to create and then an apply creates 4 resources and fails on the 5th, you may be tempted to run another atlantis apply. If you do, it will say that the original plan is stale.

Ran Apply for dir: terraform/redacted workspace: default Apply Error

exit status 1: running "terraform apply -no-color $PLANFILE" in "/atlantis/repos/redacted/redacted/18/default/terraform/redacted": 

Error: Saved plan is stale

The given plan file can no longer be applied because the state was changed by another operation after the plan was created.

Describe the solution you'd like

Instead, when the apply fails, detect the failure, re-plan it and post the new plan, then if another atlantis apply is submitted, it should not fail with a stale plan.

Perhaps we can have a new input?

# atlantis's server.yaml
autoplan_if_apply_fails: true

or a new hook

# repo's atlantis.yaml
version: 3
projects:
- dir: terraform/redacted
  workflow: custom
workflows:
  custom:
    apply:
      # if apply fails
      steps_if_error:
        # repeat the previous plan
        - plan

Describe the drawbacks of your solution

I cannot think of any.

Describe alternatives you've considered

Try to remember to always run atlantis plan or atlantis plan -d xyz after a failed apply so I can run a subsequent atlantis apply

nitrocode avatar Aug 26 '22 14:08 nitrocode

This feature will be extremely useful when there is a terragrunt monorepo with mocks. That's the only thing that is currently missing to implement a "run-all apply" style workflow.

m0ps avatar Sep 21 '22 02:09 m0ps