# Tree Model

> **Status:** Draft 0.2, 2026-11-23. The shape of a Gravity Keep configuration: namespaces, placement, resources and their types, defaults and guardrails, templates, references, bindings and policy, how a value is resolved, the two written forms, and sources. Companion to [Vision](vision.md), [Commit Model](commit-model.md), and [Rules](rules.md).

# 1. Purpose

Junos gives every device the same fixed top level (`system`, `interfaces`, `protocols`, `security`). AWS estates don't share a shape. One company starts with a single account, another with an organization of two hundred. One organizes by business unit, another by environment first. So Gravity Keep keeps the Junos discipline (a single tree, edited as a candidate, committed whole) and makes the **top of the tree the company's own**. The company names its branches. The fixed vocabulary appears only *inside* a namespace: `placement`, `defaults`, `guardrails`, `binding`, `policy`, `access`, `source`, `templates`, `template`, `apply`, `resource`, and `namespace`. Inside a resource, `placement`, `protect`, `adopt-from`, `create`, `destroy`, and the type's own properties.

The tree is the one place where it is stated what should exist, where it should exist, and what every piece must have in common with its neighbours.

# 2. Namespaces

A **namespace** is a named branch. Its **path** is its name and the names of every namespace above it: `/tidewater/lending/prod`.

