State
Terraform records what exists in the cloud. That is enough to plan a change and not enough to explain one: a plan that recreates a bucket cannot say the bucket is where checkout keeps receipts, because nothing in Terraform's state ever knew.
Octo keeps a record of its own beside Terraform's, under .octo/. It holds what you asked for, what
exists, and the link between the two, and that link is what turns a line in a plan into a sentence
about your infrastructure.
What it holds
models.json is your intent as the last run understood it: every model, the relationships
between them, and the module that built each one, with the inputs octo.yaml gave it.
resources-actual.json is what Octo believes exists. For every resource it holds the
configuration Octo asked for, what the provider answered with once it existed, and which model the
resource was created for. Here is the receipts bucket after an apply and a commit, abridged:
"@octo/s3-storage=bucket-shop-receipts-914372": {
"className": "@octo/S3Storage",
"createdBy": "service=shop-receipts-s3-storage,region=eu-west-1,account=123456789012,app=shop",
"kind": "terraform",
"moduleId": "receipts-module",
"resource": {
"localResourceId": "bucket-shop-receipts",
"properties": {
"awsAccountId": "123456789012",
"awsRegionId": "eu-west-1",
"Bucket": "shop-receipts"
},
"resourceId": "bucket-shop-receipts-914372",
"response": {
"Arn": "arn:aws:s3:::shop-receipts"
}
}
}
createdBy is the receipts service in your intent, and response holds the ARN AWS assigned.
resourceId is the name the module gave the bucket, localResourceId, followed by a short hash of
where the receipts service sits. Before the first commit there is no bucket, so response holds
only the placeholder the resource declares. Afterwards it is what any other resource reads when it
has to point at this bucket.
The same file records which Terraform addresses each resource wrote. That mapping is how a report
can put aws_s3_bucket_public_access_block.bucket-shop-receipts-914372-public-access under the
receipts service, and how it
spots drift: a change to an address nobody's resource wrote came from outside Octo.
resources-old.json is the previous record, kept so that a run can tell a settled state from a
change that was started and not finished.
Two records, two jobs
| Records | Written by | Kept in | |
|---|---|---|---|
| Octo's | Intent, resources, and the link between them | generate and commit | .octo/*.json |
| Terraform's | Cloud objects and their attributes | apply | .octo/<moduleId>.tfstate |
Neither replaces the other. Terraform's state lets Terraform know the bucket exists. Octo's lets a report say that the bucket is checkout's receipts storage. Both are kept in the same place, so whoever can reach one can reach the other. The Lifecycle shows which command writes what.
Where it is kept
A state provider decides where these files live, and holds the lock that keeps two runs from writing at once. The definition file picks one:
settings:
stateProvider:
type: LocalStateProvider
statePath: .octo
LocalStateProvider keeps them in a directory on your machine, which is what the shop uses and what
suits one person. State Providers covers keeping them where a
whole team can reach them.
Losing it
Deleting .octo/ does nothing to your cloud account and everything to what Octo and Terraform know
about it. The next run treats itself as the first one and proposes creating your whole
infrastructure again, and Terraform, with no state left either, agrees. An apply then fails on
whatever has a unique name, such as the bucket, and quietly builds a second copy of whatever does
not, such as the VPC.
Recovering means restoring the files before anything applies, which is the case for keeping them where they cannot be lost.