Documentation ¶
Overview ¶
nolint: goconst
Index ¶
- Constants
- Variables
- func AllowMissingVariables(options *bindOptions)
- func DecomposeToken(tok string, sourceRange hcl.Range) (string, string, string, hcl.Diagnostics)
- func GetSchemaForType(t model.Type) (schema.Type, bool)
- func NewApplyCall(args []model.Expression, then *model.AnonymousFunctionExpression) *model.FunctionCallExpression
- func NewConvertCall(from model.Expression, to model.Type) *model.FunctionCallExpression
- func ParseApplyCall(c *model.FunctionCallExpression) (applyArgs []model.Expression, then *model.AnonymousFunctionExpression)
- func ParseConvertCall(c *model.FunctionCallExpression) (model.Expression, model.Type)
- func RewriteApplies(expr model.Expression, nameInfo NameInfo, applyPromises bool) (model.Expression, hcl.Diagnostics)
- func RewriteConversions(x model.Expression, to model.Type) model.Expression
- func RewritePropertyReferences(expr model.Expression) model.Expression
- type BindOption
- type Component
- type ConfigVariable
- func (cv *ConfigVariable) Name() string
- func (cv *ConfigVariable) SyntaxNode() hclsyntax.Node
- func (cv *ConfigVariable) Traverse(traverser hcl.Traverser) (model.Traversable, hcl.Diagnostics)
- func (cv *ConfigVariable) Type() model.Type
- func (cv *ConfigVariable) VisitExpressions(pre, post model.ExpressionVisitor) hcl.Diagnostics
- type LocalVariable
- func (lv *LocalVariable) Name() string
- func (lv *LocalVariable) SyntaxNode() hclsyntax.Node
- func (lv *LocalVariable) Traverse(traverser hcl.Traverser) (model.Traversable, hcl.Diagnostics)
- func (lv *LocalVariable) Type() model.Type
- func (lv *LocalVariable) VisitExpressions(pre, post model.ExpressionVisitor) hcl.Diagnostics
- type NameInfo
- type Node
- type OutputVariable
- func (ov *OutputVariable) Name() string
- func (ov *OutputVariable) SyntaxNode() hclsyntax.Node
- func (ov *OutputVariable) Traverse(traverser hcl.Traverser) (model.Traversable, hcl.Diagnostics)
- func (ov *OutputVariable) Type() model.Type
- func (ov *OutputVariable) VisitExpressions(pre, post model.ExpressionVisitor) hcl.Diagnostics
- type PackageCache
- type Program
- type Resource
- func (r *Resource) DecomposeToken() (string, string, string, hcl.Diagnostics)
- func (r *Resource) Name() string
- func (r *Resource) SyntaxNode() hclsyntax.Node
- func (r *Resource) Traverse(traverser hcl.Traverser) (model.Traversable, hcl.Diagnostics)
- func (r *Resource) Type() model.Type
- func (r *Resource) VisitExpressions(pre, post model.ExpressionVisitor) hcl.Diagnostics
- type ResourceOptions
- type ResourceProperty
Constants ¶
const ( // IntrinsicApply is the name of the apply intrinsic. IntrinsicApply = "__apply" // IntrinsicConvert is the name of the conversion intrinsic. IntrinsicConvert = "__convert" // IntrinsicInput is the name of the input intrinsic. IntrinsicInput = "__input" )
const Invoke = "invoke"
Variables ¶
var ( // ArchiveType represents the set of Pulumi Archive values. ArchiveType model.Type = model.MustNewOpaqueType("Archive") // AssetType represents the set of Pulumi Asset values. AssetType model.Type = model.MustNewOpaqueType("Asset") // ResourcePropertyType represents a resource property reference. ResourcePropertyType model.Type = model.MustNewOpaqueType("Property") )
Functions ¶
func AllowMissingVariables ¶ added in v2.2.0
func AllowMissingVariables(options *bindOptions)
func DecomposeToken ¶
func GetSchemaForType ¶ added in v2.2.0
GetSchemaForType extracts the schema.Type associated with a model.Type, if any.
The result may be a *schema.UnionType if multiple schema types are associated with the input type.
func NewApplyCall ¶
func NewApplyCall(args []model.Expression, then *model.AnonymousFunctionExpression) *model.FunctionCallExpression
NewApplyCall returns a new expression that represents a call to IntrinsicApply.
func NewConvertCall ¶ added in v2.2.0
func NewConvertCall(from model.Expression, to model.Type) *model.FunctionCallExpression
NewConvertCall returns a new expression that represents a call to IntrinsicConvert.
func ParseApplyCall ¶
func ParseApplyCall(c *model.FunctionCallExpression) (applyArgs []model.Expression, then *model.AnonymousFunctionExpression)
ParseApplyCall extracts the apply arguments and the continuation from a call to the apply intrinsic.
func ParseConvertCall ¶ added in v2.2.0
func ParseConvertCall(c *model.FunctionCallExpression) (model.Expression, model.Type)
ParseConvertCall extracts the value being converted and the type it is being converted to from a call to the convert intrinsic.
func RewriteApplies ¶
func RewriteApplies(expr model.Expression, nameInfo NameInfo, applyPromises bool) (model.Expression, hcl.Diagnostics)
RewriteApplies transforms all expressions that observe the resolved values of outputs and promises into calls to the __apply intrinsic. Expressions that generate or inspect outputs or promises are passed as arguments to these calls, and are replaced by references to the corresponding parameter.
As an example, assuming that resource.id is an output, this transforms the following expression:
toJSON({ Version = "2012-10-17" Statement = [{ Effect = "Allow" Principal = "*" Action = [ "s3:GetObject" ] Resource = [ "arn:aws:s3:::${resource.id}/*" ] }] })
into this expression:
__apply(resource.id, eval(id, toJSON({ Version = "2012-10-17" Statement = [{ Effect = "Allow" Principal = "*" Action = [ "s3:GetObject" ] Resource = [ "arn:aws:s3:::${id}/*" ] }] })))
Here is a more advanced example, assuming that resource is an object whose properties are all outputs, this expression:
"v: ${resource[resource.id]}"
is transformed into this expression:
__apply(__apply(resource.id,eval(id, resource[id])),eval(id, "v: ${id}"))
This form is amenable to code generation for targets that require that outputs are resolved before their values are accessible (e.g. Pulumi's JS/TS libraries).
func RewriteConversions ¶ added in v2.2.0
func RewriteConversions(x model.Expression, to model.Type) model.Expression
RewriteConversions wraps automatic conversions indicated by the HCL2 spec and conversions to schema-annotated types in calls to the __convert intrinsic.
Note that the result is a bit out of line with the HCL2 spec, as static conversions may happen earlier than they would at runtime. For example, consider the case of a tuple of strings that is being converted to a list of numbers:
[a, b, c]
Calling RewriteConversions on this expression with a destination type of list(number) would result in this IR:
[__convert(a), __convert(b), __convert(c)]
If any of these conversions fail, the evaluation of the tuple itself fails. The HCL2 evaluation semantics, however, would convert the tuple _after_ it has been evaluated. The IR that matches these semantics is
__convert([a, b, c])
This transform uses the former representation so that it can appropriately insert calls to `__convert` in the face of schema-annotated types. There is a reasonable argument to be made that RewriteConversions should not be responsible for propagating schema annotations, and that this pass should be split in two: one pass would insert conversions that match HCL2 evaluation semantics, and another would insert calls to some separate intrinsic in order to propagate schema information.
func RewritePropertyReferences ¶ added in v2.6.0
func RewritePropertyReferences(expr model.Expression) model.Expression
Types ¶
type BindOption ¶ added in v2.2.0
type BindOption func(*bindOptions)
func Cache ¶ added in v2.2.0
func Cache(cache *PackageCache) BindOption
func Loader ¶ added in v2.6.0
func Loader(loader schema.Loader) BindOption
func PluginHost ¶ added in v2.2.0
func PluginHost(host plugin.Host) BindOption
type Component ¶
type Component struct { Syntax *hclsyntax.Block InputTypes map[string]model.Type OutputTypes map[string]model.Type Children []*Resource Locals []*LocalVariable }
Component represents a component definition in a program.
TODO(pdg): implement
type ConfigVariable ¶
type ConfigVariable struct { // The variable definition. Definition *model.Block // The default value for the config variable, if any. DefaultValue model.Expression // contains filtered or unexported fields }
ConfigVariable represents a program- or component-scoped input variable. The value for a config variable may come from stack configuration or component inputs, respectively, and may have a default value.
func (*ConfigVariable) Name ¶
func (cv *ConfigVariable) Name() string
func (*ConfigVariable) SyntaxNode ¶
func (cv *ConfigVariable) SyntaxNode() hclsyntax.Node
SyntaxNode returns the syntax node associated with the config variable.
func (*ConfigVariable) Traverse ¶
func (cv *ConfigVariable) Traverse(traverser hcl.Traverser) (model.Traversable, hcl.Diagnostics)
func (*ConfigVariable) Type ¶
func (cv *ConfigVariable) Type() model.Type
Type returns the type of the config variable.
func (*ConfigVariable) VisitExpressions ¶ added in v2.1.0
func (cv *ConfigVariable) VisitExpressions(pre, post model.ExpressionVisitor) hcl.Diagnostics
type LocalVariable ¶
type LocalVariable struct { // The variable definition. Definition *model.Attribute // contains filtered or unexported fields }
LocalVariable represents a program- or component-scoped local variable.
func (*LocalVariable) Name ¶
func (lv *LocalVariable) Name() string
func (*LocalVariable) SyntaxNode ¶
func (lv *LocalVariable) SyntaxNode() hclsyntax.Node
SyntaxNode returns the syntax node associated with the local variable.
func (*LocalVariable) Traverse ¶
func (lv *LocalVariable) Traverse(traverser hcl.Traverser) (model.Traversable, hcl.Diagnostics)
func (*LocalVariable) Type ¶
func (lv *LocalVariable) Type() model.Type
Type returns the type of the local variable.
func (*LocalVariable) VisitExpressions ¶ added in v2.1.0
func (lv *LocalVariable) VisitExpressions(pre, post model.ExpressionVisitor) hcl.Diagnostics
type Node ¶
type Node interface { model.Definition // Name returns the name of the node. Name() string // Type returns the type of the node. Type() model.Type // VisitExpressions visits the expressions that make up the node's body. VisitExpressions(pre, post model.ExpressionVisitor) hcl.Diagnostics // contains filtered or unexported methods }
Node represents a single definition in a program or component. Nodes may be config, locals, resources, or outputs.
func Linearize ¶
Linearize performs a topological sort of the nodes in the program so that they can be processed by tools that need to see all of a node's dependencies before the node itself (e.g. a code generator for a programming language that requires variables to be defined before they can be referenced). The sort is stable, and nodes are kept in source order as much as possible.
func SourceOrderNodes ¶
type OutputVariable ¶
type OutputVariable struct { // The definition of the output. Definition *model.Block // The value of the output. Value model.Expression // contains filtered or unexported fields }
OutputVariable represents a program- or component-scoped output variable.
func (*OutputVariable) Name ¶
func (ov *OutputVariable) Name() string
func (*OutputVariable) SyntaxNode ¶
func (ov *OutputVariable) SyntaxNode() hclsyntax.Node
SyntaxNode returns the syntax node associated with the output variable.
func (*OutputVariable) Traverse ¶
func (ov *OutputVariable) Traverse(traverser hcl.Traverser) (model.Traversable, hcl.Diagnostics)
func (*OutputVariable) Type ¶
func (ov *OutputVariable) Type() model.Type
Type returns the type of the output variable.
func (*OutputVariable) VisitExpressions ¶ added in v2.1.0
func (ov *OutputVariable) VisitExpressions(pre, post model.ExpressionVisitor) hcl.Diagnostics
type PackageCache ¶ added in v2.2.0
type PackageCache struct {
// contains filtered or unexported fields
}
func NewPackageCache ¶ added in v2.2.0
func NewPackageCache() *PackageCache
type Program ¶
type Program struct { Nodes []Node // contains filtered or unexported fields }
Program represents a semantically-analyzed Pulumi HCL2 program.
func BindProgram ¶
func BindProgram(files []*syntax.File, opts ...BindOption) (*Program, hcl.Diagnostics, error)
BindProgram performs semantic analysis on the given set of HCL2 files that represent a single program. The given host, if any, is used for loading any resource plugins necessary to extract schema information.
func (*Program) BindExpression ¶
func (p *Program) BindExpression(node hclsyntax.Node) (model.Expression, hcl.Diagnostics)
BindExpression binds an HCL2 expression in the top-level context of the program.
func (*Program) NewDiagnosticWriter ¶
NewDiagnosticWriter creates a new hcl.DiagnosticWriter for use with diagnostics generated by the program.
type Resource ¶
type Resource struct { // The definition of the resource. Definition *model.Block // Token is the type token for this resource. Token string // Schema is the schema definition for this resource, if any. Schema *schema.Resource // The type of the resource's inputs. This will always be either Any or an object type. InputType model.Type // The type of the resource's outputs. This will always be either Any or an object type. OutputType model.Type // The type of the resource variable. VariableType model.Type // The resource's input attributes, in source order. Inputs []*model.Attribute // The resource's options, if any. Options *ResourceOptions // contains filtered or unexported fields }
Resource represents a resource instantiation inside of a program or component.
func (*Resource) DecomposeToken ¶
DecomposeToken attempts to decompose the resource's type token into its package, module, and type. If decomposition fails, a description of the failure is returned in the diagnostics.
func (*Resource) SyntaxNode ¶
SyntaxNode returns the syntax node associated with the resource.
func (*Resource) Traverse ¶
func (r *Resource) Traverse(traverser hcl.Traverser) (model.Traversable, hcl.Diagnostics)
func (*Resource) VisitExpressions ¶ added in v2.1.0
func (r *Resource) VisitExpressions(pre, post model.ExpressionVisitor) hcl.Diagnostics
type ResourceOptions ¶
type ResourceOptions struct { // The definition of the resource options. Definition *model.Block // An expression to range over when instantiating the resource. Range model.Expression // The resource's parent, if any. Parent model.Expression // The provider to use. Provider model.Expression // The explicit dependencies of the resource. DependsOn model.Expression // Whether or not the resource is protected. Protect model.Expression // A list of properties that are not considered when diffing the resource. IgnoreChanges model.Expression }
ResourceOptions represents a resource instantiation's options.
type ResourceProperty ¶
ResourceProperty represents a resource property.
func (*ResourceProperty) SyntaxNode ¶
func (*ResourceProperty) SyntaxNode() hclsyntax.Node
func (*ResourceProperty) Traverse ¶
func (p *ResourceProperty) Traverse(traverser hcl.Traverser) (model.Traversable, hcl.Diagnostics)
func (*ResourceProperty) Type ¶
func (p *ResourceProperty) Type() model.Type