🚀 Spacelift to the moon 🚀

🚀 Spacelift to the moon 🚀

Table of contents

No heading

No headings in the article.

I’ve accidentally ran into Spacelift and I’m so happy I did. To be honest, I’ve never been a big fan of tools on top of IaC, but this is something else.

As they state on their website, Spacelift is a sophisticated CI/CD platform for a variety of tools.

At a first glance, Spacelift is pretty similar to Terraform Cloud, giving you the opportunity to create stacks based on your Terraform code, run policies on it to make sure that engineers create only what they are supposed to create, view runs and manage state.

The free offer of Spacelift is superior to Terraform Cloud’s offering, in my opinion, as it comes with some free policies [not all, though].

Spacelift leverages OPA for defining policies, something that you will most likely be familiar with, so whatever policies you have in place now, you can easily add them to Spacelift.

With Spacelift, you can use also CloudFormation, Pulumi and Kubernetes, which opens a door for people that don’t like or want to use Terraform (don’t know why some of you don’t like it).

Enough with what it does, let’s see it in action.

To show you some of Spacelift characteristics in the free tier, I’ve created a dummy Terraform repository that uses a null resource in order to run a local-exec.

resource "null_resource" "test" {
  provisioner "local-exec" {
    command = "echo Hello Spacelift"
  }
}

After that, I’ve created my Spacelift account and jumped right into creating my first stack.

I’ve integrated my Github account with Spacelift, selected the dummy repository mentioned above and specified the branch I want Spacelift to monitor for changes.

After clicking continue you have to configure the backend. In my case, of course, this was Terraform, but as I stated before, you have other options as well.

When you are configuring the backend, you have the possibility of selecting the terraform version, whether or not you want Spacelift to Manage the state and even import an existing state file.

After this, in the define behaviour tab, you have the possibility to set some other things like autodeploy, runner image and some more. I’ve kept the default values enabled as this stack will be used only for demo purposes.

At the end of this process, you will need to name the stack and optionally you can provide labels and a description.

The stack was created successfully and a terraform plan was initialised. Due to the fact that I didn’t enable the autodeploy feature, I had to provide a manual confirmation before applying the code.

I’ve decided to add another null resource to my code, but I’ve given it the same name in order to create an error. This time, I’ve created a feature branch, pushed the code to that feature branch and opened a pull-request to the main one.

Due to the fact that I’ve opened this PR, whenever I push to the PR branch, a plan job gets triggered. After a couple of seconds, I get the error on my PR:

After fixing the naming error mentioned before, I’ve pushed the change to my branch and I immediately see on my PR that it is fixed and also get a glance about what is going to happen:

After merging, the run for the main branch will run and you will see a terraform plan, have the possibility of confirming it and apply the code.

To sum it up, I think Spacelift is a powerful tool that will be used more and more by both small and large businesses. It has the capability of making engineers more efficient by not having to check a hundred systems before commenting on a PR. The feeling I get is that Spacelift combines all the features from Terraform Cloud and Atlantis and also has a couple of other capabilities on top. The simplicity of the interface and the clear definitions for every field that you have to fill in, makes the experience enjoyable and the frustration level when something is not configured properly gets kept a minimum.

Features like drift detection, code polices, module registry and native integration with Slack are very useful nowadays and Spacelift does them perfectly.

I didn’t mention that Spacelift has its own Terraform provider, which means that you can manage your entire Spacelift resources using Terraform. In the future, I am planning to do a complete environment setup for Spacelift using Terraform and GitHub Actions, so stay tuned.

Useful Links: