Documentation ¶
Overview ¶
The config package is responsible for loading and validating the configuration.
Index ¶
- Constants
- Variables
- func IsEmptyDir(root string) (bool, error)
- func ProviderConfigName(t string, pcs []*ProviderConfig) string
- type AtlasConfig
- type Config
- type CountValueType
- type CountVariable
- type InterpolatedVariable
- type Module
- type ModuleVariable
- type Output
- type PathValueType
- type PathVariable
- type ProviderConfig
- type Provisioner
- type RawConfig
- func (r *RawConfig) Config() map[string]interface{}
- func (r *RawConfig) GobDecode(b []byte) error
- func (r *RawConfig) GobEncode() ([]byte, error)
- func (r *RawConfig) Interpolate(vs map[string]ast.Variable) error
- func (r *RawConfig) Merge(other *RawConfig) *RawConfig
- func (r *RawConfig) UnknownKeys() []string
- func (r *RawConfig) Value() interface{}
- type Resource
- type ResourceLifecycle
- type ResourceVariable
- type SelfVariable
- type UserVariable
- type Variable
- type VariableType
Constants ¶
const InterpSplitDelim = `B780FFEC-B661-4EB8-9236-A01737AD98B6`
InterpSplitDelim is the delimeter that is looked for to split when it is returned. This is a comma right now but should eventually become a value that a user is very unlikely to use (such as UUID).
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 ¶
var Funcs map[string]ast.Function
Funcs is the mapping of built-in functions for configuration.
var NameRegexp = regexp.MustCompile(`\A[A-Za-z0-9\-\_]+\z`)
NameRegexp is the regular expression that all names (modules, providers, resources, etc.) must follow.
Functions ¶
func IsEmptyDir ¶ added in v0.3.0
IsEmptyDir returns true if the directory given has no Terraform configuration files.
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 AtlasConfig ¶ added in v0.4.0
AtlasConfig is the configuration for building in HashiCorp's Atlas.
type Config ¶
type Config struct { // Dir is the path to the directory where this configuration was // loaded from. If it is blank, this configuration wasn't loaded from // any meaningful directory. Dir string Atlas *AtlasConfig Modules []*Module 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 ¶
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 ¶
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 ¶
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 ¶
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) InterpolatedVariables ¶ added in v0.3.0
func (c *Config) InterpolatedVariables() map[string][]InterpolatedVariable
InterpolatedVariables is a helper that returns a mapping of all the interpolated variables within the configuration. This is used to verify references are valid in the Validate step.
func (*Config) TestString ¶ added in v0.3.0
TestString is a Stringer-like function that outputs a string that can be used to easily compare multiple Config structures in unit tests.
This function has no practical use outside of unit tests and debugging.
type CountValueType ¶ added in v0.3.0
type CountValueType byte
CountValueType is the type of the count variable that is referenced.
const ( CountValueInvalid CountValueType = iota CountValueIndex )
type CountVariable ¶ added in v0.3.0
type CountVariable struct { Type CountValueType // contains filtered or unexported fields }
CountVariable is a variable for referencing information about the count.
func NewCountVariable ¶ added in v0.3.0
func NewCountVariable(key string) (*CountVariable, error)
func (*CountVariable) FullKey ¶ added in v0.3.0
func (c *CountVariable) FullKey() string
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 DetectVariables ¶ added in v0.3.7
func DetectVariables(root ast.Node) ([]InterpolatedVariable, error)
DetectVariables takes an AST root and returns all the interpolated variables that are detected in the AST tree.
func NewInterpolatedVariable ¶
func NewInterpolatedVariable(v string) (InterpolatedVariable, error)
type Module ¶ added in v0.3.0
Module is a module used within a configuration.
This does not represent a module itself, this represents a module call-site within an existing configuration.
type ModuleVariable ¶ added in v0.3.0
A ModuleVariable is a variable that is referencing the output of a module, such as "${module.foo.bar}"
func NewModuleVariable ¶ added in v0.3.0
func NewModuleVariable(key string) (*ModuleVariable, error)
func (*ModuleVariable) FullKey ¶ added in v0.3.0
func (v *ModuleVariable) FullKey() string
type Output ¶
Output is an output defined within the configuration. An output is resulting data that is highlighted by Terraform when finished.
type PathValueType ¶ added in v0.3.0
type PathValueType byte
const ( PathValueInvalid PathValueType = iota PathValueCwd PathValueModule PathValueRoot )
type PathVariable ¶ added in v0.3.0
type PathVariable struct { Type PathValueType // contains filtered or unexported fields }
A PathVariable is a variable that references path information about the module.
func NewPathVariable ¶ added in v0.3.0
func NewPathVariable(key string) (*PathVariable, error)
func (*PathVariable) FullKey ¶ added in v0.3.0
func (v *PathVariable) FullKey() string
type ProviderConfig ¶
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 ¶
Provisioner is a configured provisioner step on a resource.
type RawConfig ¶
type RawConfig struct { Key string Raw map[string]interface{} Interpolations []ast.Node 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 ¶
NewRawConfig creates a new RawConfig structure and populates the publicly readable struct fields.
func (*RawConfig) Config ¶
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) GobEncode ¶
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 ¶
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) Merge ¶ added in v0.4.0
Merge merges another RawConfig into this one (overriding any conflicting values in this config) and returns a new config. The original config is not modified.
func (*RawConfig) UnknownKeys ¶
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 RawCount *RawConfig RawConfig *RawConfig Provisioners []*Provisioner DependsOn []string Lifecycle ResourceLifecycle }
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.
type ResourceLifecycle ¶ added in v0.3.0
type ResourceLifecycle struct {
CreateBeforeDestroy bool `hcl:"create_before_destroy"`
}
ResourceLifecycle is used to store the lifecycle tuning parameters to allow customized behavior
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 SelfVariable ¶ added in v0.4.0
type SelfVariable struct { Field string // contains filtered or unexported fields }
SelfVariable is a variable that is referencing the same resource it is running on: "${self.address}"
func NewSelfVariable ¶ added in v0.4.0
func NewSelfVariable(key string) (*SelfVariable, error)
func (*SelfVariable) FullKey ¶ added in v0.4.0
func (v *SelfVariable) FullKey() string
func (*SelfVariable) GoString ¶ added in v0.4.0
func (v *SelfVariable) GoString() string
type UserVariable ¶
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 ¶
Variable is a variable defined within the configuration.
func (*Variable) DefaultsMap ¶
DefaultsMap returns a map of default values for this variable.
func (*Variable) Type ¶
func (v *Variable) Type() VariableType
Type returns the type of varialbe this is.
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 )