Skip to main content

The Definition File

Everything Octo does starts from one file. It says which modules make up your infrastructure, what each one is given, where state lives, and which Terraform providers the generated folders declare. For most teams it is the only file anybody edits.

This is the shop's, from the Shop Stack, with a checkout server added.

octo.yaml
version: 1

env:
- key: AWS_ACCOUNT_ID
kind: string
value: "123456789012"
- key: RECEIPTS_BUCKET_NAME
kind: string
value: shop-receipts

terraform:
requiredVersion: "1.6.0"
requiredProviders:
aws:
source: hashicorp/aws
providers:
- providerType: aws
accountId: "${env.AWS_ACCOUNT_ID}"
regionId: eu-west-1
spec:
profile: default

settings:
listeners:
- type: JournalEventListener
- type: LoggingEventListener
stateProvider:
type: LocalStateProvider
statePath: .octo

imports:
- className: SimpleAppModule
importPath: "@quadnix/octo-aws-cdk/modules/app/simple-app"
# ...

modules:
- moduleId: app-module
moduleClass: SimpleAppModule
moduleInputs:
name: shop
# ...

version, imports, modules, settings, and terraform are required. env, extends, hooks, rules, stores, and tags are optional. The file is checked against a schema before anything else happens, so a misspelled key is caught with a message naming it.

Octo reads octo.yaml from the working directory, or the file OCTO_DEFINITION_FILE_PATH names, relative to the working directory; no command has a flag for it. Everything the file names by relative path, imports and the state directory included, resolves against the file's own directory rather than your shell's working directory.

Editor autocompletion

Put this at the top and your editor will complete keys and flag mistakes as you type:

# yaml-language-server: $schema=https://raw.githubusercontent.com/quadnix/octo/refs/heads/main/packages/octo-build/src/resources/octo-v1.schema.json

modules​

The intent. Each entry loads one instance of one module class.

modules:
- moduleId: receipts-module
moduleClass: AwsS3StorageServiceModule
moduleInputs:
region: "${{region-module.model.region}}"
bucketName: "${env.RECEIPTS_BUCKET_NAME}"
accessPrefixes:
- uploads
moduleIdYours to choose. It scopes everything this instance produces, and names its Terragrunt folder.
moduleClassA class name that appears in imports.
moduleInputsWhatever that module's schema declares. Validated before the module runs.

Modules run top to bottom, and a module can only reference what an earlier one produced. Loading the same class twice under two IDs gives two independent instances.

Changing a moduleId renames its folder, and Octo moves the Terraform state of everything in it across, so nothing is rebuilt.

imports​

Where each module class comes from.

imports:
- className: AwsS3StorageServiceModule
importPath: "@quadnix/octo-aws-cdk/modules/service/aws-s3-storage-service"
- className: ShopRegionModule
importPath: "./dist/index.js"

A bare specifier is resolved from your project's node_modules. A relative path is resolved against the definition file, which is why your own modules are imported from ./dist/index.js after npm run build rather than from ./src.

Importing a class you never load is harmless. Loading one you never imported fails at boot, with a message naming the class.

terraform​

The provider setup that would otherwise sit at the top of every .tf file. Octo renders it into every generated folder.

terraform:
requiredVersion: "1.6.0"
requiredProviders:
aws:
source: hashicorp/aws
minVersion: "5.0.0"
providers:
- providerType: aws
accountId: "${env.AWS_ACCOUNT_ID}"
regionId: eu-west-1
spec:
profile: default

requiredVersion and requiredProviders become the terraform block. providers is one entry per deployment target, and a target is an account and a region together. Resources bind to a provider by that pair alone, which is why a shop that spans two regions needs two entries.

Each entry becomes a named provider block, and the name is built from the account number: _123456789012-eu-west-1. That name reaches every generated folder, and generated Terraform is committed, so accountName lets you put something else there:

  providers:
- providerType: aws
accountId: "${env.AWS_ACCOUNT_ID}"
accountName: prod
regionId: eu-west-1

The alias then reads prod-eu-west-1.

spec is passed through to the provider block as written, so anything the provider accepts goes there: profile, assume_role, endpoints. Octo also writes allowed_account_ids onto every AWS provider from accountId, so credentials for another account fail the plan instead of deploying there. An entry with an accountName goes without it, since the guard would put the account number back into the committed Terraform.

A HashiCorp utility provider such as null, random or time takes no region, and Octo leaves the region line off it. For a provider Octo does not know that behaves the same way, setRegionAttribute: false on the entry does the same. Each entry needs an account and region pair of its own, whatever its providerType.

settings​

settings:
listeners:
- type: JournalEventListener
- type: LoggingEventListener
level: info
colorize: true
stateProvider:
type: LocalStateProvider
statePath: .octo

listeners decides what each command prints and records. LoggingEventListener is the terminal output, with a level of trace, debug, info, warn, error, fatal or silent, and colorize, which defaults to whether the output is a terminal. JournalEventListener keeps the journal. Without any listeners a command is silent.

