How to create a Spacelift space and integration in the same Terraform apply
Last updated: November 2, 2026
When managing Spacelift resources through Terraform, a common issue arises when trying to create a space and its associated cloud integration (e.g., an AWS integration) in the same plan or PR. If your integration module uses a data source lookup to find the space, Terraform will attempt to resolve that lookup during the plan phase — before the space actually exists — resulting in an error.
The Problem
Data sources with hardcoded inputs (such as a space name or path) are read during the plan phase. If the space hasn't been created yet, the lookup fails. This is a known behavior described in the Terraform documentation on data source behavior.
Recommended Solution: Pass the Space ID as a Module Output
Instead of using a data source lookup in your integration module, pass the space_id directly from the space module's output. This allows Terraform to infer the dependency and create the space before the integration.
module "aws_integration" {
source = "./modules/aws-integration"
space_id = module.space.space_id
}This approach has several benefits:
Your space and integration modules remain separate, so no extra provider configuration is needed.
A full one-apply rebuild still works, since Terraform will automatically order the resource creation correctly.
The
spacelift_aws_integrationresource acceptsspace_iddirectly — see the Spacelift provider documentation for details.
Alternative: Stack Dependencies (Separate Stacks Only)
If your spaces and integrations are managed in separate Spacelift stacks, you can use stack dependencies to pass the space_id between stacks. However, note that stack dependencies only apply to tracked runs — a PR preview will not see a newly created space until after the changes are merged.
For most use cases where spaces and integrations need to be created together in the same PR, the module output approach described above is the recommended solution.