Skip to main content
ubx supports 10 types of conditional expressions. All types propagate Pending<T> — any expression involving a ~ reference becomes Pending<T> and defers to apply time via .apply().

Type 1 — ?? Null Coalescing

Returns the left operand if non-null/non-empty; otherwise the right.
unit "aws_s3_bucket_v2" "b" {
  bucket = input.custom_name ?? "default-bucket"
}
bucket: (customName ?? "default-bucket"),

Type 2 — Ternary ? :

Classic conditional expression.
unit "aws_rds_instance" "db" {
  instance_class = input.env == "prod" ? "db.r6g.xlarge" : "db.t3.micro"
}
instanceClass: (env === "prod") ? "db.r6g.xlarge" : "db.t3.micro",

Type 3 — when Block Modifier

Conditionally creates an entire resource block.
input "enable_cache" { default = "true" }

unit "aws_elasticache_replication_group" "cache" {
  when                  = input.enable_cache == "true"
  replication_group_id  = "my-cache"
  num_cache_clusters    = 1
}
The resource is only included in the plan when the condition is true.

Type 4 — when on output Blocks

output "replica_endpoint" {
  value = ~unit.aws_rds_instance.replica.endpoint
  when  = input.env == "prod"
}
Compiles to a ternary:
export const replica_endpoint = ((env === "prod"))
  ? replica.endpoint
  : pulumi.output(undefined);

Type 5 — && and || in Conditions

unit "aws_s3_bucket_v2" "logs" {
  when   = input.env == "prod" && input.enable_logs == "true"
  bucket = "prod-logs"
}

Type 6 — Comparison Operators

instance_class = input.node_count > 3 ? "db.r6g.xlarge" : "db.t3.micro"
Supported: ==, !=, >, <, >=, <=

Type 7 — ! Negation

unit "aws_s3_bucket_v2" "dev_bucket" {
  when   = !(input.env == "prod")
  bucket = "dev-assets"
}

Type 8 — Nested Ternary

instance_class = input.env == "prod"
  ? "db.r6g.xlarge"
  : input.env == "staging"
    ? "db.t3.small"
    : "db.t3.micro"

Type 9 — Pending&lt;T&gt; in Condition

When a condition contains a Pending&lt;T&gt; value, the result is Pending&lt;T&gt; and resolves at apply time:
unit "aws_s3_bucket_v2" "replica" {
  bucket = ~unit.aws_s3_bucket_v2.primary.bucket ?? "fallback-bucket"
}
bucket: primary.bucket.apply(b => b ?? "fallback-bucket"),

Type 10 — ?? in String Interpolation

unit "aws_s3_bucket_v2" "b" {
  bucket = "${input.prefix ?? "default"}-assets"
}
bucket: `${(prefix ?? "default")}-assets`,