terraform

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package terraform provides a harness for the Terraform CLI. It is known to work with Terraform v0.14.7.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Classify

func Classify(err error) error

Classify errors returned from the Terraform CLI by inspecting its stderr.

Types

type FileFormat

type FileFormat int

The FileFormat of a Terraform file.

const (
	Unknown FileFormat = iota
	HCL
	JSON
)

Supported Terraform file formats.

type Harness

type Harness struct {
	// Path to the terraform binary.
	Path string

	// Dir in which to execute the terraform binary.
	Dir string
}

A Harness for running the terraform binary.

func (Harness) Apply

func (h Harness) Apply(ctx context.Context, o ...Option) error

Apply a Terraform configuration.

func (Harness) Destroy

func (h Harness) Destroy(ctx context.Context, o ...Option) error

Destroy a Terraform configuration.

func (Harness) Diff

func (h Harness) Diff(ctx context.Context, o ...Option) (bool, error)

Diff invokes 'terraform plan' to determine whether there is a diff between the desired and the actual state of the configuration. It returns true if there is a diff.

func (Harness) Init

func (h Harness) Init(ctx context.Context, o ...InitOption) error

Init initializes a Terraform configuration.

func (Harness) Outputs

func (h Harness) Outputs(ctx context.Context) ([]Output, error)

Outputs extracts outputs from Terraform state.

func (Harness) Resources

func (h Harness) Resources(ctx context.Context) ([]string, error)

Resources returns a list of resources in the Terraform state.

func (Harness) Validate

func (h Harness) Validate(ctx context.Context) error

Validate a Terraform configuration. Note that there may be interplay between validation and initialization. A configuration that needs to be initialized but isn't is deemed invalid. Attempts to initialise an invalid configuration will result in errors, which are not available in a machine readable format.

func (Harness) Workspace

func (h Harness) Workspace(ctx context.Context, name string) error

Workspace selects the named Terraform workspace. The workspace will be created if it does not exist.

type InitOption

type InitOption func(o *initOptions)

An InitOption affects how a Terraform is initialized.

func FromModule

func FromModule(module string) InitOption

FromModule can be used to initialize a Terraform configuration from a module, which may be pulled from git, a local directory, a storage bucket, etc.

type Option

type Option func(o *options)

An Option affects how a Terraform is invoked.

func WithVar

func WithVar(k, v string) Option

WithVar supplies a Terraform variable.

func WithVarFile

func WithVarFile(data []byte, f FileFormat) Option

WithVarFile supplies a file of Terraform variables.

type Output

type Output struct {
	Name      string
	Sensitive bool
	Type      OutputType
	// contains filtered or unexported fields
}

An Output from Terraform.

func (Output) BoolValue

func (o Output) BoolValue() bool

BoolValue returns the output's value as a boolean. It should only be used for outputs of type 'bool'.

func (Output) JSONValue

func (o Output) JSONValue() ([]byte, error)

JSONValue returns the output's value as JSON. It may be used for outputs of any type.

func (Output) NumberValue

func (o Output) NumberValue() float64

NumberValue returns the output's value as a number. It should only be used for outputs of type 'number'.

func (Output) StringValue

func (o Output) StringValue() string

StringValue returns the output's value as a string. It should only be used for outputs of type 'string'.

type OutputType

type OutputType int

An OutputType of Terraform.

const (
	OutputTypeUnknown OutputType = iota
	OutputTypeString
	OutputTypeNumber
	OutputTypeBool
	OutputTypeTuple
	OutputTypeObject
)

Terraform output types.

Jump to

Keyboard shortcuts

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