Documentation ¶
Index ¶
- type AKSCluster
- type AKSPool
- type Action
- type TFApplyResult
- type TFResult
- type Terraform
- func (t *Terraform) GetPlan(ctx context.Context, env []string, dir string) (*gabs.Container, error)
- func (t *Terraform) Init(ctx context.Context, env []string, dir string) *TFResult
- func (t *Terraform) Output(ctx context.Context, env []string, dir string) (map[string]interface{}, error)
- func (t *Terraform) Plan(ctx context.Context, env []string, dir string) *TFResult
- func (t *Terraform) StartApply(ctx context.Context, env []string, dir string) (*exec.Cmd, chan TFApplyResult, error)
- func (t *Terraform) StartDestroy(ctx context.Context, env []string, dir string) (*exec.Cmd, chan TFApplyResult, error)
- type TerraformFake
- func (t *TerraformFake) GetPlan(ctx context.Context, env []string, dir string) (*gabs.Container, error)
- func (t *TerraformFake) Init(ctx context.Context, env []string, dir string) *TFResult
- func (t *TerraformFake) Output(ctx context.Context, env []string, dir string) (map[string]interface{}, error)
- func (t *TerraformFake) Plan(ctx context.Context, env []string, dir string) *TFResult
- func (t *TerraformFake) SetupFakeResultsForCreate(clusters map[string]interface{})
- func (t *TerraformFake) SetupFakeResultsForDeleteCluster()
- func (t *TerraformFake) SetupFakeResultsForFailedDestroy()
- func (t *TerraformFake) SetupFakeResultsForNothingToDo()
- func (t *TerraformFake) SetupFakeResultsForSuccessfulDestroy()
- func (t *TerraformFake) StartApply(ctx context.Context, env []string, dir string) (*exec.Cmd, chan TFApplyResult, error)
- func (t *TerraformFake) StartDestroy(ctx context.Context, env []string, dir string) (*exec.Cmd, chan TFApplyResult, error)
- type Terraformer
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
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 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
GetPlan reads an existing plan and returns a json structure.
func (*Terraform) Init ¶
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 ¶
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) Output ¶
func (t *TerraformFake) Output(ctx context.Context, env []string, dir string) (map[string]interface{}, error)
Output 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.