> For the complete documentation index, see [llms.txt](https://docs.infraglide.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.infraglide.com/terraform-iac-engine/state-management.md).

# State File & Backend Management

InfraGlide tracks Terraform state **per pipeline version** and stores generated artifacts in an object store. Understanding this layout prevents accidental cross-version state corruption.

***

### Overview

![alt text](/files/sIo9leuFWVDQAq4o4lkH)

***

### State Management for Canvas Pipelines

For standard canvas generation and execution:

* Terraform uses state tracking dedicated to each pipeline version.
* State files are maintained in isolated execution environments per pipeline.
* State locking prevents concurrent modifications during plan, deploy, or destroy actions.

> **Remote Backends:** Remote backends (such as S3, GCS, or Azure Blob with state locking) are supported via landing-zone templates and backend configuration blocks.

***

### One State File per Version

Working directories and execution environments are isolated per version segment.

**Never** share one state file across two pipeline versions. Saving a new version creates an isolated environment; when appropriate, InfraGlide copies the prior live state into the new version so Terraform can continue managing existing resources seamlessly.

***

### Artifact Store vs State

| Artifact                    | Purpose                                                            |
| --------------------------- | ------------------------------------------------------------------ |
| **Generated Configuration** | Persisted for execution and state tracking                         |
| **Provider Lockfile**       | Preserved to guarantee reproducible provider plugin builds         |
| **Terraform State**         | Version-specific state file managing live infrastructure resources |

S3 (or org-scoped artifact storage) is therefore an **artifact** store for canvas pipelines, not necessarily the Terraform remote state backend.

***

### Execution Concurrency

InfraGlide adds application-level locks on top of Terraform's file lock:

* **Per-pipeline:** a second deployment on the same pipeline returns **409** while one is active.
* **Per-lineage:** another version in the same family cannot run concurrently (409).
* Destroy has extra guards for archived vs live versions.

These prevent two applies from fighting over the same version directory.

***

### Inspecting State

The **State Inspector** is available via the pipeline menu:

**Pipeline menu (⋯) → Inspect state** (visible only when permitted for deployed pipelines)

![alt text](/files/ilkeUSoAvatuhw3a4XN9)

The panel provides:

* **Resource list** — all Terraform-tracked resources with their type, name, and provider.
* **State operations** — perform state moves, removals, and imports directly through the state management panel.
* **Raw state viewer** — inspect the raw JSON structure of `terraform.tfstate`.

> **Caution:** Manual state surgery can desync InfraGlide's resource tracking. Prefer normal Deploy/Destroy flows when possible. Always make a backup of state before manual operations.

***

### Credentials and State

Cloud credentials are injected as process environment variables at execute time only. They are not written into state as plaintext provider blocks for AWS/Azure (and GCP credentials are not persisted into generated JSON for disk).

Terraform output persisted to the DB is redacted before storage.

***

### See also

* [Real-Time Terraform Code Generation](/terraform-iac-engine/code-generation.md)
* [Pipeline Versioning](/visual-canvas-and-pipeline-designer/versioning.md)
* [Plan, Deploy & Destroy Actions](/deployments-and-execution-history/execution-actions.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.infraglide.com/terraform-iac-engine/state-management.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
