How to make one stack rely on another in Spacelift
Last updated: January 3, 2025
To orchestrate your stacks you can use Stack dependencies or trigger policies in Spacelift allow you to make one stack rely on another, ensuring that stacks run in a specific order or share inputs. This article explains how to set up stack dependencies and troubleshoot common issues.
Creating Stack Dependencies
To create a stack dependency:
Ensure you have the correct permissions:
At least reader permission on the dependency stack
Admin permission on the dependee stack
Navigate to the stack settings where you want to add the dependency
Locate the "Dependencies" section
Add the stack you want to depend on
For detailed information on defining stack dependencies, refer to our stack dependencies documentation.
Benefits of Stack Dependencies
Ensure proper order of stack execution (e.g., deploy a database before deploying services that use it)
Share inputs between stacks
Configure dependent stacks to trigger only when shared outputs change or always trigger
Troubleshooting: "Stack Not Found" Error
If you encounter an error like Error: could not create stack dependency: dependency stack x not found: stack x not found, it's likely due to permission issues, especially when working with stacks in different spaces.
To resolve this:
Verify that you have the correct permissions on both stacks
Ensure that the stacks are in the same space, or that proper cross-space permissions are set up
Review the Spaces Access Control documentation for more information on required permissions
Troubleshooting: "job assignment failed: the following inputs are missing:" Error
If you encounter an error like job assignment failed: the following inputs are missing: Storage.TF_VAR_AWS_S3_BUCKET_ARN => TF_VAR_AWS_S3_BUCKET_ARN
and you can see the outputs in the UI, it means the output is not available in our backend to be used, this can happen if outputs were imported in and there was no successful apply phase. We have enabled the output uploading to our backend on 2023 August 21. This also means that if you have a stack that produced an output before that date, you'll need to rerun it to make the output available for references.
To resolve this:
We upload outputs during the Apply phase. If you stumble upon the error above, you'll need to make sure that the stack producing the output had a tracked run with an Apply phase.
You can simply do it by adding a dummy output to the stack and removing it afterwards:
output "dummy" {
value = "dummy"
}
Alternative: Trigger Policies
While stack dependencies are the recommended approach for most scenarios, Spacelift also offers trigger policies as an alternative method for managing stack relationships. You can learn more about trigger policies in our trigger policy documentation.
Best Practices
When working with stack dependencies, especially across different spaces, it's important to follow best practices. Review our spaces best practices guide for recommendations on organizing and managing your Spacelift environment effectively.