config

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseBody

func ParseBody(body hcl.Body, context *hcl.EvalContext, val interface{}) error

ParseBody parses the hcl.Body into a value map.

func ParseFile

func ParseFile(source *SourceFile) (*hcl.File, error)

ParseFile parses file content into hcl.File. It will not read the filename from disk so filename argument can be anything, but it will not try to load same file twice.

To convert the file into a struct use ParseBody

Types

type Backend

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

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

type Data

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

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

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"`

	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

type Environment

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

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

type Hook

type Hook struct {
	Type         string    `hcl:"type,label"`
	TriggerOn    string    `hcl:"trigger_on,attr"`
	Command      string    `hcl:"command,attr"`
	Arguments    *[]string `hcl:"args,attr"`
	SetEnv       *bool     `hcl:"set_env,attr"`
	DisableCache *bool     `hcl:"disable_cache,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

type Inputs

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

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

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader client for loading sources

func NewLoader

func NewLoader(options *Options) *Loader

NewLoader creates a new loader client

func (*Loader) Load

func (l *Loader) Load(path string) ([]*Source, error)

Load sources from path and return list of all Sources found at path. Path can either be a single file or a directory, in which case it will load all files found in directory.

type Module

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

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.

type Options

type Options struct {
	WorkingDirectory string
	TempDirectory    string

	// MaxDepth to search for dependencies. Should be enough with 1.
	MaxDepth int
}

Options when loading modules. If TempDirectory is not set it will create a random temporary directory. This is not advised as it will create a new temporary directory for every call to load.

type Source

type Source struct {
	SourceFile

	Name         string `hcl:"name,label"`
	Config       *Config
	Env          map[string]string
	Dependencies map[string]*Source
}

Source information about one file loaded from disk. Includes hcl tag for name because it is needed when saving SourceFile.

func GetSourceFromFile

func GetSourceFromFile(file string) (*Source, error)

GetSourceFromFile returns the Source for file (should be absolute path). If file exists in cache it will return the cached item, otherwise it will create the Source and return a pointer to new Source.

type SourceFile

type SourceFile struct {
	File    string
	Content []byte
}

SourceFile is a file to load config source from

func GetSourceFile

func GetSourceFile(file string) (*SourceFile, error)

GetSourceFile returns the SourceFile for input file. If file is already loaded before it will return a pointer to that, otherwise it will load the file and return a new pointer

func (*SourceFile) Config

func (sf *SourceFile) Config() (*Config, error)

Config returns the configuration struct for SourceFile. It will parse the content of file.

func (*SourceFile) ConfigMergedWith

func (sf *SourceFile) ConfigMergedWith(sources []*SourceFile) (*Config, error)

ConfigMergedWith returns the config from sourcefile merged together with the config from input sources.

func (*SourceFile) EvalContext

func (sf *SourceFile) EvalContext() *hcl.EvalContext

EvalContext returns hcl eval context for SourceFile. It will add a variable source.path that is full path for file, source.name is the name of file without extension and source.filename is the name of file with extension

func (*SourceFile) GetAutoImport

func (sf *SourceFile) GetAutoImport() ([]*SourceFile, error)

GetAutoImport returns a list of all files that should be auto imported together with this sourcefile. That is all files that have _auto in filename and resides in same folder as sourcefile

Returned list will not include the sourcefile itself, this is just a list of the additional files that should be loaded.

Jump to

Keyboard shortcuts

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