terraform

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AKSCluster added in v0.1.5

type AKSCluster struct {
	ResourceGroup string
	Cluster       string
	Action        Action
	// KubeconfigRaw contains the kubeconfig of a (to be) deleted cluster.
	KubeconfigRaw string
}

AKSCluster represents an AKS Cluster change.

func ClustersFromPlan added in v0.1.5

func ClustersFromPlan(plan *gabs.Container) ([]AKSCluster, error)

ClustersFromPlan parses a plan and returns AKSClusters that are going to be created, updated or deleted. The plan json conforms to https://www.terraform.io/docs/internals/json-format.html

type AKSPool

type AKSPool struct {
	ResourceGroup string
	Cluster       string
	Pool          string
	MinCount      int
	MaxCount      int
	Action        Action
}

AKSPool represents an AKS Node pool change.

func PoolsFromPlan added in v0.1.5

func PoolsFromPlan(plan *gabs.Container) ([]AKSPool, error)

PoolsFromPlan parses a plan and returns AKS Pools that are going to be created, updated or deleted. The plan json conforms to https://www.terraform.io/docs/internals/json-format.html

type Action

type Action int

Action is the terraform plan action.

const (
	ActionCreate Action = 1 << iota
	ActionUpdate
	ActionDelete
)

type TFApplyResult

type TFApplyResult struct {
	// Running count of the number of objects that have started creating, modifying and destroying.
	Creating, Modifying, Destroying int

	// Errors is a list of error messages.
	Errors []string

	// Number of object added, changed, destroyed upon completion.
	// The numbers are non-zero when terraform completed successfully.
	TotalAdded, TotalChanged, TotalDestroyed int

	// Most recently logged terraform object name.
	Object string
	// Most recently logged action being performed; creating (creation), modifying (modification), destroying (destruction).
	// *ing means in-progress, *tion means completed.
	Action string
	// Most recently logged elapsed time reported by terraform.
	Elapsed string

	// Text is the verbatim output of the command.
	// NB every TFApplyResult instance holds a string with all lines known at that time.
	Text string
}

TFApplyResult

type TFResult

type TFResult struct {
	// Info > 0 and Errors == 0 means the command is successful.
	Info int
	// Warnings > 0 means command successful but something unexpected happened.
	Warnings int

	// Errors is a list of error messages.
	// len > 0 means the command failed.
	Errors []string

	PlanAdded   int
	PlanChanged int
	PlanDeleted int

	// Text is the verbatim output of the command.
	Text string
}

TFResults is the output of a terraform command.

type Terraform

type Terraform struct{}

Terraform provisions infrastructure using terraform cli.

func (*Terraform) GetPlan added in v0.1.5

func (t *Terraform) GetPlan(ctx context.Context, env []string, dir string) (*gabs.Container, error)

GetPlan reads an existing plan and returns a json structure.

func (*Terraform) Init

func (t *Terraform) Init(ctx context.Context, env []string, dir string) *TFResult

Init resolves (downloads) dependencies for the terraform configuration files in dir.

func (*Terraform) Output

func (t *Terraform) Output(ctx context.Context, env []string, dir string) (map[string]interface{}, error)

Output gets terraform output values an returns them as a map of types and values. When outputs.tf contains output "xyz" { value = 7 } the returned map contains ["yxz"]["value"] == 7

func (*Terraform) Plan

func (t *Terraform) Plan(ctx context.Context, env []string, dir string) *TFResult

Plan creates an execution plan for the terraform configuration files in dir.

func (*Terraform) StartApply

func (t *Terraform) StartApply(ctx context.Context, env []string, dir string) (*exec.Cmd, chan TFApplyResult, error)

StartApply applies the plan in dir without waiting for completion. If a Cmd is returned cmd.Wait() should be called wait for completion and clean-up.

func (*Terraform) StartDestroy

func (t *Terraform) StartDestroy(ctx context.Context, env []string, dir string) (*exec.Cmd, chan TFApplyResult, error)

StartDestroy destroys the resources specified in the plan in dir without waiting for completion. If a Cmd is returned cmd.Wait() should be called wait for completion and clean-up.

type TerraformFake

type TerraformFake struct {
	// Tally is the number of times Init, Plan, Apply has been called.
	InitTally, PlanTally, ApplyTally, DestroyTally, OutputTally, GetPlanTally int

	// Results that are returned by the fake implementations of Init or Plan.
	InitResult, PlanResult TFResult

	// Result that is played back by the fake implementation of StartApply.
	ApplyResult, DestroyResult []TFApplyResult

	// OutputResult is the parsed JSON output of terraform output.
	OutputResult map[string]interface{}

	// ShowPlanResult is the result of terraform show plan.
	ShowPlanResult string

	// Log
	Log logr.Logger
}

