prevent_destroy and a final snapshot. The naive approach is to duplicate the entire stack per environment. The Terraform approach is a maze of terraform.workspace conditionals and variable files. ubx’s answer is the extend block: a targeted, named override that changes specific attributes for a specific environment, leaving everything else inherited from the base. You write your resource once in main.iac, then write a small envs/prod/overrides.iac that overrides only what changes. The compiler merges them at apply time. Your base stays DRY, your environment differences are explicit, and there’s no branching or duplication.
What you’ll learn
- How
extendblocks override specific attributes of an existing resource - How environment override files are structured and loaded with
--env - What the compiler merges and what it inherits
Why this matters
extend is targeted and named — it overrides a specific resource by type and label, not the whole file. If a main.iac has ten resources and only one needs a prod override, you write one extend block. The other nine are inherited unchanged.The source code
How it works
The merger loads the base and the override
When you run
ubx plan --env prod, the compiler’s merger stage loads main.iac (the base) and envs/prod/overrides.iac (the override). It processes all .iac files in the envs/<env>/ directory alongside the base files.extend merges attribute-by-attribute
The
extend "unit" "aws_rds_instance" "db" block targets the base resource by type and label. Each attribute in the extend block overrides the corresponding attribute in the base. Attributes present in the base but absent from the extend are inherited unchanged — engine, username, tags, and identifier are untouched in prod.What ubx generates
Common mistakes
Run it
What you learned
extend overrides specific attributes of a named resource without touching anything elseEnvironment override files live in
envs/<env>/ and are loaded with --envThe compiler merges base + override before type-checking — the generated code contains the merged result
Next steps
Secret function
Pull sensitive values at apply time from any secrets backend
extend block reference
Full extend block syntax and merge rules
Full runnable example: github.com/ubiquex/ubx-examples/13-multi-environment-extend

