Spacelift.plan Not Found Error

Last updated: November 7, 2024

Issue: Spacelift.plan Not Found

Error Message: Error: Failed to read the given file as a state or plan file

This error typically occurs when the Spacelift plan file (Spacelift.plan) is not located in the expected directory after the planning phase, which can interrupt your run.

Possible Cause: Directory Change Before Plan Generation

One reason this error can occur is if a directory change happens before the planning phase, causing Spacelift.plan to be generated in the wrong location. By default, Spacelift expects Spacelift.plan to be in /mnt/workspace/source after the planning phase. If it is generated elsewhere, Spacelift cannot locate it, resulting in this error.

Troubleshooting Steps

  1. Use an after_plan Hook to Move Spacelift.plan
    If you need to change directories before planning, add an after_plan hook to ensure Spacelift.plan is moved back to /mnt/workspace/source after the planning phase.

    How to Set Up the after_plan Hook:

    • Go to your stack's hook tab.

    • Add an after_plan hook with a command to move Spacelift.plan to /mnt/workspace/source. For example:

      mv /path/to/generated/spacelift.plan /mnt/workspace/source/

  2. Confirm Directory Location Using after_apply Hooks
    If you’re not intentionally changing directories, you can set up after_apply hooks to diagnose the issue. Using commands like ls -la and pwd can help verify where Spacelift.plan is being generated and identify if it’s in an unexpected directory.

    Read more about hooks here.

Additional Troubleshooting Tips

  • Ensure that any custom scripts or hooks used before the planning phase do not unintentionally alter the directory structure.

  • Verify your stack’s configuration to check if directory changes are occurring automatically.

Need Further Assistance?

If the issue persists, please reach out to our support team with the following information:

  • Run ID

  • Relevant Hook Configurations

  • Any additional error messages or logs

Our team can provide guidance and help resolve any remaining issues with locating Spacelift.plan.