The Lifecycle
With most infrastructure tools, working out what a change will do and doing it happen in one
command. Somebody runs apply, reads the plan as it scrolls past, and types yes. That works until
the person who should read the plan is not the person at the keyboard, or until an approval has to
happen in a pull request rather than in a terminal.
Octo splits the work into separate commands, so each one can run on its own, on a different machine, or with somebody's approval in between:
npm run octo:generate # your intent -> Terraform
npm run octo:validate # the Terraform -> a report on what would change
npm run octo:lock # nobody else may change the app until the commit
npm run octo:apply # the Terraform -> real infrastructure
npm run octo:commit # what was created -> Octo's record, and the lock is released
Nothing in your cloud account changes before apply, and the two commands before it need no
permission to change anything.
The dotted line is what makes it a cycle. Octo does not scan your cloud account to learn what exists; it reads the record the last commit left, and compares your intent against that.
Generate
generate turns the definition file into Terraform, writing one folder per module under .octo-tf.
It needs no credentials, it touches nothing in the cloud, and the same definition file always
produces the same folders.
A mistake in the definition file stops it before any Terraform is written: a misspelled key, a module handed the wrong kind of input, or a reference to a module that is not there. Each error names the input it is about.
A module you removed from your intent keeps its folder, emptied of resources. That empty folder is what makes the next apply destroy what the module had built, and the commit after it deletes the folder.
Validate
validate plans every folder with Terraform and reports the plans against your intent. It answers
two questions and keeps them apart: what will change because of what you asked for, and what
changed that nothing you asked for explains, which is drift.
Validate reports; it does not judge. Drift and destroys are findings for you to read, and the only thing that fails the command is a folder Terraform could not plan. Reading a Validate Report covers what a report contains.
Lock
lock takes the app's lock and prints its ID. Apply and commit both require it, so two people can
never change the same app at once, and the commit that ends the run releases it. Apply and commit
find the lock on their own when it was taken in the same directory, so you rarely need the ID.
A run that dies keeps its lock, and is finished rather than released. Recovering a Failed Run covers it.
Apply
apply is the only command that changes your infrastructure. It runs Terragrunt over the generated
folders, which applies them in the order their dependencies need, and prints Terraform's progress
as it goes. It never stops to ask for a yes.
It stops for one thing: a destroy. Before it applies anything, it plans, and if the plan would destroy something it refuses and prints what, with the flag that approves each one. A destroy that loses data, a table's rows or a bucket's objects, says so on its line. Destroying Infrastructure covers approving them.
If the apply fails part way, it prints the command that records what it did build.
Commit
commit reads what the apply produced, the IDs, ARNs and endpoints only the cloud could know, and
records them in .octo/. That record is what the next run compares against, and what other
resources read when they need to point at these ones. Then it releases the lock.
Apply is plain Terragrunt and knows nothing of Octo, which is why reading the results back is a command of its own. A commit that is skipped leaves Octo believing none of it exists, and the next run proposes building it all again.
A commit records all of it or none of it. If a folder's apply did not finish, the commit refuses
and keeps the lock, and --partial records the part that did.
What each step touches
| Cloud | Octo's record | Generated folders | Lock | |
|---|---|---|---|---|
generate | intent | writes | ||
validate | reads a plan | reads | ||
lock | takes | |||
apply | writes | reads | requires | |
commit | reads outputs | everything | reads | requires, releases |
In a pipeline
The split is what makes a reviewed deploy possible. A job on the pull request runs generate and
validate and publishes the report, with credentials that can only read. Once somebody has approved
it, a second job runs all five commands with credentials that can change things. GitHub Actions
Pipeline has the complete setup.