Skip to main content
In this article, we explain how changes in your Terraform configuration trigger concurrent runs in Spacelift and how to handle queued states when multiple engineers modify the code simultaneously.

Updating the Terraform Configuration

We begin by updating the main Terraform configuration file (main.tf) to deploy a simple AWS EC2 instance. The configuration below specifies the required Terraform version, AWS provider settings, and resource details for the EC2 instance:
Next, verify that your AWS credentials are correctly stored on your local system. This ensures that authentication is properly configured:

Creating a VPC

Now, let’s create a simple Virtual Private Cloud (VPC) with a CIDR block of 10.0.0.0/16, named “tf-example”. After you save, add, and commit these changes to your Git repository, a new run is triggered in Spacelift. Below is the Terraform configuration for creating the VPC:
After committing these changes, the Git output might look like this:
Back in Spacelift, the run corresponding to the “add VPC” commit starts by initializing, generating a plan, and then moving into an unconfirmed state. The plan output indicates that a new VPC will be created:
At this point, the plan is in an unconfirmed state. Instead of confirming or discarding the plan immediately, another engineer might make a change to the VPC configuration.

Handling Concurrent Changes

Assume another engineer updates the VPC configuration by changing the CIDR block to 10.2.0.0/16. Their updated configuration is as follows:
After committing these changes, you will see similar Git output:
Since the previous run is still awaiting confirmation, this new commit causes the new run to be queued. Spacelift blocks the new plan because a prior commit is pending confirmation. The following log output illustrates the plan execution for the queued run:
If the run remains in a queued state due to an unconfirmed prior commit, you may need to discard the queued run to allow the previously pending changes to proceed.

Finalizing the Run

Once the queued run is discarded, the remaining unconfirmed run continues through the following initialization steps:
  • Downloading the source code.
  • Setting up mounted files.
  • Configuring file permissions.
  • Pulling the required Docker image.
  • Downloading Terraform.
  • Creating and starting the Docker container.
  • Verifying prerequisites.
Example initialization output:
After reviewing the plan, you can confirm the run. The confirmed plan incorporates a minor adjustment in the resource tags, as seen below:
Confirming the run initiates Terraform to apply the changes. During the apply phase, the new VPC is created successfully:
The run then transitions to a finished state, and you can verify the successful creation of the VPC in your AWS environment. The image below shows an example of the Spacelift dashboard displaying the “spacelift-demo” stack details, including resources and configuration information:
The image shows a Spacelift dashboard with details of a stack named "spacelift-demo," including resources and configuration data on the right panel.

Summary

This article demonstrated how Spacelift handles concurrent runs and queued states when multiple engineers update Infrastructure as Code. By understanding and managing these states effectively, you can avoid conflicts and ensure a smooth deployment process. For more detailed information on managing Terraform configurations and Spacelift operations, check out the Terraform Documentation and Spacelift Guides.

Watch Video