cost_limit on component blocks — constraining the total cost of a component abstraction. The same attribute works on individual unit blocks, giving you per-resource cost governance without needing to wrap resources in components. A multi-AZ RDS instance with cost_limit = 200 will block ubx apply if the AI estimates it will cost more than $200/month. A Lambda function with cost_limit = 20 catches the mistake of accidentally setting a very high memory allocation. Like the component variant, the limit is only enforced when ubx plan --cost is run with UBX_AI_API_KEY set — plain ubx validate always passes, ensuring cost governance doesn’t break CI pipelines that don’t have AI configured.
What you’ll learn
- How
cost_limiton aunitblock enforces a per-resource spend ceiling - The three-tier behaviour: validate (always passes), plan (warns), apply (blocks)
- How to set different limits for different resource tiers
Why this matters
Per-resource
cost_limit is infrastructure budgeting at the source level. A cost_limit = 200 on an RDS instance communicates the expected cost envelope to every engineer who reads the .iac file — and enforces it automatically when AI evaluation is enabled.The source code
How it works
cost_limit is parsed and stored as resource metadata
cost_limit = 200.00 is recorded on the IRUnit node as a metadata field. It doesn’t appear in the generated Pulumi code — it’s a ubx-level constraint only.ubx plan --cost evaluates each resource against its limit
With
UBX_AI_API_KEY set, ubx plan --cost asks the AI to estimate the monthly cost of each resource that has a cost_limit. The estimate is compared to the limit and shown in the plan output with a pass/warn/fail indicator.Behaviour by command
| Command | cost_limit behaviour |
|---|---|
ubx validate | Parsed, stored as metadata — never evaluated, always passes |
ubx plan | Parsed, stored — no AI call, no evaluation |
ubx plan --cost | AI evaluates each resource, warns if cost_limit exceeded |
ubx apply | Blocked if a prior --cost check found any limit exceeded |
ubx apply (no prior cost check) | Runs normally — no cost enforcement without --cost |
Common mistakes
Run it
What you learned
cost_limit on a unit block sets a per-resource monthly spend ceilingWithout
--cost, cost_limit is metadata only — ubx validate always passesubx apply is blocked if a prior --cost check found any limit exceededNext steps
Security scan
Enforce security rules at validate time
AI plan summary
Plain-English plan summaries and cost estimates
Full runnable example: github.com/ubiquex/ubx-examples/49-cost-limit-constraint

