2.2 KiB
(pcl-binding)=
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
resource
node and anoutput
node. As part of this, the generic notions of e.g. labels are refined to have semantic meaning:- In the case of a
resource
block, for instance, the labels (herer
andrandom:index:RandomString
) are interpreted as giving the name and type of the resource being defined. - In the case of an
output
block, the label (hereo
) is interpreted as giving the name of the output being exported.
- In the case of a
-
Resolving the
random
package (as referenced by therandom:index:RandomString
type in ther
resource node) and loading its schema. -
Using the resolved schema to construct an object type comprising the
RandomString
resource's input properties and using a scope containing this type to type check thelength
attribute. -
Adding a definition for
r
to the top-level scope so that references tor
can be type checked later on. This definition will refer to an object type comprising theRandomString
resource's output properties, as resolved from the loaded schema. -
Type checking the
value
attribute of theoutput
node.
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.