Until now, having stacks trigger other stacks and configuring those dependencies was possible but required trigger policies and some fine-tuning to get right. Luckily, Spacelift has now released Stack Dependencies! The Stack Dependencies feature makes it much easier to configure dependencies between stacks to deploy more modular and complex infrastructure.
If your organization has been lucky enough to have less complex infrastructure that doesn’t require stacks to trigger other stacks, consider that a good thing! Unfortunately, as infrastructure grows, so does its complexity. To manage modularity, guardrails, and other concerns, most organizations split up their infrastructure into multiple modules or logical parts.
In the simplest case, you may find an infrastructure stack and an application configuration stack where the infrastructure is deployed first, and the application is configured afterward. The infrastructure could be deployed using Terraform, Cloudformation, Pulumi, or others. The application could be configured using one of the former or even Ansible or Kubernetes stacks.
In this post, we’ll focus more on implementing the Stack Dependency feature than what’s being deployed.
As you can see in the above image, we have two stacks: Infra Stack and App Stack.
In this scenario, we will configure a simple dependency that instructs App Stack to be triggered any time Infra Stack is run. This could be triggered manually or by some other triggering event such as a push event.
To configure dependencies through the UI (the recommended way is typically to script everything in Terraform and deploy using Spacelift), click on one of the stacks that is part of the dependency chain, and choose “Add dependencies” depending on which side of the chain the chosen stack lies.
Since this is the Infra Stack, we’ll want to choose the “Add dependencies” button on the “Depended on by” side.
Once we’ve done that, we can choose the App Stack:
Once that’s done, everything is finished! Yes, really, that’s it! It’s incredibly easy to create complex dependency chains using the UI.
Once the dependency is configured, trigger the Infra Stack, and once it’s finished deploying, it will trigger the App Stack. Be aware that any push policies applied to the App Stack still apply, so if the push policy calls for an untracked run due to a modification to the repository, that will still happen. But, the tracked run will also be initiated by the trigger.
Check out the documentation for more information on the different behaviors associated with push policies.
As you can see in the run history, the App Stack was triggered successfully!
Check out this short video with the Stack Dependencies introduction:
Stack Dependencies can be very powerful, and we’re only scratching the surface with this example. Keep an eye out for much more in-depth content involving Stack Dependencies, and keep building!
The most flexible management platform for Infrastructure as Code
Spacelift is a flexible orchestration solution for IaC development. It delivers enhanced collaboration, automation and controls to simplify and accelerate the provisioning of cloud based infrastructures.