git:: source prefix tells ubx to clone the specified repository, check out the specified ref, and compile the .iac files at the specified subdirectory path as the component’s body. Pin to an immutable ref — a tag or a full SHA — and ubx caches the clone after the first resolution, making subsequent validates fast and offline-capable. Use a branch name and ubx re-clones on every validate, always reflecting the branch’s current state.
What you’ll learn
- The
git::URL syntax: clone URL, subdirectory path, and?ref=for pinning - How immutable refs (tags, SHAs) enable caching; mutable refs (branches) always re-clone
- How to self-reference the
ubx-examplesrepo for a self-contained example
Why this matters
git:: sources give you the benefits of a registry — versioned, external, independently-maintained components — without requiring a registry server. A ?ref=v1.2.0 pin is as reproducible as a registry version, and a public GitHub repository is as accessible as any npm package.The source code
How it works
ubx parses and validates the git:: URL at compile time
The URL format is validated during parsing — the
git:: prefix, the // subdirectory separator, and the ?ref= parameter are all checked syntactically. An invalid URL produces a compile error before any network request is made.The repository is cloned at validate time
When you run
ubx validate (or ubx plan/apply), ubx clones the repository to a local cache (~/.ubx/cache/git/), checks out the specified ref, and resolves the subdirectory path. The .iac files found there are compiled as the component’s body — identical to a local ./components/rds source.Immutable refs are cached; mutable refs always re-clone
A tag (
?ref=v1.2.0) or full SHA (?ref=abc123def) is immutable — once cloned, ubx uses the cache for all subsequent validates. A branch name (?ref=main) is mutable — ubx re-clones on every validate to pick up the latest commit. Use a tag or SHA for reproducible builds in CI.What ubx generates
Common mistakes
Run it
What you learned
git:: sources clone a repository and compile the .iac files at the specified subdirectoryImmutable refs (
?ref=v1.2.0, ?ref=<sha>) are cached; mutable refs (?ref=main) re-clone every timeThe generated code is identical to a local
.iac component — source type is transparent at codegenNext steps
Component cost limit
Enforce a monthly spend ceiling on a component
Registry component
Versioned components via the Strata registry
Full runnable example: github.com/ubiquex/ubx-examples/23-git-source-component