TerraformFake provides a Terraformer for testing.

func (*TerraformFake) GetPlan added in v0.1.5

func (t *TerraformFake) GetPlan(ctx context.Context, env []string, dir string) (*gabs.Container, error)

GetPlanPools reads an existing plan and returns AKSPools that are going to be updated or deleted.

func (*TerraformFake) Init

func (t *TerraformFake) Init(ctx context.Context, env []string, dir string) *TFResult

Init implements Terraformer.

func (*TerraformFake) Output

func (t *TerraformFake) Output(ctx context.Context, env []string, dir string) (map[string]interface{}, error)

Output implements Terraformer.

func (*TerraformFake) Plan

func (t *TerraformFake) Plan(ctx context.Context, env []string, dir string) *TFResult

Plan implements Terraformer.

func (*TerraformFake) SetupFakeResultsForCreate added in v0.1.6

func (t *TerraformFake) SetupFakeResultsForCreate(clusters map[string]interface{})

SetupFakeResultsForCreate makes the fake replay a successful create. If clusters == nil it defaults to:

map[string]interface{}{
	"mycluster": map[string]interface{}{
		"kube_admin_config": map[string]interface{}{
			"client_certificate":     string with base64 encoded value,
			"client_key":             <idem>,
			"cluster_ca_certificate": <idem>,
			"host":                   "https://api.kubernetes.example.com:443",
			"password":               "4ee5bb2",
			"username":               "someadmin",
		},
	},
},

func (*TerraformFake) SetupFakeResultsForDeleteCluster added in v0.1.6

func (t *TerraformFake) SetupFakeResultsForDeleteCluster()

SetupFakeResultsForDeleteCluster makes the fake replay a situation where a cluster is being removed.

func (*TerraformFake) SetupFakeResultsForFailedDestroy added in v0.1.6

func (t *TerraformFake) SetupFakeResultsForFailedDestroy()

SetupFakeResultsForFailedDestroy makes the fake replay failed destroy.

func (*TerraformFake) SetupFakeResultsForNothingToDo added in v0.1.6

func (t *TerraformFake) SetupFakeResultsForNothingToDo()

SetupFakeResultsForNothingToDo makes the fake replay a situation where terraform plan reports nothing to do.

func (*TerraformFake) SetupFakeResultsForSuccessfulDestroy added in v0.1.6

func (t *TerraformFake) SetupFakeResultsForSuccessfulDestroy()

SetupFakeResultsForSuccessfulDestroy makes the fake replay a successful destroy.

func (*TerraformFake) StartApply

func (t *TerraformFake) StartApply(ctx context.Context, env []string, dir string) (*exec.Cmd, chan TFApplyResult, error)

StartApply implements Terraformer.

func (*TerraformFake) StartDestroy

func (t *TerraformFake) StartDestroy(ctx context.Context, env []string, dir string) (*exec.Cmd, chan TFApplyResult, error)

StartDestroy implements Terraformer.

type Terraformer

type Terraformer interface {
	// Init resolves (downloads) dependencies for the terraform configuration files in dir.
	Init(ctx context.Context, env []string, dir string) *TFResult
	// Plan creates an execution plan for the terraform configuration files in dir.
	Plan(ctx context.Context, env []string, dir string) *TFResult
	// StartApply applies the plan in dir without waiting for completion.
	// If a Cmd is returned cmd.Wait() should be called wait for completion and clean-up.
	StartApply(ctx context.Context, env []string, dir string) (*exec.Cmd, chan TFApplyResult, error)
	// StartDestroy destroys the resources specified in the plan in dir without waiting for completion.
	// If a Cmd is returned cmd.Wait() should be called wait for completion and clean-up.
	StartDestroy(ctx context.Context, env []string, dir string) (*exec.Cmd, chan TFApplyResult, error)
	// Output gets terraform output values an returns them as a map of types and values.
	// When outputs.tf contains output "xyz" { value = 7 } the returned map contains ["yxz"]["value"] == 7
	Output(ctx context.Context, env []string, dir string) (map[string]interface{}, error)
	// GetPlan reads an existing plan and returns a json structure.
	GetPlan(ctx context.Context, env []string, dir string) (*gabs.Container, error)
}

Terraformer is able to provision infrastructure.

Jump to

Keyboard shortcuts

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