PCL binding#
Binding is the process of verifying the structure of a PCL program’s abstract syntax tree (AST) (checking that it contains blocks describing resources, outputs, and so on) before associating it with (or “binding it to”) a set of Pulumi schema, in the process checking and resolving references between parts (“nodes”) of the program and using this information to type check the program’s expressions. For instance, given the AST for a PCL program such as the following:
resource "r" "random:index:RandomString" {
length = 8
}
output "o" {
value = r.result
}
the binding process would encompass the following tasks:
Walking the tree to ensure that all its blocks are valid nodes in a PCL program. In this case, the program contains two nodes: a
resourcenode and anoutputnode. As part of this, the generic notions of e.g. labels are refined to have semantic meaning:In the case of a
resourceblock, for instance, the labels (hererandrandom:index:RandomString) are interpreted as giving the name and type of the resource being defined.In the case of an
outputblock, the label (hereo) is interpreted as giving the name of the output being exported.
Resolving the
randompackage (as referenced by therandom:index:RandomStringtype in therresource node) and loading its schema.Using the resolved schema to construct an object type comprising the
RandomStringresource’s input properties and using a scope containing this type to type check thelengthattribute.Adding a definition for
rto the top-level scope so that references torcan be type checked later on. This definition will refer to an object type comprising theRandomStringresource’s output properties, as resolved from the loaded schema.Type checking the
valueattribute of theoutputnode.
The output of binding is a bound program, which wraps the original AST-level program with the set of resolved nodes, which in turn reference semantic model expressions, and so on.