Free forever, no credit card.Get Started for Free →
← All posts
November 29, 2026 · 6 min read

Does Terraform Remember Between Runs? A State File Maps Your Infrastructure. The Reasoning Behind the Last Apply Never Gets Saved.

Does Terraform Remember Between Runs? A State File Maps Your Infrastructure. The Reasoning Behind the Last Apply Never Gets Saved. Terraform remembers exactly one thing between runs, and it remembers it in a file. Terraform is an infrastructure as code tool: you declare the servers, networks, and databases you want in configuration files, and Terraform creates, changes, or destroys real cloud resources so reality matches the declaration. Run terraform apply twice with the same configuration and

Does Terraform Remember Between Runs? A State File Maps Your Infrastructure. The Reasoning Behind the Last Apply Never Gets Saved.

Terraform remembers exactly one thing between runs, and it remembers it in a file. Terraform is an infrastructure as code tool: you declare the servers, networks, and databases you want in configuration files, and Terraform creates, changes, or destroys real cloud resources so reality matches the declaration. Run terraform apply twice with the same configuration and you get one set of resources, not two. That is not because the second run recalls the first. It is because a state file on disk tells it what already exists.

That file is thorough about objects and silent about everything else. It records which resource in your code corresponds to which object in your cloud account, with every attribute the provider returned. It does not record why a change was made, what the last plan reviewer worried about, which drift was intentional, or what an AI agent driving the pipeline decided at 3 a.m. The next run starts from the configuration, the state, and a fresh look at the cloud. Nothing else carries over.

The state file is the whole memory

After the first successful apply, a file named terraform.tfstate appears in the working directory. It is plain JSON, and it maps every resource address in your configuration, such as aws_instance.web, to the real object Terraform created: the provider's unique ID for that object, plus all of its attributes, its IP addresses, its tags, and the dependencies between resources. It also stores the output values your configuration defines, a serial number that increases with every write, and a lineage identifier that marks which history the file belongs to.

Every plan is a three-way comparison. Terraform reads the configuration for what you want, reads the state for what it recorded last time, and refreshes by asking the provider what those recorded objects look like right now. The plan is the difference between those three pictures. If they agree, the plan is empty. If someone resized an instance in the cloud console, the refresh catches it and the next plan proposes to change it back. That is drift detection, and it only works because the state file survived between runs.

Lose the file and the memory is gone in a very literal way. With no state, Terraform sees a configuration and no record that anything was ever created, so the next plan proposes to create everything from scratch. Resources that exist in the cloud but not in state are invisible until they are imported. This is why experienced teams treat the state file as the one artifact that must never be deleted, hand-edited, or committed to Git, where its contents, including attribute values stored in plain text, would be exposed.

Where the file lives decides who shares the memory

By default the state file sits in the working directory on one machine, which means the memory belongs to that machine. Two people running apply from two laptops each hold a different picture of the infrastructure, and their writes overwrite each other. The standard fix is a remote backend: the backend block in the configuration points Terraform at shared storage such as Amazon S3, Azure Blob Storage, Google Cloud Storage, or HCP Terraform, and running terraform init again offers to migrate the existing state there.

A remote backend adds three things the local file cannot. It gives every runner, human or pipeline, the same single state to read. It adds locking, so when one operation holds the state, a second one waits or fails with a lock error instead of corrupting the file; on S3 that locking is now native with use_lockfile, while the older DynamoDB table approach is deprecated. And with versioning turned on in the storage, an earlier state can be restored after a bad apply. Locally, the only safety net is terraform.tfstate.backup, the previous version of the file, one step deep.

Notice what all of this protects. Backends, locking, and versioning guard a snapshot of resource attributes. They say nothing about the work around the run: the ticket that justified a change, the exception a reviewer granted, the reason one piece of drift was accepted and another was reverted. That context lives in pull requests, chat threads, and people's heads, and none of it is loaded when the next run starts.

The gap an AI agent falls into

This matters more as scheduled automations and AI agents take over routine infrastructure work. An agent that runs a nightly plan, summarizes drift, and opens tickets is reading the same three pictures Terraform reads. It can tell you that a security group changed. It cannot tell you that the same change appeared last Tuesday, was investigated, and was traced to a teammate's load test, because that conclusion was reached in a previous run and never written anywhere the agent can load.

So the agent re-investigates. It re-asks the same questions in the same channels. It flags accepted drift as new, and it drafts the same summary the last run drafted, because from its side of the state file, every run is the first run. Terraform's memory answers "what exists." The question an operator actually needs answered is "what has already been decided about what exists," and no backend stores that.

Give the agent a memory next to the state file

The fix is a memory layer that sits alongside the pipeline rather than inside it. Vilix AI is a cloud-hosted memory service for AI tools and agents: there is nothing to install or host yourself, and the same memory is reachable from every tool over MCP, so the agent that runs your Terraform pipeline, the assistant you chat with in the morning, and the agent that writes the drift report all read and write one shared memory instead of three separate ones.

Two properties matter for this use case. First, Vilix AI keeps full conversation history, not just extracted facts, so the reasoning behind a decision, the exception that was granted, the load test that explained the drift, survives in the form it was actually discussed, ready to be loaded at the start of the next run. Second, the memory is shared agent state rather than chat history: when one run records "this drift is expected until Friday," every later run and every other connected tool starts already knowing it.

Getting started costs nothing to test. Vilix AI has a free plan that stays free forever, and the Pro plan comes with a 7-day trial that needs no card. Your memory stays yours: you can export it or delete it at any time. Terraform will keep doing what it does well, remembering exactly which objects it manages. Pair it with a memory that remembers the decisions, and the next run finally starts where the last one ended.

Get Started for Free

Persistent memory across ChatGPT, Claude, and the AI tools you already use in Vilix AI.

Get Started for Free

Free forever, no credit card.

Keep reading
Does Azkaban Remember Between Runs? The History Is Kept. The Reasoning Is Not.

Does Azkaban Remember Between Runs? The History Is Kept. The Reasoning Is Not. Azkaban remembers that a flow ran, when it ran, whether it succeeded, and what it printed to its logs. It does not remember what the work inside the flow learned. Each new execution starts from the project files, the schedule, and whatever parameters are handed in at launch. If a step inside that flow is an AI agent, the agent wakes up with a job definition and no past: none of the findings, decisions, or open questi

Does Apache Ignite Remember Between Runs? The Grid Holds Data. The Agent Starts Empty.

Does Apache Ignite Remember Between Runs? The Grid Holds Data. The Agent Starts Empty. Apache Ignite remembers the data placed in its caches, and with one optional setting it remembers that data across a full cluster restart. Without that setting it remembers nothing once the cluster stops. Either way, what Ignite holds is current data under keys and in tables. It does not hold a run: what a scheduled AI agent checked, concluded, or promised to do next. An automation that wakes tomorrow can que

Does Hazelcast Remember Between Runs? The Map Holds Values. The Agent Starts Empty.

Does Hazelcast Remember Between Runs? The Map Holds Values. The Agent Starts Empty. Hazelcast remembers exactly what its data structures were told to hold, for exactly as long as the cluster, a backup, or an optional persistence layer keeps them alive. An IMap entry put by one process can be read by another process seconds or days later, as long as the cluster stays up or the entry was written through to an external store. What Hazelcast never holds is a run. It stores current values under keys