config

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package config contains all configuration structs and helper functions to merge and validate different elements of configuration. To create new configuration read it from file by using the loader package.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ValidHookTriggers is a list of valid values for trigger_on
	ValidHookTriggers = []string{"prepare", "finish"}
)

Functions

This section is empty.

Types

type Backend

type Backend struct {
	Type   string   `hcl:"type,label"`
	Config hcl.Body `hcl:",remain"`

	comp.Remainer
}

Backend for remote state storage. This will be added to an override file before running terraform init. Any existing backend configuration in module will therefore be overridden.

Supports same attributes as terraform backend configuration. For dependencies this is used to configure remote state data source.

func (*Backend) Merge

func (b *Backend) Merge(src *Backend) error

Merge current backend with source. Source will overwrite settings from current backend

type Config

type Config struct {
	Datas        []*Data       `hcl:"data,block"`
	Dependencies []*Dependency `hcl:"dependency,block"`
	Hooks        []*Hook       `hcl:"hook,block"`
	Environment  *Environment  `hcl:"environment_variables,block"`
	Backend      *Backend      `hcl:"backend,block"`
	Module       *Module       `hcl:"module,block"`
	Inputs       *Inputs       `hcl:"inputs,block"`
}

Config structure for file describing deployment. This includes the module source, inputs dependencies, backend etc. One config element is connected to a single deployment

func (*Config) Merge

func (c *Config) Merge(srcs []*Config) error

Merge all sources into current configuration struct. Should just call merge on all blocks / attributes of config struct.

func (*Config) PostProcess

func (c *Config) PostProcess(file *File)

PostProcess is called after merging all configurations together to perform additional processing after config is read. Can modify config elements

func (Config) Validate

func (c Config) Validate() (bool, error)

Validate that the configuration is correct. Calls validation on all parts of the struct. This assumes merge is already done and this is a complete configuration. If it is just a partial configuration from a child config it can fail as required blocks might not have been set.

type Data

type Data struct {
	Type string `hcl:"type,label"`
	Name string `hcl:"name,label"`

	Config hcl.Body `hcl:",remain"`

	comp.Remainer
}

Data sources as defined by terraform. This is just a copy of the terraform model and is written to the dependency file as defined, no extra processing done.

func (*Data) Merge

func (d *Data) Merge(src *Data) error

Merge data source with src data source only if type and name matches.

type Dependency

type Dependency struct {
	Name             string `hcl:"name,label"`
	Source           string `hcl:"source,attr"`
	RunInSeparateEnv bool   `hcl:"run_in_separate_env,optional"`

	Backend *Backend `hcl:"backend,block"`
}

Dependency towards another tau deployment. Source can either be a relative / absolute path (start with . or / in that case) to a file or a directory.

For each dependency it will create a remote_state data source to retrieve the values from dependency. Backend configuration will be read from the dependency file. To override attributes define the backend block in dependency and only define the attributes that should be overridden. For instance it can be useful to override token attribute if current module and dependency module use different token's for authentication

If RunInSeparateEnv is set to true it should fork a new environment that resolves all dependencies in separate process (environment relative to dependency). Otherwise it will resolve all dependencies in same environment as current execution.

func (*Dependency) Merge

func (d *Dependency) Merge(src *Dependency) error

Merge dependency with source dependency.

func (*Dependency) Validate

func (d *Dependency) Validate() (bool, error)

Validate that source is set on dependency.

type Environment

type Environment struct {
	Config hcl.Body `hcl:",remain"`

	comp.Remainer
}

Environment variables that should be added to the shell commands run (specfifically terraform). Define variables using attributes, blocks not supported

func (*Environment) Merge

func (e *Environment) Merge(src *Environment) error

Merge current environment with config from source

func (*Environment) Parse

func (e *Environment) Parse(context *hcl.EvalContext) (map[string]string, error)

Parse parses the config and returns all the environment variables defined in config.

func (Environment) Validate

func (e Environment) Validate() (bool, error)

Validate checks that all variables contain valid names

type File

type File struct {
	Name     string
	FullPath string
	Content  []byte
	// contains filtered or unexported fields
}

File is a config file that is not parsed. It will read the content and store for later processing Used when same config files should be read with different evaluation contexts.

Children is used to add files it is dependent on that should be processed together with this one. When parsing configuration it will merge config from all children together with File. Current file takes presedence and will overwrite all children files.

func NewFile

func NewFile(filename string, content []byte) (*File, error)

NewFile returns a new File. It will check that it exists and read content, but not parse it

func (*File) AddChild

func (f *File) AddChild(file *File)

AddChild adds a child File.

func (*File) AddToContext

func (f *File) AddToContext(key string, value cty.Value)

AddToContext adds a variable to the evaluation context of this file

func (*File) Config

func (f *File) Config() (*Config, error)

Config returns the full configuration for file. This includes the merged configuration from all children. Should only call this once as it will do full parsing of file and all children

func (*File) EvalContext

func (f *File) EvalContext() *hcl.EvalContext

EvalContext returns the evaluation context for this file

func (*File) String

func (f *File) String() string

type Hook

type Hook struct {
	Type         string    `hcl:"type,label"`
	TriggerOn    *string   `hcl:"trigger_on,attr"`
	Command      *string   `hcl:"command,attr"`
	Script       *string   `hcl:"script,attr"`
	Arguments    *[]string `hcl:"args,attr"`
	SetEnv       *bool     `hcl:"set_env,attr"`
	FailOnError  *bool     `hcl:"fail_on_error,attr"`
	DisableCache *bool     `hcl:"disable_cache,attr"`
	WorkingDir   *string   `hcl:"working_dir,attr"`
}

Hook describes a hook that should be run at specific time during deployment. Can be used to set environment variables or prepare environment before deployment

TriggerOn decides at which event this hook should trigger. On event command specified in Command will run. If read_output is set to true it will try to parse the output from command (stdout) as key=value pairs and add them to list of environment variables that are sent to terraform commands

To prevent same command from running multiple times it will assume that running same command multiple times always produce same result and therefore cache output. To prevent this set disable_cache = true. It will force the command to run for every source including hook

By default it will fail command if hook fails. To prevent this set fail_on_error = false

func (Hook) HasCommand

func (h Hook) HasCommand() bool

HasCommand returns true is command is defined

func (Hook) HasScript

func (h Hook) HasScript() bool

HasScript returns true if script is defined

func (*Hook) Merge

func (h *Hook) Merge(src *Hook) error

Merge current hook with config from source

func (Hook) Validate

func (h Hook) Validate() (bool, error)

Validate that all required settings are correct

type Inputs

type Inputs struct {
	Config hcl.Body `hcl:",remain"`

	comp.Remainer
}

Inputs that are sent to module for deployment. Config is converted to a map of attributes. Supports all functions supported by terraform.

func (*Inputs) Merge

func (i *Inputs) Merge(src *Inputs) error

Merge current inputs with config from source

type Module

type Module struct {
	Source  string `hcl:"source,attr"`
	Version string `hcl:"version,optional"`
}

Module to import and deploy. Uses go-getter to download source, so supports git repos, http(s) sources etc. If version is defined it will assume it is a terraform registry source and try to download from registry.

func (*Module) GetSource

func (m *Module) GetSource() string

GetSource returns the full source path for module. This can be sent to getter client to retrieve the module.

func (*Module) Merge

func (m *Module) Merge(src *Module) error

Merge current module with config from source

Directories

Path Synopsis
Package comp contains compositions for configuration structs.
Package comp contains compositions for configuration structs.
Package loader can load and parse configuration files.
Package loader can load and parse configuration files.

Jump to

Keyboard shortcuts

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