Gravity Keep

01 · Tree

One tree for everything you run in AWS.

Namespaces are branches you name yourself. Resources are the leaves. Where things land, what they must have in common, and who writes each branch all flow down the tree, so each is said once.

Namespaces

The top of the tree is yours.

A router has a fixed top level. An AWS estate doesn't: one company starts with an account, another with an organization of two hundred. So the company names its own branches, and the fixed vocabulary appears only inside a namespace: placement, defaults, guardrails, binding, policy, access, source, templates, apply, resource.

A namespace carries no meaning of its own. /tidewater/lending/prod isn't special because it says prod; it's special because of its binding and policy. Moving or renaming one is a single commit, and never replaces a resource.

/tidewater                     organization, guardrails, tags
  /tidewater/organization      accounts, OUs, SCPs
  /tidewater/gravity-keep      the control plane itself
  /tidewater/foundation/prod   keys, WAF, DNS, Postgres
  /tidewater/lending
    /tidewater/lending/dev
    /tidewater/lending/prod    sourced from Git
      /tidewater/lending/prod/east
      /tidewater/lending/prod/west
  /tidewater/sandbox           ownership learning

Placement

Where things land is inherited.

Four keys, each inherited until something sets it again. Every resource type has a scope that says which keys it needs; commit check fails a resource whose placement doesn't resolve. Moving an account under an organization is a placement change high in the tree, and nothing beneath it moves.

KeyExample
organizationo-tw7exampl3
account111100000021, or a reference to an account in the tree
regionus-east-2
zoneAn Availability Zone ID (use2-az1), never a name, because names differ between accounts
ScopeNeedsExamples
GlobalaccountIAM role, hosted zone
Regionalaccount, regionbucket, function, key
Zonal+ zonesubnet, volume
OrganizationorganizationSCPs, OUs

Resources

Types come from AWS, not from a provider someone wrote.

A resource type is a CloudFormation registry type with a derived alias: AWS::EC2::SecurityGroup is ec2.security-group. Properties come from the type's schema, in kebab-case, so validation and completion come from AWS's own definition.

Only what you state is managed. A property nobody stated, down to the sub-properties AWS fills in inside a block, is left to AWS and can never drift. That keeps drift about what you meant.

A short type table adds what the schema doesn't say: whether a type is stateful or identity-bearing, which runner it uses, how long it may take, and how its values compare.

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;
    }
}

Defaults and guardrails

Say it once, at the highest branch where it's true.

Defaults fill in what a resource leaves unset, and the nearest one wins. Guardrails say what must be true of everything beneath, and nothing beneath may weaken them. A conflict fails commit check and names the guardrail's path. There's no expression language, just a fixed set of forms.

namespace tidewater {
    guardrails {
        placement region in [ us-east-2 us-west-2 us-east-1 ];
        tags { owner required; data-classification required; }
        s3.bucket { bucket-encryption required; }
        logs.log-group { retention-in-days minimum 731; }
        lambda.function { architectures in [ arm64 ]; }
        rds.db-instance { destroy { deletion in [ retain snapshot ]; } }
    }
    defaults {
        tags { cost-center 4100; }
        logs.log-group { retention-in-days 731; }
    }
}

Where every value came from.

A value is resolved from the template, then defaults from the root down, then the resource's own statements, then fixed-value guardrails. show | display inheritance prints the tree with a note on every value that came from somewhere else.

Rolling out a new guardrail.

A new rule that half the estate breaks would stop every commit. So it starts as guardrails audit: same forms, but it never fails or changes anything, and each violation is listed as a finding. When the findings reach zero, a commit moves it into guardrails.

Promoting a change.

To take a new default to development first, set it nearer: the dev branch's default wins. Then promote moves it to the top and deletes the copies beneath, in one commit. Session 9 walks the whole rollout.

Templates

Bundles you apply, never copy.

A template is a named, versioned bundle: a Lambda with its role, encrypted log group, and alarms. It substitutes typed parameters and nothing else; a template that needs two shapes is two templates.

Versions use Terraform's constraint syntax: "1.2.3" exactly, "~> 1.0" for any 1.x. A range is resolved only at a commit that changes the namespace applying it, or on request with update templates, and the exact version and digest are recorded. Publishing a new version changes nothing by itself, and a rollback restores the versions it recorded.

namespace intake {
    apply gs-lambda {
        version "~> 1.3.0";
        memory 1024;
        code s3://tidewater-artifacts/lending/intake/2.4.1/bootstrap.zip;
        log-key @/tidewater/foundation/prod/kms.key/logs;
    }
}
jordan@tidewater# update templates
template  gs-lambda 1.3.0 -> 1.3.1 (newest within ~> 1.3.0)

References

The only way one resource depends on another.

@<path>:<attribute> points at another resource in the tree. References give order: a resource is created after what it references, and deleted before. There's no depends_on. A reference waits until its target is stable, except for an early attribute, such as the DNS record a certificate needs before it can be issued.

Lifecycle phases

Created, maintained, destroyed.

Every statement on a resource belongs to one phase. Where a value comes from (a default, a template) and how long it is held are separate questions, so they're written separately.

Create · create { }

Set once, then let go.

Applied when the resource is created or replaced, never compared again. For what AWS owns afterwards: a desired count under auto scaling, storage under storage autoscaling.

Maintain · ordinary statements

Held for life.

The default. Compared with AWS and remediated when it drifts.