stateProvider is required, and picks where Octo's state, Terraform's state and the app's lock are kept. LocalStateProvider keeps them in the statePath directory. RemoteStateProvider keeps them in a backend every machine reaches:

  stateProvider:
type: RemoteStateProvider
organizationId: shop-organization
appId: shop
sessionId: "${env.STATE_SESSION_ID}"
statePath: .octo

State Providers covers what each key means and which provider a team needs.

env​

Values you want to declare in one place and override from the shell.

env:
- key: AWS_ACCOUNT_ID
kind: string
value: "123456789012"
- key: ENABLE_NAT_GATEWAY
kind: boolean
value: false

Reference one as ${env.KEY}, anywhere in moduleInputs at any depth, and in a provider's accountId, regionId or spec. A reference that is the whole value takes the key's kind, and one inside a longer string is written into it, so an ARN can be built from its parts:

resources: ["arn:aws:ses:us-east-1:${env.AWS_ACCOUNT_ID}:identity/example.com"]

An environment variable named OCTO_ENV_ and the key wins over the declared value, which is what makes the same file work in CI:

OCTO_ENV_AWS_ACCOUNT_ID=999999999999 npm run octo:generate

Only the OCTO_ENV_ name counts, so an AWS_ACCOUNT_ID your shell exports for other work cannot move a deploy to another account. The value from the shell is converted to the key's kind, and a boolean accepts only a plain true or false.

hooks​

Optional callbacks around lifecycle points, for an audit trail or an approval gate.

hooks:
- importPath: "./dist/index.js"
method: registerAuditHooks

The named export is called, and returns the hooks to register. Hooks covers the shapes available.

tags​

Tags applied to every resource a run produces, without any module being told about them.

tags:
- tags:
ManagedBy: octo
Owner: platform-team
- scope:
moduleId: region-module
tags:
Tier: network

An entry with no scope reaches every resource; one naming a moduleId reaches only what that module declared, and wins where both set the same key. Tagging Resources covers what to put there.

extends and stores​

Two optional sections let one app build on the state of another, such as a web app standing on the backend it calls. Building on Other Apps covers both.

rules​

The rules file, relative to octo.yaml. Without the key, Octo reads rules.yaml beside octo.yaml when there is one, and runs without rules when there is not; a file the key names must exist.

rules: policies/rules.yaml

Writing Rules covers what a rules file holds. The file is checked against its own schema, which an editor can read the same way:

# yaml-language-server: $schema=https://raw.githubusercontent.com/quadnix/octo/refs/heads/main/packages/octo-build/src/resources/rules-v1.schema.json

References between modules​

${{...}} is how one module receives what another produced, and it is what makes this a graph rather than a list.

FormResolves to
${{<moduleId>.model.<key>}}A model the module produced. ${{region-module.model.region}}.
${{<moduleId>.overlay.<overlayId>}}An overlay the module produced, by its overlay ID.
${{<moduleId>.resource.<resourceId>}}A resource the module produced, by its resource ID.
${{<moduleId>.input.<key>}}An input that module was given, so two modules can share a value.
${{<moduleId>.metadata.<key>}}Something the module's registerMetadata() worked out.

The <key> is what the module registered its output under, and it is normally the model's node name: model.app, model.account, model.region, model.subnet, model.service. A dotted path digs into the value, so ${{region-module.model.region.regionId}} is the string rather than the node.

Hand over the node wherever you can. ${{region-module.model.region}} gives the storage module a region it can query for anchors; ${{region-module.model.region.regionId}} gives it a string it can only trust.

References resolve when the module that needs them runs, so the module being referenced has to be listed earlier. A reference that cannot be resolved is an error naming the reference.

Functions from your own code​

A module input that is a function, such as a bucket's filter or transform, takes an export of a JavaScript file of yours:

octo/upload.js
export function skipSourceMaps(filePath) {
return !filePath.endsWith('.map');
}

export function underApp(filePath) {
return `app/${filePath}`;
}
    moduleInputs:
directoryPath: dist
filter: "${import ./octo/upload.js#skipSourceMaps}"
transform: "${import ./octo/upload.js#underApp}"

${import <path>#<export>} is replaced by that export before the module runs. A relative path is read from the definition file's directory, and a package name from your project's dependencies, the same as imports. The reference is the whole value; one inside a longer string is an error.

Octo loads the file with Node, so it is JavaScript, or TypeScript you compile first. The function runs on every command, and Octo compares what it returns between runs, so it reads nothing but its arguments: one that reads the clock or the network changes the plan every time.

Several definition files​

There is no environment flag. A deployment that must not share state with another is a separate file with a separate statePath:

OCTO_DEFINITION_FILE_PATH=octo.prod.yaml octo generate -o .octo-tf-prod

Keep the output directories separate too. Octo leaves folders it does not recognize alone, so nothing is overwritten, but terragrunt run --all does not know that: point two definitions at one directory and an apply of either one applies both.

Octo's environment model is a different idea, and the one to reach for first. staging and qa inside one region are environment models: they live in one graph, share one state file, and can refer to each other. A separate file is for deployments that must be isolated from each other, which for most teams means production and everything else.