Skip to content

Intent to IaCยป

Once you've used Spacelift Intent to provision and manage infrastructure through natural language, you can transition to a traditional Infrastructure-as-Code workflow. The Intent to IaC feature generates OpenTofu/Terraform HCL code from your Intent project's resources and optionally creates a Spacelift stack with the generated code and imported state.

Why transition to IaC?ยป

  • Codify stable infrastructure โ€” Move from natural-language management to version-controlled IaC once your architecture stabilizes.
  • Team collaboration โ€” IaC workflows with pull requests and reviews scale better for teams.
  • Full Spacelift features โ€” Stacks unlock the complete Spacelift feature set: drift detection, policies, run promotion, scheduling, and more.

View HCL for a resourceยป

You can inspect the generated HCL for any individual resource in your Intent project.

  1. Navigate to your Intent project and open the Resources tab.
  2. Click a resource row to open the resource detail drawer.
  3. The drawer displays the generated HCL code for that resource.

Resource detail drawer with HCL code

You can also retrieve HCL for a single resource via MCP:

1
Show me the HCL for resource "my-s3-bucket" in the current project.

Download HCL for the entire projectยป

To download the complete HCL for all resources in your project:

  1. Navigate to your Intent project detail page.
  2. Open the dropdown menu (top-right).
  3. Click Download HCL file(s).

Download HCL option in dropdown menu

The downloaded file contains:

  • A terraform block with all required providers and their versions.
  • Resource definitions for every resource in the project.
  • Dependency references between resources resolved as Terraform expressions (e.g., aws_subnet.main.id).

You can also retrieve the full project HCL via MCP:

1
Show me the HCL for this entire project.

Create a stack from an Intent projectยป

The most powerful transition path is creating a Spacelift stack directly from your Intent project. This generates HCL code, stores it in a Spacelift Repo, and optionally imports the Terraform state so your first run shows zero changes.

Via MCPยป

Use your MCP client to create a stack:

1
Create a stack from the current project and import the state.

Intent will:

  1. Generate HCL code from all project resources (saved as main.tofu).
  2. Create a Spacelift Repo to store the generated code.
  3. Create a stack linked to that repo.
  4. Import the Terraform state (if requested).

Creating a stack from Intent project via MCP

Via Spacelift UIยป

You can also create a stack directly from the Spacelift web interface:

  1. Navigate to your Intent project detail page.
  2. Click the Create a stack button in the top-right corner.

    Create a stack button on Intent project page

  3. In the drawer that opens, fill in:

    • Stack name โ€” A unique name for the new stack (defaults to the Intent project name).
    • Transfer state โ€” Check this to import the current state from the Intent project into the new stack. Enabled by default.

    Create a stack drawer

  4. Click Create. Once the stack is created, you'll be redirected to the new stack page.

Warning

Creating a stack transfers the project's context, environment variables, and integrations to the new stack.

What happens during the transitionยป

  1. HCL generation โ€” All resources are converted to HCL with proper provider blocks and inter-resource references.
  2. Repo creation โ€” A Spacelift Repo is created to store the generated main.tofu file.
  3. Stack creation โ€” A new stack is created using OpenTofu as the workflow tool, linked to the generated repo.
  4. Environment copy โ€” Environment variables from the Intent project are copied to the new stack.
  5. Integration copy โ€” Cloud integrations (e.g., AWS) attached to the project are attached to the stack.
  6. State import (if enabled) โ€” The Terraform state is uploaded and linked to the stack, so the first tracked run detects zero changes.

After the transitionยป

When you create a stack with state import, the Intent project transitions to a read-only state:

  • You can still view resources, history, and configuration in the Intent project.
  • New resource operations (create, update, delete) are blocked.
  • All future infrastructure changes should be made through the new stack.

Intent project in read-only state

Info

If you create a stack without importing state, the Intent project remains active and you can continue managing resources through Intent.

Verify the transitionยป

After creating the stack, trigger a tracked run to verify that the generated code and imported state match:

  1. Navigate to the new stack in Spacelift.
  2. Trigger a tracked run.
  3. The run should complete with zero changes, confirming the state was imported correctly.

Tracked run with zero changes after transition

From this point, manage your infrastructure through the stack using the standard Spacelift workflow: edit the generated HCL in the Spacelift Repo (or migrate it to an external VCS), push changes, and let Spacelift handle the plan/apply cycle.