How to Use Stack Dependencies Across Spaces

Last updated: December 12, 2024

Understanding Stack IDs

When using a spacelift_stack data source, ensure you're using the correct stack ID. You can find the correct ID by:

  1. Checking the URL of the stack in the Spacelift GUI

  2. Clicking the "Copy ID" button in the stack's interface

Cross-Space References

When referencing stacks across different spaces, keep in mind:

  • A stack can reference child spaces or the same space

  • A stack cannot directly reference sibling or parent spaces using data sources

Using Stack Dependencies

Stack dependencies can be used between sibling spaces, but there are important permissions to consider:

  • The stack creating the dependency needs at least reader permission for the dependency stack

  • The stack creating the dependency needs admin permission for the dependee stack

If a stack in one space is trying to create a dependency with a stack in a sibling space, it may not have the necessary permissions, resulting in a "stack not found" error.

Troubleshooting

If you encounter errors like "Error: stack not found" or "Error: could not create stack dependency", check the following:

  1. Verify the stack ID is correct

  2. Ensure the stack creating the dependency has the necessary permissions in both spaces

  3. If using a stack manager, make sure it has the required access to create dependencies across spaces

Best Practices

To optimize your Spacelift setup:

  1. Review your space structure regularly

  2. Consider the Spacelift Spaces Best Practices guide

  3. If you're facing complex setups, consider scheduling a session with a Spacelift Solutions Architect to review and optimize your configuration

This diagram illustrates a typical stack structure in Spacelift. Understanding this hierarchy can help in planning your stack dependencies and permissions.