Importing state files in OpenTofu/Terraform Stacks?

Last updated: May 1, 2026

Only users with Admin permissions can import state in the Spacelift UI. If that's not an option, there are two other approaches:

Option 1: Import state via the Spacelift Terraform provider

  1. Use the Spacelift Terraform provider to import state during stack creation:

    resource "spacelift_stack" "example-stack" {
      name = "Example Stack in Spacelift"
    
      # Source code.
      repository = ""
      branch = "main"
    
      # State file information
      import_state      = ""
      import_state_file = ""
    }

Option 2: Mount the state file and push it with a task

  1. Upload the state file as a mounted file and then use a task to push it eg terraform state push -force

Using spacectl Both of these options are also available via the spacectl CLI. You can mount a file to a stack's environment and trigger a task using the following commands:

# Mount a file to the stack environment
spacectl stack environment mount RELATIVE_PATH_TO_MOUNT FILE_PATH

# Run a task on the stack
spacectl stack task --id <stack-id> "terraform state push -force"

For a full list of available stack commands, run spacectl stack --help.

For implementing best practices around access control and permissions, refer to the following resources: