Skip to main content
ubx handles multiple environments (staging, production, etc.) through extend blocks without duplicating stack definitions.

How It Works

  1. Write base resource definitions in main.iac (staging defaults)
  2. Write environment-specific overrides in envs/<env>/overrides.iac using extend blocks
  3. Deploy with ubx apply --env <env>

File Layout

project/
  main.iac              # base definitions
  ubx.yaml
  envs/
    staging/
      overrides.iac     # staging-specific overrides
    prod/
      overrides.iac     # production overrides
    eu/
      overrides.iac     # region-specific overrides

extend Block Syntax

# envs/prod/overrides.iac
extend "unit" "aws_rds_instance" "db" {
  instance_class    = "db.r6g.2xlarge"
  allocated_storage = 100
  multi_az          = true
}
Only the overridden attributes change — all other attributes inherit from the base.

The --env Flag

ubx plan --env staging     # preview staging
ubx plan --env prod        # preview production
ubx apply --env prod       # deploy to production
The --env flag tells ubx which envs/<env>/ folder to load overrides from.

Default Environment

# ubx.yaml
defaultEnv: staging
When --env is omitted, defaultEnv is used.

Environment in Resources

Use input.env to inject the environment name into resource configurations:
input "env" {
  type    = "string"
  default = "staging"
}

unit "aws_s3_bucket_v2" "assets" {
  bucket = "${input.env}-assets"
}
ubx apply --env prod     # bucket = "prod-assets"
ubx apply --env staging  # bucket = "staging-assets"