Documentation
¶
Overview ¶
nolint: goconst
Index ¶
- Constants
- Variables
- func AllowMissingProperties(options *bindOptions)
- func AllowMissingVariables(options *bindOptions)
- func AnnotateAttributeValue(expr model.Expression, attributeType schema.Type) model.Expression
- func AnnotateResourceInputs(node *Resource)
- func DecomposeToken(tok string, sourceRange hcl.Range) (string, string, string, hcl.Diagnostics)
- func EnumMember(t *model.EnumType, value cty.Value) (*schema.Enum, bool)
- func FixupPulumiPackageTokens(r *Resource)
- func GenEnum(t *model.EnumType, from model.Expression, safeEnum func(member *schema.Enum), ...)
- func GetDiscriminatedUnionObjectMapping(t *model.UnionType) map[string]model.Type
- func GetSchemaForType(t model.Type) (schema.Type, bool)
- func IsOutputVersionInvokeCall(call *model.FunctionCallExpression) bool
- func LowerConversion(from model.Expression, to model.Type) model.Type
- func MapProvidersAsResources(p *Program)
- 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 RecognizeOutputVersionedInvoke(expr *model.FunctionCallExpression) (bool, *model.ObjectConsExpression, model.Type)
- func RecognizeTypedObjectCons(theExpr model.Expression) (bool, *model.ObjectConsExpression, 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, hcl.Diagnostics)
- func RewritePropertyReferences(expr model.Expression) model.Expression
- func SkipResourceTypechecking(options *bindOptions)
- 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) LogicalName() string
- 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) LogicalName() string
- 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 PackageInfo
- type Program
- func (p *Program) BindExpression(node hclsyntax.Node) (model.Expression, hcl.Diagnostics)
- func (p *Program) NewDiagnosticWriter(w io.Writer, width uint, color bool) hcl.DiagnosticWriter
- func (p *Program) PackageReferences() []schema.PackageReference
- func (p *Program) PackageSnapshots() ([]*schema.Package, error)
- func (p *Program) Packages() []*schema.Package
- type Resource
- func (r *Resource) DecomposeToken() (string, string, string, hcl.Diagnostics)
- func (r *Resource) LogicalName() string
- func (r *Resource) Name() stringdeprecated
- 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" )
const Invoke = "invoke"
const LogicalNamePropertyKey = "__logicalName"
Variables ¶
var ( // ArchiveType represents the set of Pulumi Archive values. ArchiveType model.Type = model.NewOpaqueType("Archive") // AssetType represents the set of Pulumi Asset values. AssetType model.Type = model.NewOpaqueType("Asset") // ResourcePropertyType represents a resource property reference. ResourcePropertyType model.Type = model.NewOpaqueType("Property") // AssetOrArchiveType represents the set of Pulumi Archive values. AssetOrArchiveType model.Type = model.NewUnionType(ArchiveType, AssetType) )
Functions ¶
func AllowMissingProperties ¶
func AllowMissingProperties(options *bindOptions)
func AllowMissingVariables ¶
func AllowMissingVariables(options *bindOptions)
func AnnotateAttributeValue ¶ added in v3.43.0
func AnnotateAttributeValue(expr model.Expression, attributeType schema.Type) model.Expression
func AnnotateResourceInputs ¶ added in v3.43.0
func AnnotateResourceInputs(node *Resource)
func DecomposeToken ¶
func EnumMember ¶ added in v3.30.0
EnumMember returns the name of the member that matches the given `value`. If no member if found, (nil, true) returned. If the query is nonsensical, either because no schema is associated with the EnumMember or if the type of value mismatches the type of the schema, (nil, false) is returned.
func FixupPulumiPackageTokens ¶ added in v3.39.0
func FixupPulumiPackageTokens(r *Resource)
func GenEnum ¶ added in v3.30.0
func GenEnum( t *model.EnumType, from model.Expression, safeEnum func(member *schema.Enum), unsafeEnum func(from model.Expression), )
GenEnum is a helper function when generating an enum. Given an enum, and instructions on what to do when you find a known value, and an unknown value, return a function that will generate an the given enum from the given expression.
This function should probably live in the `codegen` namespace, but cannot because of import cycles.
func GetDiscriminatedUnionObjectMapping ¶
GetDiscriminatedUnionObjectMapping calculates a map of type names to object types for a given union type.
func GetSchemaForType ¶
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 IsOutputVersionInvokeCall ¶ added in v3.18.0
func IsOutputVersionInvokeCall(call *model.FunctionCallExpression) bool
Detects invoke calls that use an output version of a function.
func LowerConversion ¶ added in v3.30.0
LowerConversion lowers a conversion for a specific value, such that converting `from` to a value of the returned type will produce valid code. The algorithm prioritizes safe conversions over unsafe conversions. If no conversion can be found, nil, false is returned.
This is useful because it cuts out conversion steps which the caller doesn't need to worry about. For example: Given inputs
from = string("foo") # a constant string with value "foo"
to = union(enum(string: "foo", "bar"), input(enum(string: "foo", "bar")), none)
We would receive output type:
enum(string: "foo", "bar")
since the caller can convert string("foo") to the enum directly, and does not need to consider the union.
For another example consider inputs:
from = var(string) # A variable of type string to = union(enum(string: "foo", "bar"), string)
We would return type:
string
since var(string) can be safely assigned to string, but unsafely assigned to enum(string: "foo", "bar").
func MapProvidersAsResources ¶ added in v3.37.0
func MapProvidersAsResources(p *Program)
Remaps the "pulumi:providers:$Package" token style to "$Package:index:Provider", consistent with code generation. This mapping is consistent with how provider resources are projected into the schema and removes special casing logic to generate registering explicit providers.
The resultant program should be a shallow copy of the source with only the modified resource nodes copied.
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 ¶
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 ¶
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 RecognizeOutputVersionedInvoke ¶ added in v3.18.0
func RecognizeOutputVersionedInvoke( expr *model.FunctionCallExpression, ) (bool, *model.ObjectConsExpression, model.Type)
Pattern matches to recognize an encoded call to an output-versioned invoke, such as `invoke(token, __convert(objCons(..)))`. If matching, returns the `args` expression and its schema-bound type.
func RecognizeTypedObjectCons ¶ added in v3.18.0
func RecognizeTypedObjectCons(theExpr model.Expression) (bool, *model.ObjectConsExpression, model.Type)
Pattern matches to recognize `__convert(objCons(..))` pattern that is used to annotate object constructors with appropriate nominal types. If the expression matches, returns true followed by the constructor expression and the appropriate type.
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 ¶
func RewriteConversions(x model.Expression, to model.Type) (model.Expression, hcl.Diagnostics)
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 ¶
func RewritePropertyReferences(expr model.Expression) model.Expression
func SkipResourceTypechecking ¶
func SkipResourceTypechecking(options *bindOptions)
Types ¶
type BindOption ¶
type BindOption func(*bindOptions)
func Cache ¶
func Cache(cache *PackageCache) BindOption
func Loader ¶
func Loader(loader schema.Loader) BindOption
func PluginHost ¶
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 ¶
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) LogicalName ¶ added in v3.31.0
func (lv *LocalVariable) LogicalName() string
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 ¶
func (lv *LocalVariable) VisitExpressions(pre, post model.ExpressionVisitor) hcl.Diagnostics
type Node ¶
type Node interface {
model.Definition
// Name returns the lexical 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) LogicalName ¶ added in v3.31.0
func (ov *OutputVariable) LogicalName() string
Returns the ID of the output, if the output has an ID it is returned surrounded by double quotes, otherwise the defaultValue is returned as is.
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 ¶
func (ov *OutputVariable) VisitExpressions(pre, post model.ExpressionVisitor) hcl.Diagnostics
type PackageCache ¶
type PackageCache struct {
// contains filtered or unexported fields
}
func NewPackageCache ¶
func NewPackageCache() *PackageCache
type PackageInfo ¶ added in v3.40.2
type PackageInfo struct {
// contains filtered or unexported fields
}
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.
func (*Program) PackageReferences ¶ added in v3.33.2
func (p *Program) PackageReferences() []schema.PackageReference
PackageReferences returns the list of package referenced used by this program.
func (*Program) PackageSnapshots ¶ added in v3.33.2
PackageSnapshots returns the list of packages schemas used by this program. If a referenced package is partial, its returned value is a snapshot that contains only the package members referenced by the program. Otherwise, its returned value is the full package definition.
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) LogicalName ¶ added in v3.31.0
Returns the unique name of the resource; if the resource has an unique name it is formatted with the format string and returned, otherwise the defaultValue is returned as is.
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 ¶
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
// The version of the provider for this resource.
Version model.Expression
// The plugin download URL for this resource.
PluginDownloadURL 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