config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2014 License: MPL-2.0 Imports: 23 Imported by: 0

Documentation

Overview

The config package is responsible for loading and validating the configuration.

Index

Constants

View Source
const UnknownVariableValue = "74D93920-ED26-11E3-AC10-0800200C9A66"

UnknownVariableValue is a sentinel value that can be used to denote that the value of a variable is unknown at this time. RawConfig uses this information to build up data about unknown keys.

Variables

Funcs is the mapping of built-in functions for configuration.

Functions

func ProviderConfigName

func ProviderConfigName(t string, pcs []*ProviderConfig) string

ProviderConfigName returns the name of the provider configuration in the given mapping that maps to the proper provider configuration for this resource.

Types

type Config

type Config struct {
	ProviderConfigs []*ProviderConfig
	Resources       []*Resource
	Variables       []*Variable
	Outputs         []*Output
	// contains filtered or unexported fields
}

Config is the configuration that comes from loading a collection of Terraform templates.

func Append

func Append(c1, c2 *Config) (*Config, error)

Append appends one configuration to another.

Append assumes that both configurations will not have conflicting variables, resources, etc. If they do, the problems will be caught in the validation phase.

It is possible that c1, c2 on their own are not valid. For example, a resource in c2 may reference a variable in c1. But together, they would be valid.

func Load

func Load(path string) (*Config, error)

Load loads the Terraform configuration from a given file.

This file can be any format that Terraform recognizes, and import any other format that Terraform recognizes.

func LoadDir

func LoadDir(root string) (*Config, error)

LoadDir loads all the Terraform configuration files in a single directory and appends them together.

Special files known as "override files" can also be present, which are merged into the loaded configuration. That is, the non-override files are loaded first to create the configuration. Then, the overrides are merged into the configuration to create the final configuration.

Files are loaded in lexical order.

func Merge

func Merge(c1, c2 *Config) (*Config, error)

Merge merges two configurations into a single configuration.

Merge allows for the two configurations to have duplicate resources, because the resources will be merged. This differs from a single Config which must only have unique resources.

func (*Config) Validate

func (c *Config) Validate() error

Validate does some basic semantic checking of the configuration.

type FunctionInterpolation

type FunctionInterpolation struct {
	Func InterpolationFunc
	Args []Interpolation
}

FunctionInterpolation is an Interpolation that executes a function with some variable number of arguments to generate a value.

func (*FunctionInterpolation) GoString

func (i *FunctionInterpolation) GoString() string

func (*FunctionInterpolation) Interpolate

func (i *FunctionInterpolation) Interpolate(
	vs map[string]string) (string, error)

func (*FunctionInterpolation) Variables

type InterpolatedVariable

type InterpolatedVariable interface {
	FullKey() string
}

An InterpolatedVariable is a variable reference within an interpolation.

Implementations of this interface represents various sources where variables can come from: user variables, resources, etc.

func NewInterpolatedVariable

func NewInterpolatedVariable(v string) (InterpolatedVariable, error)

type Interpolation

type Interpolation interface {
	Interpolate(map[string]string) (string, error)
	Variables() map[string]InterpolatedVariable
}

Interpolation is something that can be contained in a "${}" in a configuration value.

Interpolations might be simple variable references, or it might be function calls, or even nested function calls.

func ExprParse

func ExprParse(v string) (Interpolation, error)

ExprParse parses the given expression and returns an executable Interpolation.

type InterpolationFunc

type InterpolationFunc func(map[string]string, ...string) (string, error)

InterpolationFunc is the function signature for implementing callable functions in Terraform configurations.

type LiteralInterpolation

type LiteralInterpolation struct {
	Literal string
}

LiteralInterpolation implements Interpolation for literals. Ex: ${"foo"} will equal "foo".

func (*LiteralInterpolation) Interpolate

func (i *LiteralInterpolation) Interpolate(
	map[string]string) (string, error)

func (*LiteralInterpolation) Variables

type Output

type Output struct {
	Name      string
	RawConfig *RawConfig
}

Output is an output defined within the configuration. An output is resulting data that is highlighted by Terraform when finished.

type ProviderConfig

type ProviderConfig struct {
	Name      string
	RawConfig *RawConfig
}

ProviderConfig is the configuration for a resource provider.

For example, Terraform needs to set the AWS access keys for the AWS resource provider.

type Provisioner

type Provisioner struct {
	Type      string
	RawConfig *RawConfig
	ConnInfo  *RawConfig
}

Provisioner is a configured provisioner step on a resource.

type RawConfig

type RawConfig struct {
	Raw            map[string]interface{}
	Interpolations []Interpolation
	Variables      map[string]InterpolatedVariable
	// contains filtered or unexported fields
}

