stack block is the primary declaration in XCL. It contains resource bindings that become Pulumi resources when compiled.
Syntax
.xcl files. All stack blocks across all files in the directory are merged into a single compilation unit. The name label is for documentation only — the actual Pulumi project name is taken from the directory name.
Named resource binding
vpc is the binding name — used throughout the stack to reference this resource’s outputs (e.g., vpc.id).
The type path aws.ec2.Vpc maps directly to the Pulumi provider class. The provider segment (aws) determines which pulumi_aws package is imported.
Unnamed (fire-and-forget) resources
A resource without a binding name runs but its outputs cannot be referenced:For clause — iterating over a collection
for clause creates one resource per element of the collection. Inside the block, az (or whichever variable name you choose) refers to the current element. For maps, use the key-value form:
Count modifier — creating N identical resources
* N modifier (where N is any expression) is combined with a for clause. It specifies how many resources to create.
When clause — conditional resources
when condition must be a Resolved value — an input field or a locals value. It cannot reference resource outputs (which are Pending<T> and only known after apply).
Error if you use a resource output:
Referencing resource outputs
After a resource is declared, its outputs are available asresourceName.outputName:
when conditions.
Referencing for-resource outputs
When a resource is created with afor clause, referencing it produces a list:
[r.id for r in subnets].
Cross-stack references
Use@stackName.outputName to reference an output from a sibling stack:
Match and ternary in resource properties
Match expressions and ternary expressions are not allowed directly in resource properties. Move them to alocals block first:
conditional (if/else) expressions are not allowed in resource properties — move this expression into a locals block
Multiple stack blocks
A stack can be spread across files. Allstack "name" { ... } blocks in the directory are merged, and resource names must be unique across all files.
Error for duplicate resource names: "vpc" is already defined in stack.xcl:3 - remove one, or rename
