Runtime configuration»
The runtime configuration is an optional setup applied to individual runs instead of being global to the stack. It's defined in .spacelift/config.yml file at the root of your repository.
Configuration schema»
A single file is used to define settings for all stacks associated with its host Git repository, so the file structure looks like this:
| .spacelift/config.yml | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
The top level of the file contains three keys:
version(defaults to1if not specified).stackscontaining a mapping of immutable stack id to the stack configuration block.stack_defaultscontaining the defaults common to all stacks using this source code repository. Corresponding stack-specific settings will override any stack defaults.
Configuring individual stacks with spacectl»
When configuring an individual stack with spacectl (such as through stack deploy --id example --runtime-config ./config.yml), omit the top-level config, so the file begins at runner_image.
| .spacelift/config.yml | |
|---|---|
1 2 3 | |
However, when specifying a config.yml file within a repo, do not omit anything. Include everything in the schema, including version: "2" and stack_defaults:.
Runtime configuration precedence»
Setting precedence will follow this order, starting from the most important to the least important:
- The configuration for a specified stack defined in
config.yml. - The stack defaults defined
config.yml. - The stack configuration set in the Spacelift UI.
Info
The precedence of the runtime configuration file changed between versions 1 and 2. Previously the stack configuration set in the Spacelift UI had a higher precedence than the stack defaults defined in the config.yml file.
Starting with version 2, the values in the config.yml file always take precedence over stack settings defined outside the config.yml file.
If no stack slug is defined in the configuration file, only the first two sources are considered:
- The stack configuration set in the Spacelift UI.
- The stack defaults defined in
config.yml.
Purpose of runtime configuration»
Runtime configuration allows flexibility that would otherwise be hard to achieve. In general, its purpose is to preview effects of changes not related to the source code (e.g. OpenTofu/Terraform or Pulumi version upgrades, variable changes, etc.), before they become an established part of your infrastructure.
While stack environment applies both to tracked and non-tracked branches, a runtime configuration change can be pushed to a feature branch, which triggers proposed runs, allowing you to preview the changes before they have a chance to affect your state.
Info
If the runtime configuration file is not present or does not contain your stack, default values are used. Refer to each setting for its respective default.
Stacks configuration block»
before_ and after_ hooks»
Info
Each collection defaults to an empty array.
These scripts allow you to customize the Spacelift workflow. The following are available:
before_initafter_initbefore_planafter_planbefore_applyafter_applybefore_performafter_performbefore_destroyafter_destroyafter_run
environment map»
Info
Defaults to an empty map.
The environment allows you to declaratively pass some environment variables to the runtime configuration of the stack. In case of a conflict, these variables will override both the ones passed via attached contexts and those directly set in stack's environment.
project_root setting»
Info
Defaults to an empty string, pointing to the working directory for the run.
Project root is the path of your project directory inside the Hub repository. You can use this setting to point Spacelift to the right place if the repo contains source code for multiple stacks in various folders or serves multiple purposes like monorepos combining infrastructure definitions with source code (potentially even for multiple applications).
runner_image setting»
Info
The default runner image can be defined multiple ways.
- No image set in runtime configuration file: Spacelift will look at the stack configuration.
- No image set in the stack configuration: Spacelift will use the default runner image specified on the account level.
- No image set as account-level default: Spacelift will use a vendor-specific image, like
public.ecr.aws/spacelift/runner-terraform:latestfor Terraform, orpublic.ecr.aws/spacelift/runner-opentofu:latestfor OpenTofu stacks. See our Docker integration documentation for more details.
The runner image is the Docker image used to run your workloads. By making it a runtime setting, Spacelift allows testing the image before it modifies your infrastructure.
terraform_version setting»
Info
Defaults to the latest known supported Terraform version.
This setting is only valid on Terraform stacks and specifies the Terraform version that the run will use. The main use case is testing a newer version of Terraform before you use it to change the state. This version can only be equal to or higher than the one already used to apply state changes. For more details on Terraform version management, please refer to its dedicated help section.
opentofu_version setting»
Info
Defaults to the latest known supported OpenTofu version.
This setting specifies the OpenTofu version to be used during the run. It is only read on legacy Terraform stacks with terraform_workflow_tool set to OPEN_TOFU. Specify a version that aligns with those officially supported and tested by Spacelift.
Example: opentofu_version: "1.8.0"
Warning
Native OpenTofu vendor stacks do not read this key. If it (or terraform_version) applies to a native OpenTofu stack without an opentofu block, every run fails during preparation with an error saying the configuration still sets terraform_version. Use the opentofu block instead.
opentofu setting»
This setting overrides the OpenTofu version and workflow tool for a native OpenTofu vendor stack, either per stack or through stack_defaults. It is the only way to override these settings from the repository for native OpenTofu stacks; the legacy opentofu_version key does not apply to them.
version: The OpenTofu version or constraint. Always set it with theOPENTOFUworkflow tool. If the block does not setversion, the run ignores the stack's version and uses the newest OpenTofu version that Spacelift supports. WithCUSTOM, Spacelift ignoresversion.workflow_tool: The workflow tool to use,OPENTOFU(default) orCUSTOM.
Other OpenTofu vendor settings (smart sanitization, concise output, CPU profiling, external state access, workspace) always come from the stack and cannot be overridden here.
Example:
| .spacelift/config.yml | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Mixed Terraform and OpenTofu monorepos
Spacelift checks the stack-specific entry first and then stack_defaults. The check stops at the first level that has an opentofu block. A level that sets terraform_version or opentofu_version without an opentofu block fails the run for native OpenTofu stacks, even when that level is stack_defaults shared with Terraform stacks. Either give every OpenTofu stack its own opentofu block, or keep terraform_version under the individual Terraform stacks instead of stack_defaults.
Info
The opentofu block does not change the stack's vendor. For legacy Terraform stacks using the OpenTofu workflow tool, use opentofu_version instead, or migrate to native OpenTofu stacks.
terraform_workflow_tool setting»
This setting determines the Terraform implementation used in the workflow:
TERRAFORM_FOSS(default): Utilizes the official Terraform by HashiCorp. Best for standard Terraform operations and official provider support.CUSTOM: Enables the use of Custom Workflows for highly customized or unique deployment processes.
Pulumi version management is based on Docker images.
git_sparse_checkout_paths setting»
Info
Defaults to an empty list. If empty, the value from the stack option will be applied.
Git sparse checkout paths allow you to specify a list of directories and files that will be used in sparse checkout, meaning that only the specified paths from the list will be cloned. This can help reduce the size of the workspace by only downloading the parts of the repository that are needed for the stack.
Only path values are allowed; glob patterns are not supported.
Example valid paths:
./infrastructure/infrastructure/infrastructure./infrastructure/main.tf
Example invalid path (glob pattern):
./infrastructure/*
terragrunt setting»
This setting determines the Terragrunt parametrization.
terragrunt_tool: Choose the tool that should be used by Terragrunt betweenTERRAFORM_FOSS(default),OPEN_TOFUandMANUALLY_PROVISIONED.terragrunt_version: Terragrunt version. Defaults to the latest version.terraform_version: The Terraform version. Must not be provided when tool is set toMANUALLY_PROVISIONED. Defaults to the latest available OpenTofu/Terraform version.use_run_all: Whether to useterragrunt run-allinstead ofterragrunt. Defaults tofalse.use_smart_sanitization: Indicates whether runs on this will use Terraform's sensitive value system to sanitize the outputs of Terraform state and plans in Spacelift instead of sanitizing all fields. Defaults tofalse.use_state_management: Indicates whether Spacelift handles the OpenTofu/Terraform state.
You must set all necessary fields because if the terragrunt section is present in the config, it replaces all Terragrunt values rather than merging them. For example, if you set terraform_version only, all other fields will be reset to their defaults.
Info
Terragrunt specific parameters only work when the stack is a Terragrunt stack. Adding this does not override the stack type. For example, Ansible stacks don't become Terragrunt stacks.