terraform

package
v0.0.0-...-a16ed4d Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2020 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanDisplayReadableTerraformPolicyChanges

func CanDisplayReadableTerraformPolicyChanges() bool

CanDisplayReadableTerraformPolicyChanges is true when the prerequisites for ReadableTerraformPolicyChanges are fulfilled

func ReadableTerraformPolicyChanges

func ReadableTerraformPolicyChanges(terraformChanges string) (string, error)

ReadableTerraformPolicyChanges takes the output of `terraform plan` and rewrites policy diff to be in unified diff format

func VersionMatches

func VersionMatches(v *version.Version, versionConstraint string) bool

VersionMatches returns whether or not the version matches the constraint. A constraint is a string like ">0.7.0" or "<1". See the go-version documentation for more info: https://github.com/hashicorp/go-version If an invalid constraint string is specified, this function will always return false.

Types

type Config

type Config struct {
	// Name is a unique name for this Terraform module.
	Name string
	// BasePath is the base path to the Terraform code.
	BasePath string
	// ModulePath is the path to the module, relative to the basepath.
	ModulePath string
	// Remote is the Terraform remote configuration for this module.
	Remote conf.Remote
	// Variables is a map of the variable values for execution.
	Variables map[string]string
	// TerraformParameters is a list of additional Terraform command-line parameters
	TerraformParameters []string

	// TerraformPath is the path to the Terraform binary
	TerraformPath string

	// SharedPluginDir is the path to a directory that should contain shared
	// plugins.
	SharedPluginDir string
}

Config is the Terraform configuration required to initialize and run Terraform commands for a module.

func (Config) Validate

func (config Config) Validate() (errs error)

Validate validates the Terraform configuration is valid.

type PlanResult

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

PlanResult is the terraformResult of a Terraform plan.

func (*PlanResult) Changes

func (r *PlanResult) Changes() string

Changes returns the changes for this plan.

func (*PlanResult) HasChanges

func (r *PlanResult) HasChanges() bool

HasChanges returns whether this plan had changes or not.

func (PlanResult) Runtime

func (r PlanResult) Runtime() string

Runtime returns a human readable string with how long it took to run the command.

func (PlanResult) Stderr

func (r PlanResult) Stderr() string

Stderr returns the stderr for this execution.

func (PlanResult) Stdout

func (r PlanResult) Stdout() string

Stdout returns the stdout for this execution.

type Result

type Result interface {
	Runtime() string
	Stdout() string
	Stderr() string
}

Result is a generic interface that satisfies types returned by Terraform methods.

type Session

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

Session is a wrapper around Terraform commands. It ensures that all commands are run within the same working directory.

It also adds "auto init", meaning it will automatically run `terraform init` and `terraform get` as necessary before planning or applying.

func NewTerraformSession

func NewTerraformSession(id, baseDir string, config Config) (*Session, error)

NewTerraformSession creates a new Terraform session in the specified directory. It will return an error if a previous Terraform session was already created here.

func (*Session) Apply

func (s *Session) Apply() (Result, error)

Apply runs a `terraform apply`

func (*Session) Detach

func (s *Session) Detach() (Result, error)

Detach disables any connection to the remote state for the given module. If the module is not initialized, it does that first, and then disconnects it. This is so that Terraform first downloads the remote state locally. The purpose of Detach is to allow safe, local testing of changes to the state file, without pushing anything to the remote.

func (*Session) Get

func (s *Session) Get() (Result, error)

Get runs `terraform get`

func (*Session) Init

func (s *Session) Init() (Result, error)

Init initializes a Terraform module. This needs to happen before other commands like "plan" and "apply" can be called. See: https://www.terraform.io/docs/commands/init.html

func (*Session) InitLocal

func (s *Session) InitLocal() (Result, error)

InitLocal downloads the remote state files to the local session so that changes can be made to the state files locally without being pushed.

func (*Session) Initialized

func (s *Session) Initialized() bool

Initialized returns whether or not `terraform init` has been run.

func (*Session) Plan

func (s *Session) Plan() (Result, error)

Plan runs a `terraform plan`

func (*Session) SetTerraformPath

func (s *Session) SetTerraformPath(path string)

SetTerraformPath sets the path to Terraform.

func (*Session) Show

func (s *Session) Show(planFile string) (Result, error)

Show runs a `terraform show`.

func (*Session) Version

func (s *Session) Version() (*version.Version, error)

Version returns the version of Terraform that the binary identifies itself as.

Jump to

Keyboard shortcuts

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