- Names are lower-case letters, digits, and hyphens, starting with a letter, at most 40 characters ([CTL-001](rules.md#tree)). They never contain a dot, which is how a path tells a namespace from a resource type.
- A namespace may hold other namespaces, resources, and the statements in section 1. Nothing else.
- A namespace carries no meaning of its own. `/tidewater/lending/prod` is not special because it says `prod`. It is special because of its `binding` and `policy` (section 8). The name is for people.
- A namespace may be **moved** or **renamed** in one commit. Its resources keep their identity: nothing is replaced, and only the `gravity-path` tag changes ([CTL-006](rules.md#tree)).
- An empty namespace is removed at commit, as an empty hierarchy is in Junos.

A typical first tree is one namespace for one account. It grows into this without being rebuilt:

```
/tidewater                      the company: organization, guardrails, tags
  /tidewater/organization       accounts, OUs, SCPs, tag policies
  /tidewater/foundation         the Standard's foundation infrastructure
    /tidewater/foundation/prod
  /tidewater/lending            one application
    /tidewater/lending/dev
    /tidewater/lending/prod
      /tidewater/lending/prod/east
      /tidewater/lending/prod/west
```

# 3. Placement

**Placement** says where the resources of a namespace land. It has four keys, each inherited by everything beneath until something sets it again ([CTL-007](rules.md#placement)):

| Key | Value | Example |
|---|---|---|
| `organization` | An AWS Organizations ID, or a reference to one in the tree | `o-tw7exampl3` |
| `account` | A 12-digit account ID, or a reference to an `organizations.account` in the tree | `@/tidewater/organization/organizations.account/lending-prod:account-id` |
| `region` | An AWS Region code | `us-east-2` |
| `zone` | An Availability Zone **ID**, never a zone name | `use2-az1` |

Zone IDs are required because zone names (`us-east-2a`) map to different physical zones in different accounts, and a tree that spans accounts must mean the same place everywhere ([CTL-009](rules.md#placement)).

Every resource type has a **scope**, taken from the type's registry schema and the Gravity Keep type table:

| Scope | Needs | Examples |
|---|---|---|
| `global` | `account` | `iam.role`, `iam.policy`, `route53.hosted-zone`, `cloudfront.distribution`, `organizations.account` |
| `regional` | `account`, `region` | `s3.bucket`, `lambda.function`, `kms.key`, `rds.db-instance`, `logs.log-group` |
| `zonal` | `account`, `region`, `zone` | `ec2.subnet`, `ec2.volume` |
| `organization` | `organization` (and the management account) | `organizations.policy`, `organizations.organizational-unit` |

Commit check fails a resource whose placement does not resolve for its scope ([CTL-008](rules.md#placement)). A global resource ignores an inherited `region`; it is not an error.

A resource may set its own placement when its type demands somewhere specific. The usual case is a certificate for CloudFront, which must be issued in `us-east-1`:

```
resource acm.certificate cdn {
    placement { region us-east-1; }
    domain-name lending.tidewater.com;
    validation-method DNS;
}
```

**Moving an account under an organization** is a placement change high in the tree. A company that started with `/tidewater` placed directly in account `210987654321` adds `/tidewater/organization`, invites that account as an `organizations.account` resource (by adoption, since it exists), and sets `placement organization` on `/tidewater`. Nothing beneath moves ([samples/session-04-move-under-organization.md](samples/session-04-move-under-organization.md)).

# 4. Resources and types

A **resource** is a leaf: `resource <type> <name> { <properties> }`.

- **Types come from the CloudFormation registry.** Each registry type (`AWS::S3::Bucket`) has a derived alias (`s3.bucket`): the service and resource names, lower-cased, with words separated by hyphens (`AWS::EC2::SecurityGroup` → `ec2.security-group`). The CLI accepts either and always displays the alias ([CTL-010](rules.md#resources-and-types)).
- **Properties come from the type's schema**, with PascalCase names written in kebab-case (`VersioningConfiguration` → `versioning-configuration`). Acronyms are split by one published table (`KMSMasterKeyID` → `kms-master-key-id`, `SSEAlgorithm` → `sse-algorithm`), so a name is derived, never chosen twice, as in the Standard's CONV-006.
- **Types and validation are the schema's.** Required properties, enumerations, patterns, and lengths are checked at commit check, and the CLI completes property names and values from the schema.
- **A name is unique within its namespace and type.** The resource's full path is `<namespace path>/<type>/<name>`: `/tidewater/lending/prod/s3.bucket/documents`. Because types contain a dot and namespaces never do, a path always parses one way.
- **Only stated properties are managed** ([CTL-011](rules.md#resources-and-types)). A property that is neither stated on the resource nor supplied by a default, guardrail, or template is left to AWS. The rule applies inside nested blocks too: when a block states two of its sub-properties and AWS fills in five more, only the two are managed. Drift is only ever about managed properties, which keeps noise out.
- **Read-only properties** (`Arn`, `DomainName`) can't be set. They are what references read (section 7).
- **Create-only properties** (a bucket name, a database engine) can be set once. Changing one replaces the resource, which commit check reports as destructive when the type is stateful or identity-bearing ([commit-model 9](commit-model.md#9-deletion-and-replacement)).

**The type table** adds what the registry schema doesn't say, one row per type, published with Gravity Keep and changed only by recorded decision. `show type <type>` prints a type's row.

| Column | Says | Example |
|---|---|---|
| Scope | `global`, `regional`, `zonal`, or `organization` ([section 3](#3-placement)) | `acm.certificate`: regional |
| Stateful | Whether removing or replacing it loses data, or something others hold that is as costly ([commit-model 9](commit-model.md#9-deletion-and-replacement)) | `acm.certificate`: no; `route53.hosted-zone`: yes |
| Identity | The attributes others hold that recreating can't restore; a type with any is identity-bearing ([commit-model 9](commit-model.md#9-deletion-and-replacement)) | `iam.role`: unique ID; `ec2.security-group`: group ID; `acm.certificate`: none |
| Runner | `cloud-control` (the default), or the name of a hand-written action runner for a type with special needs ([architecture 5](architecture.md#5-convergence)) | `acm.certificate`: `acm-certificate` |
| Converging limit | How long a create or update may stay `converging` before it is `failed` ([CTL-064](rules.md#convergence)) | `rds.db-instance`: 2h; `acm.certificate`: 72h, as ACM itself allows |
| Typical duration | What commit check shows before committing | `rds.db-instance` create: about 15m |
| Early attributes | Attributes that are known, and may be referenced, while the resource is still `converging` ([section 7](#7-references)) | `acm.certificate`: `validation-record-name`, `validation-record-value`, `validation[<domain>]` |
| Destroy values | Values used only when the resource is deleted ([section 4.1](#41-lifecycle-phases)) | `rds.db-instance`: `final-snapshot-identifier`; `kms.key`: `pending-window-in-days` (default 30); `s3.bucket`: `empty-before-delete` |
| List keys | For an attribute that is a list of objects, the property that identifies each entry ([section 7](#7-references)) | `acm.certificate` `validation`: `domain-name` |
| Comparison | For a property AWS returns in a different form from the one written, the normaliser applied before comparing ([section 4.2](#42-comparing-values)) | `iam.role` `assume-role-policy-document`: `json`; `ec2.security-group` `security-group-egress`: `set`; `rds.db-instance` `engine-version`: `version-prefix` |

Most types need only the first three columns and Cloud Control. The rest exist for the few that behave unusually, and stay empty until a type needs them.

**A type is supported only once its comparisons hold.** Before a type is offered for `owned` namespaces, it runs against real resources under `report`, and any drift that nobody caused is fixed in its comparison column first. Remediating a difference that is only a matter of format would change resources for no reason, and would trip the limit for fighting resources ([CTL-032](rules.md#drift)).

Lists of objects are written as repeated blocks of the same name, in order. Lists of scalars use brackets:

```
resource ec2.security-group intake-lambda {
    group-description "Intake Lambda egress to Postgres";
    vpc-id @../ec2.vpc/main:vpc-id;
    security-group-egress {
        ip-protocol tcp;
        from-port 5432;
        to-port 5432;
        destination-security-group-id @../ec2.security-group/postgres:group-id;
    }
    security-group-egress {
        ip-protocol tcp;
        from-port 443;
        to-port 443;
        cidr-ip 0.0.0.0/0;
    }
}
```

Tags are a map, not a list, in every type: `tags { owner lending-team; }`. Gravity Keep converts to the type's own tag shape.

## 4.1 Lifecycle phases

Every resource is created, maintained, and destroyed, and a statement on it belongs to one of those phases ([CTL-066](rules.md#resources-and-types)):

| Phase | Written | Holds |
|---|---|---|
| **Create** | Inside `create { }` | Values used only when the resource is created or replaced, then left alone |
| **Maintain** | As an ordinary statement, outside any phase block | Values held for the resource's whole life, and remediated when they drift. The default |
| **Destroy** | Inside `destroy { }` | What happens when the resource leaves the tree, and the values deletion needs |

```
resource rds.db-instance main {
    engine postgres;                          /* maintain: held for life */
    engine-version 17;
    create { allocated-storage 100; }         /* create: storage autoscaling owns it afterwards */
    destroy {
        deletion snapshot;                    /* overrides the namespace's policy deletion */
        final-snapshot-identifier lending-main-final;
    }
}
```

**Create-only properties are not a phase.** They are a fact of the schema (a bucket name, a database engine): stated as ordinary statements, held like any other, and changed only by replacing the resource ([commit-model 9](commit-model.md#9-deletion-and-replacement)). The create phase is for values a person **chooses** to stop holding.

### The create phase

Some properties are needed to create a resource but belong to AWS afterwards: an ECS service's desired count once Application Auto Scaling manages it, an Auto Scaling group's desired capacity, a DynamoDB table's capacity under auto scaling, a database's storage under storage autoscaling. Holding them would undo the scaling, every time.

```
resource ecs.service intake {
    cluster @../ecs.cluster/main;
    task-definition @../ecs.task-definition/intake;
    create { desired-count 2; }
}
```

- A `create` value is applied when the resource is created or replaced, and never compared after that. It is not managed, so it can't drift.
- `create` can be written on a resource, in a template's resource body, and in `defaults`. A template that knows a property belongs to AWS after creation marks it, so no team has to remember to.
- `create` is never allowed in `guardrails`, and commit check refuses `create` for a property that a guardrail above names, because a guardrail always holds.
- Changing a `create` value in a commit changes nothing on an existing resource, and commit check says so. `request reconcile <path> create` applies the current `create` values to existing resources, on purpose.
- **An inherited create-only value never replaces an existing resource** ([CTL-071](rules.md#resources-and-types)). When a create-only property's value comes from a default or a template, it belongs to the create phase: existing resources keep the value they were created with, and new resources get the new one. Commit check says so: `rds.db-instance storage-encrypted: 3 existing resources keep false (create-only, inherited)`. Replacing them is a deliberate act: state the property on each resource, a destructive change that needs acknowledgment as usual.

The phase is about how long a value is held. Where a value comes from is a separate question: a default outside `create` is inherited **and** held, like `retention-in-days 400` on every log group ([section 5](#5-defaults-and-guardrails)).

### The maintain phase

Everything stated outside a phase block. It has no block of its own, because it is what a statement means unless it says otherwise.

**How** a change is applied (RDS `apply-immediately`, ECS `force-new-deployment`) is not a maintained value: AWS doesn't hold it, so there is nothing to compare. These update options are not yet in the model (CTLQ-028).

### The destroy phase

```
destroy {
    deletion snapshot;
    final-snapshot-identifier lending-main-final;
}
```

- `deletion retain | snapshot | delete | evict` says what happens when the resource leaves the tree. It overrides the namespace's `policy deletion` ([section 8](#8-bindings-policy-and-access)), which stays the default for every resource beneath.
- The other statements are the type's **destroy values**, listed in the type table: a database's final snapshot name, a KMS key's waiting period, a secret's recovery window, whether a bucket or repository may be emptied before deletion. They are never compared and never cause an update ([CTL-070](rules.md#resources-and-types)).
- `destroy` can be written on a resource, in a template, and in `defaults`. **Guardrails may restrict it**, so a company can say that nothing beneath a namespace is ever simply deleted: `guardrails { rds.db-instance { destroy { deletion in [ retain snapshot ]; } } }`.
- **Destroy values come from the last configuration that held the resource.** Removing a resource from the tree removes its `destroy` block with it, so deletion follows the block as it stood in the commit before the removal. Commit check shows the steps: `delete rds.db-instance/main: snapshot lending-main-final, then delete`.
- Cloud Control's delete takes no options, so the action runner carries out the destroy phase as recorded steps: updates the delete needs first (turning off deletion protection), the snapshot, emptying where allowed, then the delete.

`protect` stays an ordinary statement rather than a destroy value, because it also stops a resource being moved or renamed ([CTL-048](rules.md#ownership-and-deletion)).

## 4.2 Comparing values

AWS often returns a value in a different form from the one written: a policy document with its keys reordered, a list in another order, an ARN where a name was given, `17.4` where `17` was configured. Drift is decided only after both sides are normalised ([CTL-067](rules.md#resources-and-types)), with one of a short, fixed set of normalisers named in the type table's comparison column:

| Normaliser | Treats as equal |
|---|---|
| `json` | Documents that parse to the same value, with a single item and a one-item list counted as the same, as IAM does |
| `set` | Lists with the same entries in any order |
| `arn-or-name` | A name and the ARN that ends in it |
| `version-prefix` | A configured version and any observed version that begins with it: `17` matches `17.4` and `17.5` |
| `case-insensitive` | Values that differ only in letter case |
| `numeric` | A number and the string that spells it |

There are no custom comparison functions. A new normaliser is added by recorded decision, as a hand-written runner is (CTLQ-025). `version-prefix` is how a database is kept on its major version while AWS applies minor upgrades: `engine-version 17;` holds the major version and lets the minor one move.

## 4.3 Secrets and write-only properties

**A secret never appears in the tree** ([CTL-068](rules.md#resources-and-types)). The tree is stored in Postgres, in Git sources and exports, in plans, and in logs, so a secret written there would be everywhere. Two routes instead:

- **AWS keeps it** (preferred). `manage-master-user-password true;` on a database, or `generate-secret-string { ... }` on a `secretsmanager.secret`, and no person or tool sees the value.
- **A secret reference**, for a property that must be given a value, such as a vendor's API key on an EventBridge connection: `api-key-value @/tidewater/foundation/prod/secretsmanager.secret/vendor-api:secret-string;`. The action runner reads the secret at the moment of the AWS call. The value is never stored, planned, exported, or logged; a plan shows `(secret from /tidewater/foundation/prod/secretsmanager.secret/vendor-api, version 3)`.

**Write-only properties**, which AWS accepts but never returns (the registry schema lists them), can't be compared with AWS. The control plane compares them with a hash of **what it last sent**, and sends them again only when the configured value, or the secret's version, changes ([CTL-069](rules.md#resources-and-types)). They never drift; `show resource` marks them `write-only`.

# 5. Defaults and guardrails

A namespace can set what everything beneath it has in common in two ways ([CTL-012](rules.md#defaults-and-guardrails) to [CTL-016](rules.md#defaults-and-guardrails)).

**Defaults** fill in what a resource leaves unset. A nearer namespace's default wins over a farther one, and a resource's own statement wins over any default. A default is held like any other managed value, unless it is written inside `create` or `destroy` ([section 4.1](#41-lifecycle-phases)).

**Guardrails** say what must be true of everything beneath. Nothing beneath may weaken them. A resource that conflicts with a guardrail fails commit check, with the guardrail's path in the message. Guardrails use a fixed set of forms, with no expression language:

| Form | Meaning | Example |
|---|---|---|
| `<property> <value>` | The property has this value, and it is applied if unset | `public-access-block-configuration { block-public-acls true; }` |
| `<property> required` | The property must have a value, from anywhere | `bucket-encryption required;` |
| `<property> in [ ... ]` | The value is one of these | `architectures in [ arm64 ];` |
| `<property> not-in [ ... ]` | The value is none of these | `engine not-in [ mysql ];` |
| `<property> minimum <n>` / `maximum <n>` | A numeric bound | `retention-in-days minimum 400;` |
| `types allow [ ... ]` / `types deny [ ... ]` | Which resource types may appear beneath | `types deny [ ec2.instance ];` |
| `placement region in [ ... ]` | Where anything beneath may land | `placement region in [ us-east-2 us-west-2 ];` |
| `tags <key> required` | Every taggable resource beneath has the tag | `tags data-classification required;` |

Defaults and guardrails are written per resource type, or for `tags` and `placement`, which apply to all types:

```
namespace tidewater {
    guardrails {
        placement region in [ us-east-2 us-west-2 us-east-1 ];
        tags {
            application required;
            environment required;
            owner required;
            data-classification required;
            cost-center required;
        }
        s3.bucket {
            public-access-block-configuration {
                block-public-acls true;
                block-public-policy true;
                ignore-public-acls true;
                restrict-public-buckets true;
            }
            bucket-encryption required;
        }
        logs.log-group {
            kms-key-id required;
            retention-in-days minimum 400;
        }
        lambda.function {
            architectures in [ arm64 ];
        }
    }
    defaults {
        tags { cost-center 4100; }
        s3.bucket {
            bucket-encryption {
                server-side-encryption-configuration {
                    server-side-encryption-by-default {
                        sse-algorithm aws:kms;
                        kms-master-key-id @/tidewater/foundation/prod/kms.key/data:arn;
                    }
                    bucket-key-enabled true;
                }
            }
        }
    }
}
```

**Promoting a change through the tree.** A change high in the tree reaches every environment beneath it at once. To take it to dev first, set it nearer: a default at `/tidewater/lending/dev` wins over the one at `/tidewater`. Then set it at `prod`, then move it up with `promote <statement> to <path>`, which sets the statement at the higher namespace and deletes the identical copies beneath it in one commit. Commit check confirms that a promotion changes nothing in AWS where the copies already applied, and shows the reach of what it does change ([commit-model 3](commit-model.md#3-commit-check)). Templates promote the same way, one namespace at a time, because a version is resolved only by a commit to the namespace that applies it ([section 6.1](#61-version-constraints)).

**Tags merge** down the tree key by key: a nearer namespace sets or overrides individual keys and keeps the rest. Two tags are always added and can't be overridden: `managed-by gravity-keep` and `gravity-path <the resource's namespace path>` ([CTL-015](rules.md#defaults-and-guardrails)). Tags derived from a binding (section 8) are added too. As in the Standard, **tags are never access control.**

**Audit guardrails** let a new guardrail be rolled out without stopping every commit on the day it appears ([CTL-072](rules.md#defaults-and-guardrails)):

```
namespace tidewater {
    guardrails audit {
        s3.bucket { bucket-key-enabled true; }
        logs.log-group { retention-in-days minimum 731; }
    }
}
```

- An audit guardrail uses the same forms as a guardrail, but it never fails a commit and never changes a resource, not even a fixed value applied where a property is unset. Each violation is a **finding**, listed by `show findings` and counted in every commit check beneath it.
- Making it a real guardrail is a commit that moves the statement from `guardrails audit` to `guardrails`. Commit check then fails if anything still violates it, naming each resource. There is no date on which it turns real by itself: a change of behaviour without a commit is what [CTL-023](rules.md#candidate-and-commit) forbids.
- For a fixed value, the findings are exactly what the real guardrail would change, so the audit stage shows the reach of the change before anything moves.

Guardrails are checked when a commit is made. They are not a substitute for AWS Organizations service control policies, which AWS enforces on every API call, including calls that bypass Gravity Keep. A company should express its hardest boundaries as both: an SCP resource in `/tidewater/organization`, and the matching guardrail, so the commit fails early with a clear message instead of failing at AWS.

# 6. Templates

A **template** is a named, versioned bundle of resources stood up together, such as the Gravity Standard's Lambda: the function, its role, its KMS-encrypted log group, its metric filters, and its alarms.

```
template gs-lambda {
    version 1.2.0;
    description "Gravity Standard Lambda: arm64 Go, encrypted logs, tracing, error alarm";
    parameter memory { type integer; default 512; minimum 128; maximum 10240; }
    parameter timeout { type integer; default 30; maximum 900; }
    parameter code { type s3-object; }
    parameter log-key { type reference kms.key; }
    parameter alarm-topic { type reference sns.topic; }
    fixed lambda.function/fn architectures [ arm64 ];
    fixed lambda.function/fn runtime provided.al2023;
    resource logs.log-group logs {
        log-group-name /aws/lambda/${namespace};
        retention-in-days 400;
        kms-key-id ${log-key}:arn;
    }
    resource iam.role exec { ... }
    resource lambda.function fn {
        function-name ${namespace};
        handler bootstrap;
        memory-size ${memory};
        timeout ${timeout};
        code { s3-bucket ${code}:bucket; s3-key ${code}:key; }
        role @./iam.role/exec:arn;
        logging-config { log-group @./logs.log-group/logs; log-format JSON; }
        tracing-config { mode Active; }
    }
    resource cloudwatch.alarm errors { ... }
}
```

A namespace uses a template with `apply`:

```
namespace intake {
    apply gs-lambda {
        version "~> 1.2.0";
        memory 1024;
        code s3://tidewater-artifacts/lending/intake/2.4.1/bootstrap.zip;
        log-key @/tidewater/foundation/prod/kms.key/logs;
        alarm-topic @/tidewater/foundation/prod/sns.topic/lending-alarms;
    }
}
```

- **Expansion is visible.** The template's resources appear in the namespace that applies it, at ordinary paths (`.../intake/lambda.function/fn`), and `show | display templates` shows which came from where ([CTL-019](rules.md#templates)).
- **Parameters are declared and typed.** A value outside a parameter's type or bounds fails commit check. `${namespace}` (the applying namespace's name) and `${path}` are the only built-in values.
- **Substitution only.** A template has no loops, conditionals, or functions ([CTL-018](rules.md#templates)). A template that needs two shapes is two templates, or one template with an optional resource controlled by a `choice` parameter declared by the template (CTLQ-005).
- **A namespace may override** a template's property by stating it on the resource at the same path, unless the template declares it `fixed`. The override is shown in `display inheritance`.
- **Templates are referenced, never copied** ([CTL-017](rules.md#templates)). They are declared with `template` in a namespace (visible there and beneath) or come from a published library named in a `templates` block (the Gravity Standard's, for example), with a version constraint ([section 6.1](#61-version-constraints)).
- **Defaults and guardrails still apply** to a template's resources. A template can't escape the namespace it lands in.

## 6.1 Version constraints

An `apply` names the versions it accepts with Terraform's constraint syntax, so anyone who has pinned a Terraform module or provider already knows it:

| Constraint | Accepts |
|---|---|
| `version "1.2.3";` or `version "= 1.2.3";` | Exactly 1.2.3 |
| `version "~> 1.0";` | 1.0.0 and later, below 2.0.0: any 1.x |
| `version "~> 1.2.0";` | 1.2.0 and later, below 1.3.0: patches to 1.2 only |
| `version ">= 1.2, < 1.5, != 1.3.1";` | Every condition, separated by commas |

- **The newest matching version is chosen.** A prerelease (`1.3.0-rc.1`) is chosen only when the constraint names it exactly.
- **A range is resolved at commit, never in between** ([CTL-065](rules.md#templates)). Publishing `gs-lambda 1.4.0` changes nothing in the tree by itself. The commit records the exact version and digest each `apply` resolved to, and the tree stays on those until another commit resolves again. Otherwise a publication would change production with no commit, which [CTL-023](rules.md#candidate-and-commit) forbids.
- **A commit resolves only what it touches.** It re-resolves the `apply` statements in namespaces whose own statements it changes; a load from a Git source counts as changing its whole subtree. A commit to `/tidewater/support` never upgrades Lending's templates. To take new versions without any other change, `update templates [<path>]` re-resolves every `apply` beneath the path in the candidate.
- **An upgrade is always shown.** Commit check lists every version it would move, `template gs-lambda 1.3.0 -> 1.3.1 (newest within ~> 1.3.0) at /tidewater/lending/dev/intake`, with the plan the new version causes.
- **Going back restores versions exactly.** `rollback` and `request revert` restore the versions an earlier commit recorded. They never re-resolve, so going back really goes back.
- **A published version never changes.** If a version's digest differs from the one an earlier commit recorded, commit check fails: a republished `1.2.3` is a supply-chain alarm, not an upgrade.

# 7. References

A **reference** points from a property to another resource or one of its attributes: `@<path>:<attribute>`.

| Form | Meaning |
|---|---|
| `@/tidewater/foundation/prod/kms.key/data:arn` | An absolute path and attribute |
| `@./iam.role/exec:arn` | A resource in the same namespace |
| `@../ec2.vpc/main:vpc-id` | A resource one namespace up |
| `@/tidewater/foundation/prod/kms.key/data` | The type's primary identifier, when no attribute is named |
| `@./acm.certificate/cdn:validation[www.tidewater.com].record-value` | One entry of a list attribute, picked by its key, then a field of that entry |

- References must resolve at commit check, to a resource in the candidate or a resource adopted into the tree. A reference to something outside the tree is not allowed; adopt it first ([CTL-020](rules.md#references)).
- References give **order**: a resource is created after everything it references, and deleted before. A cycle fails commit check, with the cycle named.
- **A reference waits until what it references is `stable`** ([CTL-063](rules.md#references)), and the resource that holds it is `converging`, waiting on it, meanwhile. The one exception is an **early attribute**, listed in the type table: a value the resource has as soon as its creation starts, such as the DNS record an ACM certificate needs before it can be issued. A reference to an early attribute waits only until that value is known. A reference to anything else on the same resource still waits for it to be stable, which matters because some values that are known early can't be used early: a certificate's ARN exists at once, but CloudFront refuses a certificate that hasn't been issued.
- **List entries are picked by key, never by position.** An attribute that is a list of objects is indexed by the key property the type table names for it, because AWS decides the order of a list, and an order can change. A key that isn't in the list fails commit check if it can be known then, and fails the action otherwise.
- A reference is the only way one resource depends on another. There is no `depends_on`. If an ordering matters and no property says so, the template is missing a reference.
- Attribute names come from the schema's read-only properties, in kebab-case, and, for a type with a hand-written runner, from the type table.

# 8. Bindings, policy, and access

**`binding`** ties a namespace to a Gravity Standard application and environment:

```
namespace prod {
    binding {
        application lending;
        environment production;
        data-classification restricted;
    }
}
```

A binding is inherited. It sets the `application`, `environment`, and `data-classification` tags on everything beneath, so they are never written twice. Its environment is also what commit check counts reach by ([commit-model 3](commit-model.md#3-commit-check)), and what makes `commit mode reviewed` the default beneath production. A binding is a description, not a governance check: Gravity Keep doesn't verify development permits, and a company that uses them checks them in its pipeline, as the Standard does today.

**`policy`** says how the namespace is governed:

| Statement | Values | Default |
|---|---|---|
| `drift` | `remediate`, `report`: what an `owned` namespace does about changes made outside a commit | `remediate` |
| `commit mode` | `direct` (any authorized person commits), `reviewed` (a commit needs a second person's approval or a reviewed source) | `direct`, and `reviewed` beneath any binding to `production` |
| `commit confirmed required` | A list of types (or `all`) and a time: `commit confirmed required [ ec2.security-group wafv2.ip-set ] minutes 10;`. A commit from a session or a commit request whose plan touches a listed type is made as `commit confirmed` automatically. Loads from a Git source are not ([commit-model 5](commit-model.md#5-commit-confirmed)) | none |
| `protect` | Marks the namespace or a resource so it can't be deleted, moved, or renamed without first removing `protect` in a separate commit | not protected |
| `deletion` | `retain`, `snapshot`, `delete`, `evict`: what happens to a stateful resource removed from the tree (`evict` leaves it in AWS untagged, [commit-model 8.4](commit-model.md#84-evict)). A resource's own `destroy` block overrides it ([section 4.1](#41-lifecycle-phases)) | `retain` |
| `hold` | `maximum <d> total <d>`: the longest a single hold or extension may run, and the most all of a hold's extensions may add up to ([commit-model 6.1](commit-model.md#61-holds)) | `maximum 4h total 24h` |
| `ownership` | `owned` (commits change AWS; changes outside a commit are remediated or reported), `learning` (commits change AWS; changes outside a commit are written into the tree), or `observed` (described and watched, drift is reported, and nothing is ever changed, including tags) ([commit-model 8.3](commit-model.md#83-learning)) | `owned` |
| `learn` | `types [ ... ]`, `regions [ ... ]`, `tags { ... }`: narrows a learning namespace's area. Learning areas may not overlap | the whole placement |

**`access`** says which directory groups may do what beneath the namespace. It compiles to Verified Permissions policies, as the Standard's skills do. A person is never named:

```
access {
    group platform-engineers { edit; commit; approve; adopt; hold; revert; }
    group lending-engineers { edit; commit-request; }
    group auditors { view; }
}
```

# 9. How a value is resolved

For each managed property of each resource, the resolved value is found in this order, each later source overriding the earlier ([CTL-013](rules.md#defaults-and-guardrails)):

1. The template's resource body, if the resource came from a template.
2. Defaults, from the root namespace down to the resource's own namespace, nearest last.
3. The resource's own statements.
4. Guardrails with a fixed value, from the root down. A conflict with step 3 or with a nearer guardrail is an error, never a silent win.

A value written inside `create` is resolved the same way, and used only when the resource is created or replaced; a value inside `destroy` is used only when it is deleted ([section 4.1](#41-lifecycle-phases)).

Then every guardrail is checked against the result. `show | display inheritance` shows, for every value, where it came from:

```
resource s3.bucket documents {
    bucket-name tidewater-lending-prod-documents;
    ##
    ## 'bucket-encryption' was inherited from defaults at /tidewater
    ##
    bucket-encryption {
        server-side-encryption-configuration {
            server-side-encryption-by-default {
                sse-algorithm aws:kms;
                kms-master-key-id arn:aws:kms:us-east-2:210987654321:key/7d1e...;
            }
            bucket-key-enabled true;
        }
    }
    ##
    ## 'public-access-block-configuration' was imposed by guardrails at /tidewater
    ##
    public-access-block-configuration { ... }
}
```

# 10. The two written forms

Like Junos, the same tree has two equivalent forms, and the CLI converts between them losslessly.

**Hierarchical** (what `show` prints, and what a Git source holds, [section 11](#11-sources)):

```
namespace tidewater {
    namespace lending {
        namespace prod {
            resource s3.bucket documents {
                bucket-name tidewater-lending-prod-documents;
                versioning-configuration { status Enabled; }
            }
        }
    }
}
```

**Set** (what `show | display set` prints, and what people paste):

```
set /tidewater/lending/prod resource s3.bucket documents bucket-name tidewater-lending-prod-documents
set /tidewater/lending/prod resource s3.bucket documents versioning-configuration status Enabled
```

A leading `/` names a namespace path. Without one, `set` is relative to the session's current level ([command-reference 3](command-reference.md#3-moving-around-the-tree)).

A JSON form, matching the Standard's canonical-form rules, is produced by `show | display json` and is what the store and the API exchange.

# 11. Sources

Every namespace has exactly one **source**: the one place its configuration is written ([CTL-050](rules.md#sources)).

| Source | Who changes the namespace | Where its desired state lives |
|---|---|---|
| **The control plane** (the default) | People in sessions, and pipelines through the API: `set`, `load`, `commit`, `commit request` | Only in the control plane's store, with a copy written outside it after every commit ([CTL-056](rules.md#sources)) |
| **Git** | Pull requests to one file on one branch of one repository, loaded with `load source` | In that file. The control plane holds the loaded copy and the commit it came from |

The point is one writer per branch. Two writers (a Git file and the CLI) would each hold a copy of the desired state, and whichever wrote last would quietly undo the other. With one source per branch there is nothing to merge back and nothing to overwrite.

## 11.1 Declaring a source

A source is declared by the **parent** namespace, never by the namespace itself ([CTL-051](rules.md#sources)):

```
namespace lending {
    source prod {
        git https://github.com/tidewater/infrastructure;
        branch main;
        file lending/prod.conf;
    }
    namespace prod { ... }
}
```

The parent owns the namespace's name, its place in the tree, and its source. The file owns everything inside it: its statements, resources, and child namespaces. So a file can never declare its own source away, and handing a namespace to Git (or taking it back) is a commit by whoever may commit to the parent, under the parent's review rules.

- **A source covers the whole subtree.** A file holds the namespace and everything beneath it. A file can't contain a `source` statement, so a Git-sourced namespace never has a child sourced elsewhere.
- **A control-plane parent may have Git-sourced children.** That is the usual shape: `/tidewater` and `/tidewater/foundation` are edited in sessions, and each application's production namespace comes from the application team's repository.
- **The top namespace is always sourced in the control plane.** Taking a namespace back from Git is a commit at its parent ([section 11.3](#113-handing-a-namespace-to-git-and-back)), and the top has no parent. A Git-sourced top would also put the whole tree in one file, since nothing beneath a Git source is sourced elsewhere, and a Git outage or a broken Git credential would freeze every guardrail, access grant, and the control plane's own namespace. The top stays in the control plane so there is always somewhere to take a namespace back from Git.
- **The control plane's own namespace is always sourced in the control plane** ([CTL-057](rules.md#sources)). It holds the control plane, the pipeline roles, and the source connector: the things a rollback of a Git change runs through. A change that broke them would break the route to undo it, so they stay under `commit confirmed`.
- **Inheritance still crosses sources.** A default changed at `/tidewater` changes what `lending/prod.conf` resolves to, without the file changing. That is not a second writer, because the file still owns every statement in it. A pull request's `commit check` shows the resolved plan, so reviewers see what the parent supplies.

## 11.2 What a Git source allows and refuses

Beneath a Git-sourced namespace, the configuration changes only by `load source` of its declared file, at a commit on its declared branch ([CTL-052](rules.md#sources)):

| Route | Beneath a Git-sourced namespace |
|---|---|
| `set`, `delete`, `rename`, `copy`, `apply`, `annotate` in a session | Refused when typed, naming the source: change it by pull request |
| `load merge`, `load replace`, `load set` | Refused. Only `load source` loads it |
| `commit request` | Refused. The pull request is the review ([commit-model 10](commit-model.md#10-reviewed-commits)) |
| `rollback` | Refused for the subtree. Revert in Git, or, when it can't wait, `request revert` ([commit-model 12.2](commit-model.md#122-rolling-back-a-git-change)). A rollback of a parent leaves Git-sourced subtrees as they are and says so |
| `commit confirmed` | Not used. The pull request confirms the intent; a bad change is rolled back, not timed out |
| `adopt`, `explore` | Print the resources as a fragment with `adopt-from`, for the person to add in a pull request |
| `evict` | Refused. Set `destroy { deletion evict; }` in one pull request, then remove the resources in the next ([commit-model 8.4](commit-model.md#84-evict)) |
| `policy ownership learning` | Fails commit check: learned changes have nowhere to be written but the file |
| Holds, remediation corrections, `request reconcile` | Unchanged. None of them change the desired state |
| Moving, renaming, protecting, or deleting the namespace itself | At the parent, as for any namespace |

A load moves only forward. The control plane records the last Git commit it loaded (or wrote, [commit-model 12](commit-model.md#12-git-sourced-namespaces)), and a load is refused unless its commit is on the declared branch and descends from that one ([CTL-053](rules.md#sources)). A re-run of an older pipeline can't undo a newer merge.

`adopt-from <primary identifier>` on a resource says that the resource already exists and is to be adopted, not created, the first time a load brings it into the tree. The adopting load follows CTL-035: it may change nothing in AWS but tags. On later loads the statement is checked against the identifier the tree already holds.

## 11.3 Handing a namespace to Git, and back

**To Git.** Write the namespace's file (`show configuration /tidewater/lending/prod | save`), merge it on the branch, then commit the `source` statement at the parent. Commit check reads the file at the head of the branch, and the commit is refused unless the file resolves to exactly the namespace's active configuration ([CTL-055](rules.md#sources)). A handover changes nothing in the tree or in AWS. That head becomes the commit later loads must descend from.

**Back to the control plane.** `delete source prod` at the parent, as a commit. This is also the break-glass route when a desired-state change can't wait for a pull request. A detachment raises an alarm to the namespace's owners, like a hold. To hand the namespace back, merge a file that matches the active configuration and declare the source again.

# 12. Questions

| # | Question | Leaning |
|---|---|---|
| CTLQ-004 | **Regional fan-out.** Should a namespace be able to say `placement region [ us-east-2 us-west-2 ]` and instantiate its resources once per region, or should each region be an explicit child namespace? | Explicit children for now. Fan-out is a loop, and loops are what CTL-018 forbids. Revisit with Tidewater's resilience tier 1 work. |
| CTLQ-005 | **Optional resources in a template.** Is a `choice` parameter that switches one declared resource on or off a conditional by another name? | Allow exactly that and nothing more, so a template doesn't split into near-copies. |
| CTLQ-006 | **Types the registry handles badly.** Some registry types are not fully supported by Cloud Control API, or have awkward schemas, or behave in ways its create, read, update, and delete don't capture. Do they get hand-written action runners, or are they out of scope? | Hand-written runners, named in the type table, each a recorded decision, as the Standard treats hand-written code. Cloud Control stays the default for everything else. `acm.certificate` is the first ([CTLQ-024](commit-model.md#13-questions)); the rest of the list is settled as types come up. |
| CTLQ-007 | **Fully managed resources.** Should a resource be able to say `manage all`, so that unstated properties are held at their schema defaults and any change to them is drift? | Offer it per resource for security-sensitive types (security groups, bucket policies), off by default. |
| CTLQ-017 | **Learning under a Git source.** (Raised as the `adopt` drift policy, which `ownership learning` replaced.) Should learned changes open a pull request against the file instead of failing commit check? | Not yet. Fail commit check; a namespace that wants to learn stays sourced in the control plane. |
| CTLQ-018 | **Keeping `adopt-from`.** Once a resource is adopted, should the statement stay in the file or be removed? | Keep it. It documents where the resource came from, and checking it against the stored identifier costs nothing. |
| CTLQ-019 | **Nested Git sources.** Should a Git-sourced file be able to declare Git sources for its children (never control-plane ones), the way a CODEOWNERS file assigns paths, so a company could keep everything but the top in a tree of files? | Not until a company needs it. Source each child of the top instead; nesting makes out-of-step tracking and reverts depend on the order of files. |
| CTLQ-025 | **The starting normalisers.** Are `json`, `set`, `arn-or-name`, `version-prefix`, `case-insensitive`, and `numeric` enough for the prototype's types? | Start with these six; add one only when a type in `report` mode shows drift nobody caused that none of them explains. |
