docs

The goal of Plural Stacks is to provide a scalable framework to manage infrastructure as code with a Kubernetes-friendly, API-driven approach. Stacks support Terraform, Terragrunt, Pulumi, Ansible, and custom runner workflows. The core workflow is as follows:

  • Declaratively define a stack with a type (Terraform, Ansible, etc.), a location in a Git repository to source code from, and a cluster on which it will execute
  • On each commit to the tracked Git repository, a run is created, which the Plural deployment operator will detect and execute on the targeted cluster
    • this allows users to fine-tune the permissions and network location of IaC runs where both need to be configured.
  • Plural will carefully execute the run for you, and besides basic information like communicating stdout to the UI, we will also gather and present useful information like inputs/outputs, Terraform state diagrams and more
  • On PRs to the tracked repository, a "plan" run is also executed and comments are posted on the relevant PR where possible.

To get a better idea of the full experience, take a look at this demo video (at 2x speed if you want to save some time):

Supported stack types

TypeUse it for
TERRAFORMTerraform configurations
TERRAGRUNTTerraform configurations orchestrated with Terragrunt
PULUMIPulumi programs in supported runtimes
ANSIBLEAnsible playbooks
CUSTOMA custom runner image and command workflow

Pulumi stacks use Pulumi's own state backends. See Pulumi stacks for Pulumi Cloud and self-managed backend authentication. To drive Console resources from Pulumi via the Terraform provider, see Using from Pulumi.

A Basic Stack

The most common way to instantiate a stack is via a Kubernetes CRD. This gives a flexible, modular way to recreate infrastructure and pairs nicely with our PR Automation tooling for full self-service around IaC.

Here's an example:

yaml
apiVersion: deployments.plural.sh/v1alpha1
kind: InfrastructureStack
metadata:
  name: gke-demo
  namespace: stacks
spec:
  name: gke-demo
  type: TERRAFORM
  approval: true
  detach: false
  manageState: true
  actor: console@plural.sh
  configuration:
    version: 1.8.2
  repositoryRef:
    name: fleet
    namespace: fleets
  clusterRef:
    name: mgmt
    namespace: infra
  workdir: gke-cluster
  git:
    ref: main
    folder: terraform
  files:
  - mountPath: /plural
    secretRef:
      name: gcp-creds
  environment:
  - name: GOOGLE_APPLICATION_CREDENTIALS
    value: /plural/creds.json
  - name: TF_VAR_cluster
    value: gke-demo
  - name: TF_VAR_tier
    value: dev
  - name: TF_VAR_fleet
    value: gke-dem

This YAML is largely self-documenting. We are:

  • creating a TERRAFORM stack, so it will execute the standard Terraform workflow
  • we're using Plural as the state store, removing the need to configure S3 or other backends manually
  • approval will be required before terraform apply will trigger, ensuring a human verifies the plan first to reduce misconfiguration risk
  • we're sourcing manifests from the fleet repository (referencing a GitRepository CRD)
  • we're executing on the mgmt cluster (referencing a Cluster CRD)
  • and we're executing in the terraform/gke-cluster folder

You can also bind files and environment variables into the environment, although it is still best practice to use IRSA, GKE workload identity or similar mechanisms for issuing cloud credentials.

Terragrunt parent folders

A Terragrunt stack normally runs the single unit in git.folder. Repositories with many nested terragrunt.hcl files can instead point that folder at the parent and set configuration.terragrunt.runAll. One stack then plans every unit under the folder. Units outside the folder are left alone, including dependencies that are only read for their outputs.

yaml
apiVersion: deployments.plural.sh/v1alpha1
kind: InfrastructureStack
metadata:
  name: terragrunt-live
  namespace: stacks
spec:
  name: terragrunt-live
  type: TERRAGRUNT
  approval: true
  manageState: false
  repositoryRef:
    name: fleet
    namespace: fleets
  clusterRef:
    name: mgmt
    namespace: infra
  git:
    ref: main
    folder: live
  configuration:
    terragrunt:
      runAll: true

git.folder is the parent directory. It does not need its own terragrunt.hcl. manageState stays false because each unit keeps the backend declared in its own configuration. Plural managed state is one backend for the whole stack, so it cannot be combined with runAll.

On each run, Terragrunt plans every unit under live. When every plan is empty, apply is skipped. When some units have changes, only those units are applied. The same switch is available in the stack Configuration tab as "Run all units".