Cross-File References
Show the whole prompt
Read https://intentius.io/chant/guide/cross-file-references/.
Find properties in this project that hard-code another resource's name, ARN or ID as a string, and replace each with an import of that resource and its attribute.
Run `npx chant build` and `npx chant lint` until both pass, fix any circular import they report, and open a pull request.
Never deploy to a real cloud account or shared environment (with `chant run`, `chant components` or a platform's own CLI), approve (a pull request review, `chant approve` or `chant run approve`), override a policy denial (`chant approve policy-override`), or merge; never cut or publish a release (`chant release cut --yes` or `chant release publish`), push or delete a `ci/*` tag (`chant ci tick` pushes them), or change the value of an existing flag; never touch `.chant/allowed_signers` or `chant/lifecycle`.Optional: hand this page to your coding agent
Read https://intentius.io/chant/guide/cross-file-references/.Find properties in this project that hard-code another resource's name, ARN or ID as a string, and replace each with an import of that resource and its attribute.Run `npx chant build` and `npx chant lint` until both pass, fix any circular import they report, and open a pull request.Never deploy to a real cloud account or shared environment (with `chant run`, `chant components` or a platform's own CLI), approve (a pull request review, `chant approve` or `chant run approve`), override a policy denial (`chant approve policy-override`), or merge; never cut or publish a release (`chant release cut --yes` or `chant release publish`), push or delete a `ci/*` tag (`chant ci tick` pushes them), or change the value of an existing flag; never touch `.chant/allowed_signers` or `chant/lifecycle`.Resources often depend on each other. A policy needs a storage resource’s ARN; a function needs a table’s name. chant uses standard TypeScript imports for cross-file references.
Direct Imports
Section titled “Direct Imports”Import a resource from another file and access its attributes:
import { Bucket, Sub, AWS, Ref } from "@intentius/chant-lexicon-aws";import { environment } from "./parameters";
export const dataBucket = new Bucket({ BucketName: Sub`${AWS.StackName}-${Ref(environment)}-data`, PublicAccessBlockConfiguration: { BlockPublicAcls: true, BlockPublicPolicy: true, IgnorePublicAcls: true, RestrictPublicBuckets: true, },});import { Role, ManagedPolicy } from "@intentius/chant-lexicon-aws";import { dataBucket } from "./cross-ref-storage";
export const accessRole = new Role({ AssumeRolePolicyDocument: { Version: "2012-10-17", Statement: [{ Effect: "Allow", Principal: { Service: "lambda.amazonaws.com" }, Action: "sts:AssumeRole", }], },});
export const readPolicy = new ManagedPolicy({ PolicyDocument: { Statement: [{ Effect: "Allow", Action: ["s3:GetObject"], Resource: dataBucket.Arn, }], }, Roles: [accessRole],});dataBucket.arn resolves to a symbolic cross-resource reference in the evaluated output. The evaluator traces the import back to the source file, identifies the resource type, and resolves the attribute through the lexicon’s attribute registry.
Build-Time Resolution
Section titled “Build-Time Resolution”Cross-file references are resolved at build time, not at runtime. This means:
- The evaluator follows imports to build the resource graph
- References to nonexistent resources produce a build error
- Circular dependencies between resources are detected and reported
Importing Patterns
Section titled “Importing Patterns”| Pattern | Example |
|---|---|
| Import a resource | import { dataBucket } from "./data-bucket" |
| Import shared config | import { encryptionDefault } from "./defaults" |
| Import from lexicon | import { Bucket, Sub, AWS } from "@intentius/chant-lexicon-aws" |
| Import from core | import { Composite, output } from "@intentius/chant" |
All imports use standard TypeScript import statements. The evaluator follows imports through the module graph and resolves each referenced binding to its definition.