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 ¶
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.
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 ¶
Merge all sources into current configuration struct. Should just call merge on all blocks / attributes of config struct.
func (*Config) PostProcess ¶
PostProcess is called after merging all configurations together to perform additional processing after config is read. Can modify config elements
func (Config) Validate ¶
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.
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 ¶
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 ¶
NewFile returns a new File. It will check that it exists and read content, but not parse it
func (*File) AddToContext ¶
AddToContext adds a variable to the evaluation context of this file
func (*File) Config ¶
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
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 ¶
HasCommand returns true is command is defined
type Inputs ¶
Inputs that are sent to module for deployment. Config is converted to a map of attributes. Supports all functions supported by terraform.
type Module ¶
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.