Product

Introducing Stack Dependencies v.2

Introducing Stack Dependencies v.2

Great news! Spacelift has just introduced a new and more powerful version of stack dependencies — one of the key components of infrastructure orchestration and cross-IaC workflow management.

Why use stack dependencies?

With stack dependencies, users can create a chain of interdependent stacks that should be executed in a specific order. Imagine a complex infrastructure created in multiple environments, where hundreds of stacks are tightly coupled together to create the whole infrastructure: These stacks must be orchestrated in proper order from account preparations, through access and authorization services, networks, databases, compute resources, to monitoring and alerting. Even more important, the information must be passed between stacks. Stack dependencies allow you to do exactly that.

The first version of stack dependencies works as a “queue” of executions for stacks. However, it is a high-level relation. One stack depends on another, that’s it.

New ways to pass values and parameters between stacks

Before stack dependencies v.2, you had to use Spacelift Context to pass values between stacks. Now, you can pass parameters directly between them as well. It will simplify your workflows and make dependencies more straightforward to use.

With stack dependencies v.2, users can not only build the chain of stacks to execute, they can also pass some parameters between them! This is a very important change, as the templates don’t need to evaluate and gather data dynamically anymore. Extending the example from the previous paragraph, imagine a situation in which you have created a network stack and in the next stack — for databases — you have to use a dynamic method to gather information about the network. With stack dependencies v.2, you simply pass the information about the new network between stacks.

New ways to pass values and parameters between stacks

How to start using stack dependencies v.2?

It is very simple. If you use stack dependencies, it will work as an extension to what you have been doing so far. For new users, here is the documentation about the functionality.

How does it work?

In this example, we connect two stacks using stack dependencies v.2, but not only that: We will pass information about created resources from one stack to another. To make things even more interesting, the first stack is built with Terraform, the second with AWS CloudFormation.

Here are our two stacks, ready to be connected:

start using stack dependencies v.2

Our task is to run spacelift-demo-vpc-preprod first, and pass the id of the newly created VPC to the second stack, spacelift-demo-cf-security-groups, where this data will be used to create Security Groups in this VPC.

Let’s create a dependency between the stacks:

spacelift-demo-cf-security

In spacelift-demo-cf-security-groups stack, I configured my network stack as the first in the chain. Now, I can pass the parameter:

how the dependencies look

Click the Add output reference link and provide the relevant data. Let’s check from where I took the vpcId and myVpcId.

In the first stack, (spacelift-demo-vpc-preprod) after I defined the AWS VPC, I defined the output section:

resource "aws_vpc" "main" {
}

output "vpcId" {
  description = "ID of the VPC"
  value       = aws_vpc.main.id
}

This is the value I selected from the select output menu.

According to Spacelift’s documentation, I created a piece of code in my CloudFormation template: 

Parameters:
  myVpcId:
     Type: String

And I provided this parameter name in the input name field using CF_PARAM_ prefix.

After all configuration is saved, this is how the dependencies look:

dependency between the stacks

Let’s trigger our stack!

Commit a change to the first stack, and observe the behavior. If all goes well, the green “FINISHED” marks should be on your screen too.

trigger our stack

The benefits of stack dependencies v.2 for your organization

From a technical standpoint, the three most important benefits of this solution are:

  • Cross-IaC workflows. Stack dependencies v.2 is easy to use between different technologies (see example above). You are now free to coordinate your teams and exchange data between them, even if they use different technologies.
  • Tight connection between stacks. With stack dependencies v.2, users can create very tight management of stacks in cases where stacks must be very closely connected due to interdependencies.
  • Direct transfer of information. The values of parameters, variables or resources can be passed directly from stack to stack now. You don’t need to compute this information in the stack; you use it as a variable’s value. This shortens executions and removes the possibility of misconfiguration.

The new functionality also has business benefits:

  • Increase collaboration between teams by simplifying the exchange of information between elements of the infrastructure.
  • Decrease the time needed for changes implementation. Information is passed automatically and directly between stacks — even between cross-IaC stacks — so no additional time is needed to provide the code for collecting and confirming the information.
  • Decrease uncertainty. For example, if a network was created, the output of this process can be processed directly in another stack. The data is no longer at risk of malformation, which may lead to misconfiguration of infrastructure.
  • Easy way to manage complex solutions. Tight connections between stacks allow organizations to improve control of the infrastructure’s SDLC.

Key points

Stack dependencies v.2 widens the dependencies functionality. With this option, you not only connect two stacks to execute one after another, you also pass information created in the runtime of one stack to another. This creates a tighter connection between stacks and allows you to build your infrastructure without re-collecting the data all the time.

Combining the new stack dependencies v.2 with other Spacelift functionalities, like Blueprints, Spaces, and OPA policies and using them with OpenTofu and Terraform providers give you a very powerful Swiss army tool to orchestrate your whole infrastructure from one place.

Does stack dependencies v.2 sound like something your company should be using? Book a demo with our engineering team to discuss your options in more detail. 

The Most Flexible CI/CD Automation Tool

Spacelift is an alternative to using homegrown solutions on top of a generic CI. It helps overcome common state management issues and adds several must-have capabilities for infrastructure management.

Start free trial