pkg

package
v1.24.2 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

ForEach (aka Map) processing for modules

This file implements !Rain::Module

Package pkg provides functionality similar to the AWS CLI cloudformation package command but has greater flexibility, allowing content to be included anywhere in a template

To include content into your templates, use any of the following either as YAML tags or as one-property objects, much as AWS intrinsic functions are used, e.g. "Fn::Join"

`Rain::Include`: insert the content of the file into the template directly. The file must be in YAML or JSON format.

`Rain::Env`: inserts environmental variable value into the template as a string. Variable must be set.

`Rain::Embed`: insert the content of the file as a string

`Rain::S3Http`: uploads the file or directory (zipping it first) to S3 and returns the HTTP URI (i.e. `https://bucket.s3.region.amazonaws.com/key`)

`Rain::S3`: a string value uploads the file or directory (zipping it first) to S3 and returns the S3 URI (i.e. `s3://bucket/key`)

`Rain::S3`: an object with the following properties

`Path`: path to the file or directory. If a directory is supplied, it will
be zipped before uploading to S3 `BucketProperty`: Name of returned
property that will contain the bucket name `KeyProperty`: Name of returned
property that will contain the object key `VersionProperty`: (optional)
Name of returned property that will contain the object version

`Rain::Module`: Supply a URL to a rain module

Package pkg provides functionality similar to the AWS CLI cloudformation package command but has greater flexibility, allowing content to be included anywhere in a template

To include content into your templates, use any of the following either as YAML tags or as one-property objects, much as AWS instrinsic functions are used, e.g. "Fn::Join"

`Rain::Include`: insert the content of the file into the template directly. The file must be in YAML or JSON format. `Rain::Env`: inserts environmental variable value into the template as a string. Variable must be set. `Rain::Embed`: insert the content of the file as a string `Rain::S3Http`: uploads the file or directory (zipping it first) to S3 and returns the HTTP URI (i.e. `https://bucket.s3.region.amazonaws.com/key`) `Rain::S3`: a string value uploads the file or directory (zipping it first) to S3 and returns the S3 URI (i.e. `s3://bucket/key`) `Rain::S3`: an object with the following properties

`Path`: path to the file or directory. If a directory is supplied, it will be zipped before uploading to S3
`BucketProperty`: Name of returned property that will contain the bucket name
`KeyProperty`: Name of returned property that will contain the object key
`VersionProperty`: (optional) Name of returned property that will contain the object version
`Extension`: (optional) Extension appended to the end of the Object Key in S3

Index

Constants

View Source
const (
	MI = "$Index"
	MV = "$Identifier"
)
View Source
const (
	Metadata            = "Metadata"
	IfParam             = "IfParam"
	IfNotParam          = "IfNotParam"
	Overrides           = "Overrides"
	DependsOn           = "DependsOn"
	Properties          = "Properties"
	CreationPolicy      = "CreationPolicy"
	UpdatePolicy        = "UpdatePolicy"
	DeletionPolicy      = "DeletionPolicy"
	UpdateReplacePolicy = "UpdateReplacePolicy"
	Condition           = "Condition"
	Default             = "Default"
	Source              = "Source"
	ForEach             = "ForEach"
)
View Source
const (
	Hash     string = "Hash"
	Location string = "Location"
)
View Source
const AWSToolsMetrics = "AWSToolsMetrics"
View Source
const Rain = "Rain"

Variables

View Source
var Experimental bool

Experimental must be set to true to enable !Rain::Module

View Source
var HasModules bool
View Source
var HasRainSection bool
View Source
var NoAnalytics bool

Functions

func ConvertCsvToSequence added in v1.4.4

func ConvertCsvToSequence(csv string) *yaml.Node

Convert a comma delimted string to a sequence node

func DownloadFromZip added in v1.20.0

func DownloadFromZip(uriString string, verifyHash string, path string) ([]byte, error)

DownloadFromZip retrieves a single file from a zip file hosted on a URI

func ExtraIntrinsics added in v1.22.0

func ExtraIntrinsics(n *yaml.Node, basePath string) error

func File

func File(path string) (*cft.Template, error)

File opens path as a CloudFormation template and returns a cft.Template with assets included as per AWS CLI packaging rules and any Rain:: functions used

func FnInsertFile added in v1.22.0

func FnInsertFile(n *yaml.Node, basePath string) error

FnInsertFile inserts the contents of a local file into the template

func FnJoin added in v1.22.0

func FnJoin(n *yaml.Node) error

FnJoin converts to a scalar if the join can be fully resolved

func FnMerge added in v1.22.0

func FnMerge(n *yaml.Node) error

FnMerge merges objects and lists together. The arguments must be fully resolvable client-side

func FnSelect added in v1.22.0

func FnSelect(n *yaml.Node) error

FnSelect reduces Fn::Select to a scalar if it can be fully resolved

func ProcessOutputArrays added in v1.22.0

func ProcessOutputArrays(t *cft.Template) error

After processing normal outputs, go back and look for array references like Content[].Arn. Values for these should be stored on the template.

func Template

func Template(t *cft.Template, rootDir string, fs *embed.FS) (*cft.Template, error)

Template returns t with assets included as per AWS CLI packaging rules and any Rain:: functions used. rootDir must be passed in so that any included assets can be loaded from the same directory

func Unzip added in v1.20.0

func Unzip(f *os.File, dest string) error

Unzip unzips a zip file to a destination directory

Types

type EvalResult added in v1.23.0

type EvalResult string
const (
	Equals     EvalResult = "=="
	NotEquals  EvalResult = "!="
	UnResolved EvalResult = "?"
)

type Module added in v1.22.0

type Module struct {
	Config          *cft.ModuleConfig
	ParametersNode  *yaml.Node
	ResourcesNode   *yaml.Node
	OutputsNode     *yaml.Node
	Node            *yaml.Node
	ParentTemplate  *cft.Template
	ConditionsNode  *yaml.Node
	ConditionValues map[string]bool
	ModulesNode     *yaml.Node
	Parsed          *ParsedModule
	ParentModule    *Module
}

Module represents a complete module, including parent config

func (*Module) CheckOutputGetAtt added in v1.22.0

func (module *Module) CheckOutputGetAtt(s string, outputName string, outputVal any) (*yaml.Node, error)

CheckOutputGetAtt checks to see if a GetAtt string matches an Output. Returns nil if it's not a match.

func (*Module) Conditions added in v1.22.0

func (module *Module) Conditions() map[string]any

Conditions returns the Conditions node as a map

func (*Module) EvalAnd added in v1.23.0

func (module *Module) EvalAnd(n *yaml.Node) (EvalResult, error)

EvalAnd evaluates an Fn::And condition

func (*Module) EvalCond added in v1.23.0

func (module *Module) EvalCond(
	name string, val *yaml.Node) (EvalResult, error)

EvalCond evaluates a condition expression and returns its boolean value

func (*Module) EvalEquals added in v1.23.0

func (module *Module) EvalEquals(n *yaml.Node) (EvalResult, error)

EvalEquals evaluates an Fn::Equals condition

func (*Module) EvalNot added in v1.23.0

func (module *Module) EvalNot(n *yaml.Node) (EvalResult, error)

EvalNot evaluates an Fn::Not condition

func (*Module) EvalOr added in v1.23.0

func (module *Module) EvalOr(n *yaml.Node) (EvalResult, error)

EvalOr evaluates an Fn::Or condition

func (*Module) FnInvoke added in v1.22.0

func (module *Module) FnInvoke(n *yaml.Node) error

FnInvoke allows treating a module like a function, returning its outputs with modified parameters

func (*Module) GetArrayIndexFromString added in v1.23.0

func (module *Module) GetArrayIndexFromString(s string) (int, error)

GetArrayIndexFromString extracts an integer array index from a string with embedded brackets. For example, from "Content[1].Arn" it would return 1. Returns an error if no valid index is found.

func (*Module) InitNodes added in v1.22.0

func (module *Module) InitNodes()

func (*Module) Modules added in v1.22.0

func (module *Module) Modules() map[string]any

Modules returns the Modules node as a map

func (*Module) OutputGetAtt added in v1.22.0

func (module *Module) OutputGetAtt(outputName string, outputVal any, n *yaml.Node) error

A GetAtt to a module output. For example, !GetAtt A.B, where A is a module name, and B is a module output. B could be anything, a Scalar or an Object. It is also possible to reference module Maps (duplicate copies of a module), by using array brackets in the name, like A[0].B to reference a single instance of the module's Output, or A[].B, to get all module Outputs that have that name and return a Sequence with all of the Output values.

func (*Module) OutputSub added in v1.22.0

func (module *Module) OutputSub(outputName string, outputVal any, n *yaml.Node) error

OutputSub checks a Sub to see if it refers to a module Output. A Sub string can refer to an output scalar value. The reference needs to be like a GetAtt. For example, !Sub ${A.B} refers to module A, output B.

func (*Module) Outputs added in v1.22.0

func (module *Module) Outputs() map[string]any

Outputs returns the Outputs node as a map

func (*Module) Parameters added in v1.22.0

func (module *Module) Parameters() map[string]any

Parameters returns the Parameters node as a map

func (*Module) ProcessConditions added in v1.22.0

func (module *Module) ProcessConditions() error

ProcessConditions evaluates conditions in the module and removes Modules and Resources that should be omitted by a Condition that evaluates to false. It then looks for Fn::If function calls that reference the condition and resolves them, removing false nodes.

func (*Module) ProcessFnIf added in v1.23.0

func (module *Module) ProcessFnIf(n *yaml.Node,
	unResolved []string) (bool, error)

ProcessFnIf processes Fn::If functions in a node and its children Returns true if the node should be removed from its parent

func (*Module) ProcessOutputs added in v1.22.0

func (module *Module) ProcessOutputs() error

processModuleOutputs looks for any references in the parent template to the module's outputs and replaces them.

func (*Module) ProcessOverrides added in v1.22.0

func (module *Module) ProcessOverrides(
	resourceName string,
	resource *yaml.Node,
	clonedResource *yaml.Node) error

processOverrides copies module properties to the new node and checks to see if the template overrides anything

func (*Module) ProcessResources added in v1.22.0

func (module *Module) ProcessResources(outputNode *yaml.Node) error

ProcessResources injects the module's resources into the output node

func (*Module) Resolve added in v1.22.0

func (module *Module) Resolve(n *yaml.Node) error

Resolve resolves Ref, Sub, and GetAtt in the node, using module config Properties, Parameter defaults, and other Resource names within the module.

func (*Module) ResolveGetAtt added in v1.22.0

func (module *Module) ResolveGetAtt(n *yaml.Node) error

func (*Module) ResolveRef added in v1.22.0

func (module *Module) ResolveRef(n *yaml.Node) error

func (*Module) ResolveSub added in v1.22.0

func (module *Module) ResolveSub(n *yaml.Node) error

Resolve a Sub string in a module.

Sub strings can contain several types of variables. We leave intrinsics like ${AWS::Region} alone. ${Foo} is treated like a Ref to Foo ${Foo.Bar} is treated like a GetAtt.

func (*Module) Resources added in v1.22.0

func (module *Module) Resources() map[string]any

Resources returns the Resources node as a map

func (*Module) ValidateOverrides added in v1.22.0

func (module *Module) ValidateOverrides() error

validateOverrides returns an error if one of the Overrides isn't found

type ModuleContent added in v1.22.0

type ModuleContent struct {
	Content    []byte
	NewRootDir string
	BaseUri    string
}

type ParsedModule added in v1.22.0

type ParsedModule struct {
	Node       *yaml.Node
	AsTemplate *cft.Template
	RootDir    string
	FS         *embed.FS
}

Jump to

Keyboard shortcuts

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