Gardience Documentation gardience.com →
Docs / Clients

Spacelift

Spacelift runs your OpenTofu and Terraform. The Gardience provider runs inside those stacks like any other provider, so nothing extra is installed in Spacelift. Spacelift builds the machine, and Gardience keeps it patched, hardened, and audited from its first boot.

The two cover different kinds of drift. Spacelift's drift detection catches changes to your cloud resources. Gardience catches drift inside each machine: a setting changed by hand, a service stopped, a baseline check that started failing, or an update that never installed.

Before you start

#
  1. In Gardience, an admin creates a configure API key: Settings > API keys, scope Configure (Terraform, admins). It manages configuration only and never runs anything on machines already in the fleet. See API keys and the REST API.
  2. Spacelift's workers must reach your Gardience server over HTTPS. Spacelift's public workers run in Spacelift's cloud, so either allow them to reach the server, or run the stack on a Spacelift private worker pool inside your network.
  3. The machines the stack builds must reach the Gardience server on the Salt ports (4505 and 4506, or the ports set at install). That traffic goes from the new machines to your server, not through Spacelift.

Put the address and key in a Spacelift context

#

A Spacelift context holds environment variables and files that many stacks share, so the key lives in one place and never in your repository.

  1. In Spacelift, go to Share code & config > Contexts and create a context named gardience.
  2. Add the variables:
VariableValueSecret
GARDIENCE_URLhttps://gardience.example.comNo
GARDIENCE_API_KEYthe configure key, gdn_...Yes
  1. If your Gardience server uses a certificate from a private certificate authority, add that authority's PEM file as a mounted file at /mnt/workspace/gardience-ca.pem, and one more variable, GARDIENCE_CA_CERT_FILE set to /mnt/workspace/gardience-ca.pem.
  2. Attach the context to the stacks that build machines. To attach it automatically, give the context the label autoattach:gardience and give each of those stacks the label gardience.

Variables marked secret are not shown again in Spacelift's interface or API.

The stack

#

The provider reads GARDIENCE_URL, GARDIENCE_API_KEY, and GARDIENCE_CA_CERT_FILE from the environment, so the provider block stays empty:

terraform {
  required_providers {
    gardience = { source = "gardience/gardience" }
  }
}

provider "gardience" {}

resource "gardience_enrollment" "web" {
  label  = "web tier (spacelift)"
  hours  = 2160
  groups = ["web"]
}

data "gardience_bootstrap_script" "web" {
  count         = 3
  enrollment_id = gardience_enrollment.web.id
  os            = "linux"
  node          = "web-${count.index + 1}"
}

resource "aws_instance" "web" {
  count         = 3
  ami           = var.ami
  instance_type = "t3.small"
  user_data     = data.gardience_bootstrap_script.web[count.index].content
  tags          = { Name = "web-${count.index + 1}" }
}

# the run waits until each machine has joined; on destroy, the machine leaves the fleet
resource "gardience_machine" "web" {
  count      = 3
  name       = "web-${count.index + 1}"
  depends_on = [aws_instance.web]
}

When the run applies, each machine boots, installs the Salt agent, joins Gardience in the web group, and gets whatever join rules you set for that group. From then on it is in every scan, patch ring, baseline, and report. When the stack is destroyed, the machines are removed from the fleet. Everything the provider does is in the Gardience audit log under the key's owner, marked "via API key".

For the full list of resources (states, event rules, runbooks, change windows, and schedules), Windows first-boot scripts, and how removal is cushioned, see Terraform. The same page shows how to export what admins already built in the console as Terraform, so a Spacelift stack can adopt it.

Good to know

#
#
Gardience by Bouziden Management LLC.