hcl2

package
v1.14.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

nolint: goconst

Index

Constants

View Source
const (
	// IntrinsicApply is the name of the apply intrinsic.
	IntrinsicApply = "__apply"
)

Variables

View Source
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")
	// ResourceType represents a Pulumi resource instance.
	ResourceType model.Type = model.MustNewOpaqueType("Resource")
	// ResourcePropertyType represents a resource property reference.
	ResourcePropertyType model.Type = model.MustNewOpaqueType("Property")
)

Functions

func DecomposeToken

func DecomposeToken(tok string, sourceRange hcl.Range) (string, string, string, hcl.Diagnostics)

func NewApplyCall

NewApplyCall returns a new expression that represents a call to IntrinsicApply.

func ParseApplyCall

ParseApplyCall extracts the apply arguments and the continuation from a call to the apply intrinsic.

func RewriteApplies

func RewriteApplies(expr model.Expression, nameInfo NameInfo, applyPromises bool) (model.Expression, hcl.Diagnostics)

RewriteApplies transforms all bound expression trees in the given Expression that reference output-typed properties into appropriate calls to the __apply and __applyArg intrinsic. Given an expression tree, the rewrite proceeds as follows: - let the list of outputs be an empty list - for each node in post-order:

  • if the node is the root of the expression tree:
  • if the node is a variable access:
  • if the access has an output-typed element on its path, replace the variable access with a call to the __applyArg intrinsic and append the access to the list of outputs.
  • otherwise, the access does not need to be transformed; return it as-is.
  • if the list of outputs is empty, the root does not need to be transformed; return it as-is.
  • otherwise, replace the root with a call to the __apply intrinstic. The first n arguments to this call are the elementss of the list of outputs. The final argument is the original root node.
  • otherwise, if the root is an output-typed variable access, replace the variable access with a call to the __applyArg instrinsic and append the access to the list of outputs.

As an example, this transforms the following expression:

(output string
    "#!/bin/bash -xe\n\nCA_CERTIFICATE_DIRECTORY=/etc/kubernetes/pki\necho \""
    (aws_eks_cluster.demo.certificate_authority.0.data output<unknown> *config.ResourceVariable)
    "\" | base64 -d >  $CA_CERTIFICATE_FILE_PATH\nsed -i s,MASTER_ENDPOINT,"
    (aws_eks_cluster.demo.endpoint output<string> *config.ResourceVariable)
    ",g /var/lib/kubelet/kubeconfig\nsed -i s,CLUSTER_NAME,"
    (var.cluster-name string *config.UserVariable)
    ",g /var/lib/kubelet/kubeconfig\nsed -i s,REGION,"
    (data.aws_region.current.name output<string> *config.ResourceVariable)
    ",g /etc/systemd/system/kubelet.servicesed -i s,MASTER_ENDPOINT,"
    (aws_eks_cluster.demo.endpoint output<string> *config.ResourceVariable)
    ",g /etc/systemd/system/kubelet.service"
)

into this expression:

(call output<unknown> __apply
    (aws_eks_cluster.demo.certificate_authority.0.data output<unknown> *config.ResourceVariable)
    (aws_eks_cluster.demo.endpoint output<string> *config.ResourceVariable)
    (data.aws_region.current.name output<string> *config.ResourceVariable)
    (aws_eks_cluster.demo.endpoint output<string> *config.ResourceVariable)
    (output string
        "#!/bin/bash -xe\n\nCA_CERTIFICATE_DIRECTORY=/etc/kubernetes/pki\necho \""
        (call unknown __applyArg
            0
        )
        "\" | base64 -d >  $CA_CERTIFICATE_FILE_PATH\nsed -i s,MASTER_ENDPOINT,"
        (call string __applyArg
            1
        )
        ",g /var/lib/kubelet/kubeconfig\nsed -i s,CLUSTER_NAME,"
        (var.cluster-name string *config.UserVariable)
        ",g /var/lib/kubelet/kubeconfig\nsed -i s,REGION,"
        (call string __applyArg
            2
        )
        ",g /etc/systemd/system/kubelet.servicesed -i s,MASTER_ENDPOINT,"
        (call string __applyArg
            3
        )
        ",g /etc/systemd/system/kubelet.service"
    )
)

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).

Types

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 syntax node for the config variable.
	Syntax *hclsyntax.Block

	// The name of the config variable.
	VariableName string
	// 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.

type LocalVariable

type LocalVariable struct {

	// The syntax node associated with the local variable, if any.
	Syntax *hclsyntax.Attribute
	// The syntax tokens associated with the local variable, if any.
	Tokens *syntax.AttributeTokens

	// The name of the local variable.
	VariableName string
	// The type of the local variable.
	VariableType model.Type
	// The value of the local variable.
	Value model.Expression
	// 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.

type NameInfo

type NameInfo interface {
	IsReservedWord(name string) bool
}

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
	// 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

func Linearize(p *Program) []Node

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

func SourceOrderNodes(nodes []Node) []Node

type OutputVariable

type OutputVariable struct {
	Syntax *hclsyntax.Block

	VariableName string
	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.

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, host plugin.Host) (*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

func (p *Program) NewDiagnosticWriter(w io.Writer, width uint, color bool) hcl.DiagnosticWriter

NewDiagnosticWriter creates a new hcl.DiagnosticWriter for use with diagnostics generated by the program.

type Resource

type Resource struct {

	// The syntax node associated with the resource instantiation.
	Syntax *hclsyntax.Block
	// The syntax tokens associated with the resource instantiation, if any.
	Tokens *syntax.BlockTokens

	// Token is the type token for this resource.
	Token string

	// 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 body of this resource.
	Body *model.Body

	// 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

func (r *Resource) DecomposeToken() (string, string, string, hcl.Diagnostics)

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) Name

func (r *Resource) Name() string

Name returns the name of the resource.

func (*Resource) SyntaxNode

func (r *Resource) SyntaxNode() hclsyntax.Node

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) Type

func (r *Resource) Type() model.Type

Type returns the type of the resource.

type ResourceOptions

type ResourceOptions struct {
	// The syntax node associated with the resource options.
	Syntax *hclsyntax.Block
	// The syntax tokens associated with the resource options, if any.
	Tokens *syntax.BlockTokens

	// An expression to range over when instantiating the resource.
	Range 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

type ResourceProperty struct {
	Path         hcl.Traversal
	PropertyType model.Type
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL