parser

package
v0.0.0-...-d8ef078 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTerrafile = Terrafile{

	ExecBlock: &ExecBlock{
		PlanBlock: &ExecPlanBlock{
			Input:   false,
			Lock:    true,
			Out:     "tfplan",
			SkipOut: false,
		},
	},
	TerraformBlock: &TerraformBlock{
		RequiredProvidersBlock: &TerraRequiredProviders{
			RequiredProviders: make(map[string]RequiredProvider),
		},
	},
}

DefaultTerrafile sets default values for a Terrafile that are used when parsing a new Terrafile

Functions

func ExecTemplate

func ExecTemplate(buildData *BuildData, name string, text string) (*bytes.Buffer, error)

func TemplateWrite

func TemplateWrite(buildData *BuildData, name string, text string, target string) error

func TraverseUpDirectory

func TraverseUpDirectory(path string, visit func(dir string) (bool, error)) error

TraverseUpDirectory takes a path and a callback function. For each directory that is an ancestor of path (and including path), call the callback function. Callback returns an error if something went wrong (which stops the traversal) and a boolean: if true is returned the traversal continues, if false the traversal finishes gracefully

Types

type BuildData

type BuildData struct {
	Locals    map[string]interface{}
	Variables map[string]interface{}
	Values    map[string]interface{}
	Terrafile *Terrafile
	// RelativeDir is the relative directory from the root Terrafile to the
	// Terrafile being built
	RelativeDir string
	// RelativePath is the relative path from the root Terrafile to the Terrafile
	// being built
	RelativePath string
	// RelativeRootDir is the relative directory of the root Terrafile
	RelativeRootDir string
	// RootDir is the absolute directory of the root Terrafile
	RootDir string
}

BuildData defines the data which is passed to the Go template engine

type Config

type Config struct {
	Chdir string
}

func DefaultConfig

func DefaultConfig() *Config

type ExecBlock

type ExecBlock struct {
	Skip      bool           `hcl:"skip,optional"`
	ExtraArgs []string       `hcl:"extra_args,optional"`
	PlanBlock *ExecPlanBlock `hcl:"plan,block"`
}

type ExecPlanBlock

type ExecPlanBlock struct {
	Input bool `hcl:"input,optional"`
	Lock  bool `hcl:"lock,optional"`
	// Out specifies the name of the Terraform plan file to create (if any)
	Out string `hcl:"out,optional"`
	// SkipOut says whether to avoid creating a plan file or not. Useful in cases
	// such as running Terraform Cloud remotely, where plans cannot be created.
	SkipOut bool `hcl:"skip_out,optional"`
}

ExecPlanBlock defines the arguments for running the Terraform plan

type RequiredProvider

type RequiredProvider struct {
	Source  string `hcl:"source,attr" cty:"source"`
	Version string `hcl:"version,attr" cty:"version"`
}

RequiredProvider defines the body of required_providers

type TerraConfig

type TerraConfig struct {
	Terrafiles       []*Terrafile
	WorkingDirectory string
}

func Parse

func Parse(config *Config) (*TerraConfig, error)

func (*TerraConfig) MergeTerrafiles

func (c *TerraConfig) MergeTerrafiles() error

func (*TerraConfig) RootModules

func (c *TerraConfig) RootModules() []*Terrafile

RootModules returns the Terrafiles that are considered root modules and should therefore be processed

func (*TerraConfig) RootTerrafiles

func (c *TerraConfig) RootTerrafiles() []*Terrafile

RootTerrafile returns the top-most (root) Terrafiles. It's possible that there's multiple root terrafiles if there are multiple trees of terrafiles that have been parsed

type TerraLocals

type TerraLocals struct {
	Locals map[string]cty.Value `hcl:",remain"`
}

type TerraRequiredProviders

type TerraRequiredProviders struct {
	RequiredProviders map[string]RequiredProvider `hcl:",remain"`
}

TerraRequiredProviders defines the map of required_providers

type TerraTemplate

type TerraTemplate struct {
	Name     string `hcl:",label"`
	Contents string `hcl:"contents,attr"`
	// Target defines the target file to generate.
	// Defaults to the Name of the template with a ".tp.tf" extension
	Target string `hcl:"target,optional"`
	// ConditionAttr defines a string boolean that specifies whether this template
	// should be built or not.
	// The string can include Go templates, which means you can have dynamic
	// behaviour based on the Terrafile
	ConditionAttr string `hcl:"condition,optional"`
}

TerraTemplate defines the template{} block within a Terrafile

func (TerraTemplate) Condition

func (t TerraTemplate) Condition(data *BuildData) (bool, error)

Condition resolves the condition attribute to a boolean, or error. Errors can occur if either the templating errored or the conversion from string to bool is not possible.

type TerraValues

type TerraValues struct {
	Values map[string]cty.Value `hcl:",remain"`
}

type TerraVariables

type TerraVariables struct {
	Variables map[string]cty.Value `hcl:",remain"`
}

type Terrafile

type Terrafile struct {
	// Path
	Path string
	Dir  string
	// IsRoot tells whether this terrafile is for a root module
	IsRoot bool
	// Templates defines the list of templates that this Terrafile defines
	Templates []*TerraTemplate `hcl:"template,block"`

	LocalsBlock    *TerraLocals    `hcl:"locals,block"`
	VariablesBlock *TerraVariables `hcl:"variables,block"`
	ValuesBlock    *TerraValues    `hcl:"values,block"`

	TerraformBlock *TerraformBlock `hcl:"terraform,block"`

	// BuildBlock *BuildBlock `hcl:"build,block"`
	ExecBlock *ExecBlock `hcl:"exec,block"`

	// Ancestor defines any parent/ancestor Terrafiles that this Terrafile
	// should inherit from
	Ancestor *Terrafile

	// Children contains any child Terrafiles to this Terrafile
	Children []*Terrafile
}

func (*Terrafile) BuildData

func (t *Terrafile) BuildData() (*BuildData, error)

func (*Terrafile) Locals

func (t *Terrafile) Locals() map[string]cty.Value

func (*Terrafile) LocalsAsGo

func (t *Terrafile) LocalsAsGo() (map[string]interface{}, error)

func (*Terrafile) RelativeDir

func (t *Terrafile) RelativeDir() string

RelativeDir gets the relative directory from the Root Terrafile to this Terrafile

func (*Terrafile) RelativePath

func (t *Terrafile) RelativePath() string

RelativePath gets the relative directory from the Root Terrafile to this Terrafile

func (*Terrafile) RelativeRootDir

func (t *Terrafile) RelativeRootDir() string

RelativeRootDir returns the relative directory of the root Terrafile

func (*Terrafile) RootDir

func (t *Terrafile) RootDir() string

RootDir returns the absolute directory of the root Terrafile

func (*Terrafile) Values

func (t *Terrafile) Values() map[string]cty.Value

func (*Terrafile) ValuesAsGo

func (t *Terrafile) ValuesAsGo() (map[string]interface{}, error)

func (*Terrafile) Variables

func (t *Terrafile) Variables() map[string]cty.Value

func (*Terrafile) VariablesAsGo

func (t *Terrafile) VariablesAsGo() (map[string]interface{}, error)

type TerraformBlock

type TerraformBlock struct {
	RequiredVersion        string                  `hcl:"required_version,optional"`
	RequiredProvidersBlock *TerraRequiredProviders `hcl:"required_providers,block"`
}

TerraformBlock defines the terraform{} block within a Terrafile

func (*TerraformBlock) RequiredProviders

func (tb *TerraformBlock) RequiredProviders() map[string]RequiredProvider

RequiredProviders returns the map of terraform required_providers, or nil

Jump to

Keyboard shortcuts

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