eval

package
v0.0.0-...-4add889 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectVariables

func DetectVariables(expr hcl.Expression) []hcl.Traversal

DetectVariables returns all of the traversals in the given expression that are not for named constants. The result is nil if there are no such traversals.

Types

type DynAccountAZs

type DynAccountAZs struct {
	// RegionName must be either a DynLiteral or a DynRef
	RegionName DynExpr

	SrcRange hcl.Range
	// contains filtered or unexported fields
}

DynAccountAZs returns a list of availability zones that are supported in the region where the CloudFormation template is being applied, for the AWS account that is applying the template.

type DynBase64

type DynBase64 struct {
	String DynExpr

	SrcRange hcl.Range
	// contains filtered or unexported fields
}

DynBase64 returns a base64-encoded version of a given string.

type DynEquals

type DynEquals struct {
	// A and B must both be either DynLiteral or DynRef.
	A, B DynExpr

	SrcRange hcl.Range
	// contains filtered or unexported fields
}

DynEquals is a boolean expression (to be used in named conditionals only) that returns true if the two given values are equal.

type DynExpr

type DynExpr interface {
	// contains filtered or unexported methods
}

DynExpr represents an expression that can be evaluated dynamically by CloudFormation when applying a template.

This type represents the subset of operations that we can encode as expressions into CloudFormation JSON for dynamic evaluation. DynExpr instances are produced by translating hclsyntax.Expression nodes that have analogs in the CloudFormation language.

type DynGetAttr

type DynGetAttr struct {
	LogicalID string
	Attrs     []DynExpr

	SrcRange hcl.Range
	// contains filtered or unexported fields
}

DynGetAttr represents an attribute exported by a particular resource.

type DynIf

type DynIf struct {
	ConditionName string
	If, Else      DynExpr

	SrcRange hcl.Range
	// contains filtered or unexported fields
}

DynIf returns one of two values depending on the result of a named condition defined in the template.

type DynIndex

type DynIndex struct {
	List DynExpr

	// Index may only be DynLiteral, DynRef or DynMappingLookup.
	Index DynExpr

	SrcRange hcl.Range
	// contains filtered or unexported fields
}

DynIndex looks up a single item from a list expression by its index.

type DynJoin

type DynJoin struct {
	Delimiter string
	Exprs     []DynExpr

	SrcRange hcl.Range
	// contains filtered or unexported fields
}

DynJoin joins several expressions together with a delimiter.

type DynLiteral

type DynLiteral struct {
	Value cty.Value

	SrcRange hcl.Range
	// contains filtered or unexported fields
}

DynLiteral represents a literal value within our dynamic expression intermediate language.

The name is of course a bit of a misnomer since a literal can't be dynamic, but this type allows dynamic expressions to make use of literals.

type DynLogical

type DynLogical struct {
	Op     DynLogicalOp
	Values []DynExpr

	SrcRange hcl.Range
	// contains filtered or unexported fields
}

DynLogical is a boolean expression (to be used in named conditionals only) that performs the logical AND or OR operation on a number of other boolean expressions.

type DynLogicalOp

type DynLogicalOp rune
const (
	DynLogicalAnd DynLogicalOp = '&'
	DynLogicalOr  DynLogicalOp = '|'
)

func (DynLogicalOp) String

func (i DynLogicalOp) String() string

type DynMappingLookup

type DynMappingLookup struct {
	MappingName string

	// FirstKey and SecondKey may only use DynLiteral, DynRef, and nested DynMappingLookup.
	FirstKey, SecondKey DynExpr

	SrcRange hcl.Range
	// contains filtered or unexported fields
}

DynMappingLookup looks up a value from a named mapping table defined within the template.

type DynNot

type DynNot struct {
	Value DynExpr

	SrcRange hcl.Range
	// contains filtered or unexported fields
}

DynNot is a boolean expression (to be used in named conditionals only) that returns the boolean inverse of another boolean expression.

type DynRef

type DynRef struct {
	LogicalID string

	SrcRange hcl.Range
	// contains filtered or unexported fields
}

DynRef represents the name or id returned by a particular reference or pseudo-reference in the CloudFormation language.

type DynSplit

type DynSplit struct {
	Delimiter string
	String    DynExpr

	SrcRange hcl.Range
	// contains filtered or unexported fields
}

DynSplit splits a string by a given delimiter to produce a list.

type EachState

type EachState struct {
	Key   addr.EachIndex
	Value cty.Value
}
var NoEachState EachState

func (EachState) Enabled

func (s EachState) Enabled() bool

type FlatOutput

type FlatOutput struct {
	Value      DynExpr
	ExportName DynExpr
}

type FlatParameter

type FlatParameter struct {
	Type           string
	Description    string
	DefaultValue   cty.Value
	AllowedPattern cty.Value
	AllowedValues  []cty.Value
	MinLength      cty.Value
	MaxLength      cty.Value
	MinValue       cty.Value
	MaxValue       cty.Value
	NoEcho         cty.Value
}

type FlatResource

type FlatResource struct {
	Type       string
	Properties map[string]*DynExpr
	Metadata   map[string]cty.Value
	DependsOn  []string
}

type FlatTemplate

type FlatTemplate struct {
	Description string
	Metadata    map[string]cty.Value
	Parameters  map[string]*FlatParameter
	Mappings    map[string]map[string]cty.Value
	Conditions  map[string]DynExpr
	Resources   map[string]*FlatResource
	Outputs     map[string]*FlatOutput
}

type ModuleContext