Destroy · destroy { }

What deletion means.

Retain, snapshot, delete, or evict, and the values deletion needs: a final snapshot's name, a key's waiting period.

resource rds.db-instance main {
    engine postgres;
    engine-version 17;                     held; AWS may apply minor versions
    manage-master-user-password true;      the password never enters the tree
    create  { allocated-storage 200; }
    destroy { deletion snapshot; final-snapshot-identifier lending-main-final; }
}

Sources

One writer per branch.

Every namespace has exactly one source: the control plane, where people edit it in sessions, or one file on one branch of one Git repository, changed only by pull request. The parent declares it, so a file can never declare its own source away.

Two writers would each hold a copy of what should be true, and whichever wrote last would quietly undo the other. With one per branch there's nothing to merge back. Git loads only move forward, and commit covers what that means for review and rollback.

namespace lending {
    source prod {
        git https://github.com/tidewater/infrastructure;
        branch main;
        file lending/prod.conf;
    }
    namespace prod { ... }
}
jordan@tidewater# set resource s3.bucket documents ...
error: /tidewater/lending/prod is sourced from Git (CTL-052)
       change it by pull request

The rules

Tree, placement, resources, inheritance, templates, references.

Tree

  1. CTL-001

    A namespace name is lower-case letters, digits, and hyphens, starts with a letter, is at most 40 characters, and never contains a dot.

  2. CTL-002

    A control plane has exactly one tree, and every managed resource has exactly one path in it.

  3. CTL-003

    The company names the top of the tree; the fixed vocabulary (placement, defaults, guardrails, binding, policy, access, source, templates, template, apply, resource, namespace) appears only inside a namespace.

  4. CTL-004

    A namespace's behavior comes only from its statements and those it inherits, never from its name.

  5. CTL-005

    A namespace holds only namespaces, resources, and the fixed vocabulary, and an empty namespace is removed at commit.

  6. CTL-006

    Moving or renaming a namespace never replaces a resource beneath it; only the gravity-path tag changes.

Placement

  1. CTL-007

    organization, account, region, and zone are inherited down the tree until a namespace or resource sets them again.

  2. CTL-008

    A resource's placement resolves to everything its type's scope needs (global, regional, zonal, or organization), or commit check fails.

  3. CTL-009

    A zone is always written as an Availability Zone ID, never a zone name.

Resources and types

  1. CTL-010

    A resource type is a CloudFormation registry type, written as its derived alias, and its property names and attribute names are derived mechanically from its schema.

  2. CTL-011

    Only properties stated on the resource or supplied by a default, guardrail, or template are managed, down to sub-properties inside nested blocks, and only managed properties can drift.

  3. CTL-066

    A statement on a resource belongs to one phase: inside create it is applied only when the resource is created or replaced and never compared afterwards; outside any phase block it is maintained and held; inside destroy it is used only when the resource is deleted. create may appear on a resource, in a template, or in defaults, never in guardrails or for a property a guardrail above names.

  4. CTL-067

    Configured and observed values are compared only after the normaliser the type table names for the property, chosen from a fixed, published set.

  5. CTL-068

    A secret reaches AWS only by reference to a secret store, read at the moment of the call, and never appears in the tree, the store, a Git source or export, a plan, or a log.

  6. CTL-069

    A write-only property is compared with a hash of what the control plane last sent, and is sent again only when its configured value or its secret's version changes.

  7. CTL-070

    Destroy values are never compared and never cause an update; a resource's destroy block overrides its namespace's deletion policy, guardrails may restrict it, and a deletion follows the destroy block in the last commit that held the resource.

  8. CTL-071

    A create-only property whose value is inherited from a default or a template applies only to resources created after it; changing it never replaces an existing resource.

Defaults and guardrails

  1. CTL-012

    A default applies only where nothing nearer has set the property.

  2. CTL-013

    A value is resolved from the template body, then defaults from the root down, then the resource's own statements, then fixed-value guardrails, and the source of every resolved value can be shown.

  3. CTL-014

    Nothing beneath a guardrail may weaken it, and a conflict with a guardrail fails commit check and names the guardrail's path.

  4. CTL-015

    Every taggable managed resource carries managed-by gravity-keep and gravity-path <namespace path>, and neither can be overridden.

  5. CTL-016

    A boundary that must hold even for calls made outside Gravity Keep is also expressed as an AWS Organizations policy in the tree.

  6. CTL-072

    An audit guardrail never fails a commit and never changes a resource; each violation is a finding, and it becomes a guardrail only by a commit.

Templates

  1. CTL-017

    A template is referenced by name and a version constraint in Terraform's syntax, never copied into the tree.

  2. CTL-018

    A template substitutes declared, typed parameters and has no loops, conditionals, or functions.

  3. CTL-019

    A template's resources appear at ordinary paths in the namespace that applies it, and which template supplied each one can be shown.

  4. CTL-065

    A version constraint is resolved only by a commit that changes the namespace applying it, or by update templates, to the newest matching version; the commit records each resolved version and digest, rollback and request revert restore the recorded versions without resolving again, and a version whose digest has changed fails commit check.

References

  1. CTL-020

    A reference resolves to a resource in the tree, references are the only way to express a dependency, and a cycle fails commit check.

  2. CTL-063

    A reference waits until the resource it references is stable, except a reference to an attribute the type table marks early, which waits only until that value is known; list entries are referenced by key, never by position.