RawConfig is a structure that holds a piece of configuration where te overall structure is unknown since it will be used to configure a plugin or some other similar external component.

RawConfigs can be interpolated with variables that come from other resources, user variables, etc.

RawConfig supports a query-like interface to request information from deep within the structure.

func NewRawConfig

func NewRawConfig(raw map[string]interface{}) (*RawConfig, error)

NewRawConfig creates a new RawConfig structure and populates the publicly readable struct fields.

func (*RawConfig) Config

func (r *RawConfig) Config() map[string]interface{}

Config returns the entire configuration with the variables interpolated from any call to Interpolate.

If any interpolated variables are unknown (value set to UnknownVariableValue), the first non-container (map, slice, etc.) element will be removed from the config. The keys of unknown variables can be found using the UnknownKeys function.

By pruning out unknown keys from the configuration, the raw structure will always successfully decode into its ultimate structure using something like mapstructure.

func (*RawConfig) GobDecode

func (r *RawConfig) GobDecode(b []byte) error

See GobEncode

func (*RawConfig) GobEncode

func (r *RawConfig) GobEncode() ([]byte, error)

GobEncode is a custom Gob encoder to use so that we only include the raw configuration. Interpolated variables and such are lost and the tree of interpolated variables is recomputed on decode, since it is referentially transparent.

func (*RawConfig) Interpolate

func (r *RawConfig) Interpolate(vs map[string]string) error

Interpolate uses the given mapping of variable values and uses those as the values to replace any variables in this raw configuration.

Any prior calls to Interpolate are replaced with this one.

If a variable key is missing, this will panic.

func (*RawConfig) UnknownKeys

func (r *RawConfig) UnknownKeys() []string

UnknownKeys returns the keys of the configuration that are unknown because they had interpolated variables that must be computed.

type Resource

type Resource struct {
	Name         string
	Type         string
	Count        int
	RawConfig    *RawConfig
	Provisioners []*Provisioner
	DependsOn    []string
}

A resource represents a single Terraform resource in the configuration. A Terraform resource is something that represents some component that can be created and managed, and has some properties associated with it.

func (*Resource) Id

func (r *Resource) Id() string

A unique identifier for this resource.

type ResourceVariable

type ResourceVariable struct {
	Type  string // Resource type, i.e. "aws_instance"
	Name  string // Resource name
	Field string // Resource field

	Multi bool // True if multi-variable: aws_instance.foo.*.id
	Index int  // Index for multi-variable: aws_instance.foo.1.id == 1
	// contains filtered or unexported fields
}

A ResourceVariable is a variable that is referencing the field of a resource, such as "${aws_instance.foo.ami}"

func NewResourceVariable

func NewResourceVariable(key string) (*ResourceVariable, error)

func (*ResourceVariable) FullKey

func (v *ResourceVariable) FullKey() string

func (*ResourceVariable) ResourceId

func (v *ResourceVariable) ResourceId() string

type UserVariable

type UserVariable struct {
	Name string
	Elem string
	// contains filtered or unexported fields
}

A UserVariable is a variable that is referencing a user variable that is inputted from outside the configuration. This looks like "${var.foo}"

func NewUserVariable

func NewUserVariable(key string) (*UserVariable, error)

func (*UserVariable) FullKey

func (v *UserVariable) FullKey() string

func (*UserVariable) GoString

func (v *UserVariable) GoString() string

type Variable

type Variable struct {
	Name        string
	Default     interface{}
	Description string
}

Variable is a variable defined within the configuration.

func (*Variable) DefaultsMap

func (v *Variable) DefaultsMap() map[string]string

DefaultsMap returns a map of default values for this variable.

func (*Variable) Merge

func (v *Variable) Merge(v2 *Variable) *Variable

Merge merges two variables to create a new third variable.

func (*Variable) Required

func (v *Variable) Required() bool

Required tests whether a variable is required or not.

func (*Variable) Type

func (v *Variable) Type() VariableType

Type returns the type of varialbe this is.

type VariableInterpolation

type VariableInterpolation struct {
	Variable InterpolatedVariable
}

VariableInterpolation implements Interpolation for simple variable interpolation. Ex: "${var.foo}" or "${aws_instance.foo.bar}"

func (*VariableInterpolation) GoString

func (i *VariableInterpolation) GoString() string

func (*VariableInterpolation) Interpolate

func (i *VariableInterpolation) Interpolate(
	vs map[string]string) (string, error)

func (*VariableInterpolation) Variables

type VariableType

type VariableType byte

VariableType is the type of value a variable is holding, and returned by the Type() function on variables.

const (
	VariableTypeUnknown VariableType = iota
	VariableTypeString
	VariableTypeMap
)

Jump to

Keyboard shortcuts

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