Documentation ¶
Overview ¶
Package tfx extends Terraform operations for new use cases.
Index ¶
- Constants
- Variables
- func AddState(a, b *tf.State) *tf.State
- func ClearDeps(s *tf.State)
- func Config(s map[string]*schema.Schema, raw map[string]interface{}) (*schema.ResourceData, error)
- func DeepCopy(v interface{}) interface{}
- func DisableLogging()
- func ExplainDiff(d *tf.Diff) string
- func InitSchemaProvider(rp tf.ResourceProvider) *schema.Provider
- func LoadModule(path string) (*module.Tree, error)
- func MakeFactory(f func() tf.ResourceProvider) tf.ResourceProviderFactory
- func NewState() *tf.State
- func ReadDiff(r io.Reader) (*tf.Diff, error)
- func ReadDiffFile(file string) (*tf.Diff, error)
- func ReadPlanFile(file string) (*tf.Plan, error)
- func ReadStateFile(file string) (*tf.State, error)
- func SetLogFilter(w io.Writer, level string, requireLevel bool) error
- func SubState(a, b *tf.State) *tf.State
- func WriteDiff(w io.Writer, d *tf.Diff) error
- func WriteDiffFile(file string, d *tf.Diff) error
- func WritePlanFile(file string, p *tf.Plan) error
- func WriteStateFile(file string, s *tf.State) error
- type AttrGen
- type Ctx
- func (c *Ctx) Apply(t *module.Tree, s *tf.State) (*tf.State, error)
- func (c *Ctx) Conform(t *module.Tree, s *tf.State, strict bool) (StateTransform, error)
- func (c *Ctx) Diff(t *module.Tree, s *tf.State) (*tf.Diff, error)
- func (c *Ctx) Mutate(s *tf.State, cfg *MutateCfg) (*tf.Diff, error)
- func (c *Ctx) Passthrough(t *module.Tree, s *tf.State) (*tf.State, error)
- func (c *Ctx) Patch(s *tf.State, d *tf.Diff) (*tf.State, error)
- func (c *Ctx) Plan(t *module.Tree, s *tf.State) (*tf.Plan, error)
- func (c *Ctx) Refresh(s *tf.State) (*tf.State, error)
- func (c *Ctx) SetDefaults(s *tf.State)
- type DepMap
- type DepSpec
- type MutateCfg
- type MutateFunc
- type MutateState
- type ProviderMap
- func (pm *ProviderMap) Add(name, version string, f tf.ResourceProviderFactory)
- func (pm ProviderMap) DefaultResolver() tf.ResourceProviderResolver
- func (pm ProviderMap) ImportResources(typ string, attrs AttrGen) ([]Resource, error)
- func (pm ProviderMap) MakeResources(typ string, attrs AttrGen) ([]Resource, error)
- func (pm ProviderMap) NewResource(typ, id string, useImport bool) (Resource, error)
- func (pm ProviderMap) PassthroughResolver() tf.ResourceProviderResolver
- func (pm ProviderMap) ResourceSchema(typ string) (*schema.Provider, *schema.Resource)
- func (pm ProviderMap) Schema(provider string) *schema.Provider
- func (pm ProviderMap) SchemaResolver() tf.ResourceProviderResolver
- type Resource
- type StateTransform
Constants ¶
const DefaultStateFile = "terraform.tfstate"
DefaultStateFile is the name of the default Terraform state file. It is redefined here to avoid importing the entire command package.
Variables ¶
var Deps = make(DepMap)
Deps is the global dependency inference map.
Functions ¶
func AddState ¶
AddState performs 'a += b' operation on resources in a. Duplicate resources are ignored.
func DisableLogging ¶
func DisableLogging()
DisableLogging disables all Terraform logging, while allowing other messages through.
func ExplainDiff ¶
ExplainDiff returns a description of inconsistencies between actual state and desired config.
func InitSchemaProvider ¶
func InitSchemaProvider(rp tf.ResourceProvider) *schema.Provider
InitSchemaProvider should be called from factory functions to initialize new schema.Provider instances. It disables DefaultFuncs to ensure deterministic behavior (these are normally used to get environment variables), and sets zero-value defaults to prevent any user prompts.
func LoadModule ¶
LoadModule reads module config from a file or directory ("" or "-" mean stdin).
func MakeFactory ¶
func MakeFactory(f func() tf.ResourceProvider) tf.ResourceProviderFactory
MakeFactory adds a nil error return to a standard provider constructor to match factory function signature. This should be used instead of terraform.ResourceProviderFactoryFixed.
func ReadDiff ¶
ReadDiff reads Terraform diff from r. It supports both JSON-encoded diffs and plan files.
func ReadDiffFile ¶
ReadDiffFile reads Terraform diff from the specified file. It supports both JSON-encoded diffs and plan files.
func ReadPlanFile ¶
ReadPlanFile reads Terraform plan from the specified file.
func ReadStateFile ¶
ReadStateFile reads Terraform state from the specified file.
func SetLogFilter ¶
SetLogFilter configures Terraform log filter. Since all Terraform components use the default logger (ugh... why?!?), this may affect other code as well. If requireLevel is true, any log message that does not have a level prefix is filtered out.
func WriteDiffFile ¶
WriteDiffFile writes diff d to file in JSON format.
func WritePlanFile ¶
WritePlanFile writes plan p to file in binary format.
Types ¶
type AttrGen ¶
type AttrGen map[string]interface{}
AttrGen is an attribute value generator used to create resources. Valid value types are: string, []string, func(i int) string, and func(i int) *string. Functions must return values for i in the range [0,n). Use "#" key to specify n when there are no []string attributes.
type Ctx ¶
type Ctx struct { Meta tf.ContextMeta Parallelism int Providers ProviderMap }
Ctx implements standard and non-standard Terraform operations using a provider registry.
func Context ¶
func Context() *Ctx
Context returns a new context configured to use default providers.
func (*Ctx) Apply ¶
Apply does a plan/apply operation to ensure that state s matches config t and returns the new state.
func (*Ctx) Conform ¶
Conform returns a transformation that associates root module resource states in s with their configurations in t. If strict is true, the transform will remove any non-conforming resources.
func (*Ctx) Diff ¶
Diff return the changes required to apply configuration t to state s. If s is nil, an empty state is assumed.
func (*Ctx) Passthrough ¶
Passthrough does a plan/apply operation with no-op provider CRUD methods and returns the new state. The providers are prevented from making any API calls, and the resulting (invalid) state becomes a copy of the input config.
func (*Ctx) Patch ¶
Patch applies diff d to state s and returns the new state. Unlike the standard apply operation, this one does not require a valid config. It works by building and walking a modified apply graph that omits all config references, which means that node evaluation may have slightly different behavior. For example, resource lifecycle information is only available in the config, so create-before-destroy behavior cannot be implemented.
func (*Ctx) Plan ¶
Plan returns a plan to apply configuration t to state s. If s is nil, an empty state is assumed.
func (*Ctx) SetDefaults ¶
SetDefaults sets default values for any missing resource attributes in s. This is only needed after refreshing a scanned state.
type DepMap ¶
DepMap is a resource dependency inference map. Keys are resource types. Values are dependency specifications for attributes of that type. These maps are usually generated for each provider via depgen.
type DepSpec ¶
type DepSpec struct{ Attr, SrcType, SrcAttr string }
DepSpec specifies that the value of attribute Attr is obtained in HCL by interpolating "${SrcType.<name>.SrcAttr}". Resource dependencies are inferred by comparing the value(s) of the destination attribute with those of all available sources.
type MutateCfg ¶
type MutateCfg struct { Seed int64 Limit int Funcs []MutateFunc }
MutateCfg determines the behavior of the Mutate operation.
type MutateFunc ¶
type MutateFunc func(*MutateState)
MutateFunc is a function that can modify resources.
type MutateState ¶
type MutateState struct { *schema.ResourceData Rand *rand.Rand Diff *tf.ModuleDiff Module *tf.ModuleState Type string Key string Schema map[string]*schema.Schema }
MutateState contains the state of the current resource as well as the rest
func (*MutateState) RandID ¶
func (ms *MutateState) RandID(n int) string
RandID returns a random alphanumeric (base62) string of length n with the first character always an upper-case letter.
type ProviderMap ¶
type ProviderMap map[string]*provider
ProviderMap is an in-memory provider registry. It returns provider resolvers for Terraform context operations and provides access to provider schemas.
var Providers ProviderMap
Providers is the default in-memory provider registry.
func (*ProviderMap) Add ¶
func (pm *ProviderMap) Add(name, version string, f tf.ResourceProviderFactory)
Add adds a new provider to the registry. Version is optional. The factory function must return a new provider instance for each call (i.e. do not use terraform.ResourceProviderFactoryFixed wrapper).
func (ProviderMap) DefaultResolver ¶
func (pm ProviderMap) DefaultResolver() tf.ResourceProviderResolver
DefaultResolver returns a resolver for unmodified providers.
func (ProviderMap) ImportResources ¶
func (pm ProviderMap) ImportResources(typ string, attrs AttrGen) ([]Resource, error)
ImportResources calls NewResource for each "id" attribute (or for "#" invocations of its generator function), applies the resource importer, and populates any remaining attribute values.
func (ProviderMap) MakeResources ¶
func (pm ProviderMap) MakeResources(typ string, attrs AttrGen) ([]Resource, error)
MakeResources calls NewResource for each "id" attribute (or for "#" invocations of its generator function) and populates any remaining attribute values.
func (ProviderMap) NewResource ¶
func (pm ProviderMap) NewResource(typ, id string, useImport bool) (Resource, error)
NewResource returns a skeleton resource state for the specified resource type and ID. If useImport is true, the resource importer is applied to the new resource. Importers that return multiple new states or make API calls are not supported.
func (ProviderMap) PassthroughResolver ¶
func (pm ProviderMap) PassthroughResolver() tf.ResourceProviderResolver
PassthroughResolver returns a SchemaResolver with all schema validations disabled.
func (ProviderMap) ResourceSchema ¶
ResourceSchema returns the provider and resource schema for the specified resource type. It returns (nil, nil) if the type is unknown or not implemented via schema.Provider.
func (ProviderMap) Schema ¶
func (pm ProviderMap) Schema(provider string) *schema.Provider
Schema returns the schema for the specified provider. It returns nil if the provider is not registered or not implemented via schema.Provider. The returned value is cached and must only be used for local schema operations.
func (ProviderMap) SchemaResolver ¶
func (pm ProviderMap) SchemaResolver() tf.ResourceProviderResolver
SchemaResolver returns a resolver for schema-only providers. Provider configuration and CRUD operations are disabled, preventing the provider from requiring a valid config or making any API calls.
type Resource ¶
type Resource struct { Key string *tf.ResourceState // contains filtered or unexported fields }
Resource associates a state key with tf.ResourceState.
func (*Resource) Data ¶
func (r *Resource) Data() *schema.ResourceData
Data returns resource data for schema-aware operations.
type StateTransform ¶
StateTransform defines state resource address transformations. It can change resource keys, move resources between modules, and remove resources. Dependencies are updated as needed as long as they stay within the same module. Keys and values are Terraform resource addresses. Resource types are not validated. An empty value removes the resource.
func NormStateKeys ¶
func NormStateKeys(s *tf.State) (StateTransform, error)
NormStateKeys returns a transformation that normalizes resource state keys using provider names and resource IDs.
func (StateTransform) Apply ¶
func (st StateTransform) Apply(s *tf.State) error
Apply updates resource state keys according to the transformation map. The state is not modified if an error is returned. Missing resources are silently ignored. Address collisions are resolved in favor of the transformation, so the map {A: B} will replace an existing resource B with A. Without an explicit {B: ""} entry, resources that depended on B will depend on A after such transformation.
func (StateTransform) ApplyToDiff ¶
func (st StateTransform) ApplyToDiff(d *tf.Diff) error
ApplyToDiff updates resource diff keys according to the transformation map. The diff may be modified after an error.
func (StateTransform) Inverse ¶
func (st StateTransform) Inverse() StateTransform
Inverse returns an inverse state transformation. It returns nil if st is destructive. Implicit resource replacement is not detected.