type ModuleContext struct {
	// Global is a reference to the RootContext that this context belongs to.
	Global *RootContext

	// Path is the absolute path of the module instance that this context
	// belongs to. This can be used as part of identifiers that need to be
	// globally-unique in the resulting flattened CloudFormation JSON.
	Path addr.ModulePath

	// Root is a reference to the ModuleContext for the root module. The
	// root ModuleContext points to itself.
	Root *ModuleContext

	// Parent is a reference to the ModuleContext for the parent module.
	// The root module has a nil Parent.
	Parent *ModuleContext

	// Children contains references to ModuleContexts for child modules,
	// keyed by the module name given in configuration. Since a single
	// Module block can fan out to many instances with ForEach, the children
	// are accessed through a ModuleEach.
	Children map[string]*ModuleEach

	// Config is the configuration for the module that this context
	// belongs to. A Config should not be modified once it is included
	// in a ModuleContext.
	Config *config.Module

	// Constants is a map of values of all of the named constants
	// for the module.
	Constants map[string]cty.Value
}

func (*ModuleContext) DetectVariables

func (mctx *ModuleContext) DetectVariables(expr hcl.Expression) []hcl.Traversal

DetectVariables is like the global function of the same name, except that it additionally follows references to locals and includes them only if they transitively refer to variables.

func (*ModuleContext) EvalConstant

func (mctx *ModuleContext) EvalConstant(expr hcl.Expression, ty cty.Type, each EachState) (cty.Value, hcl.Diagnostics)

EvalConstant evaluates the given expression to produce a constant value, which is then converted to the requested type.

When evaluating in this mode, only constant values and named constants can be accessed. If any other scope traversals are detected then error diagnostics will be returned and the result will probably be a null value.

If EachState is set to anything other than NoEachState then the "Each" object is also available for use, exposing the values in the given EachState.

func (*ModuleContext) EvalDynamic

func (mctx *ModuleContext) EvalDynamic(expr hcl.Expression, each EachState) (DynExpr, hcl.Diagnostics)

EvalDynamic evaluates the given expression to produce a DynExpr, which can then be serialized as a value in CloudFormation JSON.

If EachState is set to anything other than NoEachState then the "Each" object is also available for use, exposing the values in the given EachState.

func (*ModuleContext) IsRootModule

func (mctx *ModuleContext) IsRootModule() bool

func (*ModuleContext) TypeCheck

func (mctx *ModuleContext) TypeCheck(expr hcl.Expression, each EachState) (cty.Type, hcl.Diagnostics)

TypeCheck verifies the internal type consistency of the given expression and then, if successful, returns the expression's own result type.

TypeCheck relies on the type rules as defined by HCL and so does not enforce the additional constraints that apply when lowering to CloudFormation dynamic expressions using EvalDynamic, which arise from the limitations of the CloudFormation expression language.

The result may be cty.DynamicPseudoType if insufficient information is available to produce a result, which can occur if there are inconsistencies or errors elsewhere in the configuration. For best results, ensure that all of the referenceable configuration constructs are correct before type-checking references to them. For example, we assume that a prior check has detected resources with invalid type names and reported them, and so TypeCheck will treat these as being DynamicPseudoType.

If any type inconsistencies are found then they are returned as error diagnostics. The returned type is always valid, but may not be accurate in the precence of error diagnostics. cty.DynamicPseudoType is returned if errors prevent type resolution altogether.

func (*ModuleContext) VisitDownstreamModules

func (mctx *ModuleContext) VisitDownstreamModules(cb ModuleVisitor)

func (*ModuleContext) VisitModules

func (mctx *ModuleContext) VisitModules(cb ModuleVisitor)

type ModuleEach

type ModuleEach struct {
	// EachType is the type of index being used for ForEach on this collection
	// of module instances, or addr.NoEach if ForEach is not in use.
	EachType addr.EachType

	// Modules contains a reference to the ModuleContext for each known index.
	// If not in ForEach mode, this map contains only a single member whose
	// key is addr.NoEachIndex.
	//
	// To iterate over all module instances, use the values of this map
	// and disregard the keys.
	Modules map[addr.EachIndex]*ModuleContext
}

ModuleEach represents either a single child ModuleContext or the multiple indexed ModuleContexts created when ForEach is used in a module block.

Use IsForEach to determine whether ForEach mode is in use, since this dictates which methods may be used on a particular instance.

func (*ModuleEach) Index

func (e *ModuleEach) Index(key addr.EachIndex) *ModuleContext

func (*ModuleEach) IsForEach

func (e *ModuleEach) IsForEach() bool

IsForEach returns true if

func (*ModuleEach) Single

func (e *ModuleEach) Single() *ModuleContext

type ModuleVisitor

type ModuleVisitor func(*ModuleContext) bool

type RootContext

type RootContext struct {
	// RootModule is a reference to the ModuleContext for the root module.
	RootModule *ModuleContext

	// Schema is a representation of the resource type schema provided by
	// AWS to describe the available resource types and their properties and
	// attributes.
	Schema *schema.Schema
}

func NewRootContext

func NewRootContext(parser *config.Parser, rootPath string, constants hcl.Attributes, sch *schema.Schema) (*RootContext, hcl.Diagnostics)

NewRootContext creates a RootContext by loading a module configuration from the given path (which may be either a directory containing .awsup files or a single .awsup file) and then loading the tree of descendent modules referenced by the root by following Source values given in Module blocks.

If the returned hcl.Diagnostics contains errors then the returned context may not be complete, but is still returned to allow for cautious use by analysis use-cases such as text editor integrations.

func (*RootContext) Build

func (ctx *RootContext) Build() (*FlatTemplate, hcl.Diagnostics)

func (*RootContext) VisitModules

func (ctx *RootContext) VisitModules(cb ModuleVisitor)

Jump to

Keyboard shortcuts

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