Skip to main content

Building on Other Apps

Infrastructure rarely lives in one repository for long. A platform team runs the network and the shared services, and the teams that build on it keep their own repositories, deploy on their own schedule, and should not be able to change what the platform owns. Their infrastructure still has to point at the platform's: checkout's server calls the platform's payments function, and needs its role admitted there.

Octo lets one app read another app's state, so a module can be handed something the other app built exactly as if it were built here. There are two ways to do it, and they differ in whose graph the new infrastructure belongs to.

  • extends makes the other app's graph part of this one. This file declares no app of its own; it adds to the other app's, the way a second team adds servers to the platform.
  • stores reads the other app's graph under a name and leaves it separate. This file declares its own app and builds beside the other one, reaching into it only where a module is handed something from it.

Either way the other app is read and never written. Octo writes no Terraform for it, none of its code runs here, and a run that would change one of its resources fails.

Extending an app​

octo.yaml
extends:
- type: LocalStateProvider
statePath: ../platform/.octo

modules:
- moduleId: checkout-account-module
moduleClass: AwsIniAccountModule
moduleInputs:
accountId: "123456789012"
app: "${{platform-app-module.model.app}}"

- moduleId: checkout-server-module
moduleClass: AwsServerModule
moduleInputs:
account: "${{checkout-account-module.model.account}}"
serverKey: checkout
lambda:
- execution: "${{platform-payments-execution-module.model.execution}}"

The entry takes the same fields as settings.stateProvider. Modules then reference what the platform built by the platform's own module IDs: the account sits under the platform's app, and checkout's server is admitted to the platform's payments function. A moduleId the platform already uses is refused, so the two files cannot collide.

Reading a store​

octo.yaml
stores:
- name: platform
stateProvider:
type: LocalStateProvider
statePath: ../platform/.octo

modules:
- moduleId: checkout-app-module
moduleClass: SimpleAppModule
moduleInputs:
name: checkout

- moduleId: checkout-account-module
moduleClass: AwsIniAccountModule
moduleInputs:
accountId: "123456789012"
app: "${{checkout-app-module.model.app}}"

- moduleId: checkout-server-module
moduleClass: AwsServerModule
moduleInputs:
account: "${{checkout-account-module.model.account}}"
serverKey: checkout
lambda:
- execution: "${{platform:platform-payments-execution-module.model.execution}}"

Here checkout is an app of its own, and the payments function is reached through the store by its name, a colon, and the reference the platform's own file would write. Building directly onto the store, such as standing an account on the platform's app, fails with Cannot add to read-only node "app=platform"!. That is the line between the two: to add to another app's graph, extend it.

A store name holds letters, digits, _ and -, and since the colon marks a store, no moduleId may contain one.

What is read, and when​

Octo reads the other app's newest sealed state: what its last commit, or its last unlock, left behind. A change the other app has under way is never seen, and an app that has never committed cannot be read yet. generate reads it once, and the rest of the run uses what generate read.

Nothing tells this app when the other one changes. The next time this app runs generate or validate after the other app has committed, it warns:

The state this app extends changed since this app's last commit; this run builds on its newest.

The change reaches this app's infrastructure when this app is applied again. A store that renamed or removed something this app points at shows up in that run's report, as a change to the resource pointing at it.

With remote state, statePath under the entry is where Octo keeps its copy of the other app's state, so give each entry a folder of its own.

Requirements​

A module of this app can only take a node whose class this file's imports loads. An import loads every class its module defines, so importing the other app's module class is enough, even without listing it under modules.

Both apps must be generated on the same version of every package they both import, Octo's included. A mismatch fails, naming the package and both versions.

Stopping​

To stop reading a store, remove the modules that use it, and the store with them. The next run plans the deletion of what those modules built.