Skip to content

Auto plan if atlantis apply fails #2474

Open
@nitrocode

Description

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

Activity

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

Metadata

Assignees

No one assigned

    Labels

    featureNew functionality/enhancementhelp wantedGood feature for contributors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions