terraformer

package
v0.0.0-...-be4dc66 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2019 License: Apache-2.0, BSD-2-Clause, MIT, + 1 more Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MainKey is the key of the main.tf file inside the configuration ConfigMap.
	MainKey = "main.tf"
	// VariablesKey is the key of the variables.tf file inside the configuration ConfigMap.
	VariablesKey = "variables.tf"
	// TFVarsKey is the key of the terraform.tfvars file inside the variables Secret.
	TFVarsKey = "terraform.tfvars"
	// StateKey is the key of the terraform.tfstate file inside the state ConfigMap.
	StateKey = "terraform.tfstate"
)

Variables

This section is empty.

Functions

func CreateOrUpdateConfigurationConfigMap

func CreateOrUpdateConfigurationConfigMap(ctx context.Context, c client.Client, namespace, name, main, variables string) (*corev1.ConfigMap, error)

CreateOrUpdateConfigurationConfigMap creates or updates the Terraform configuration ConfigMap with the given main and variables content.

func CreateOrUpdateStateConfigMap

func CreateOrUpdateStateConfigMap(ctx context.Context, c client.Client, namespace, name, state string) (*corev1.ConfigMap, error)

CreateOrUpdateStateConfigMap creates or updates the Terraformer state ConfigMap with the given state.

func CreateOrUpdateTFVarsSecret

func CreateOrUpdateTFVarsSecret(ctx context.Context, c client.Client, namespace, name string, tfvars []byte) (*corev1.Secret, error)

CreateOrUpdateTFVarsSecret creates or updates the Terraformer variables Secret with the given tfvars.

func IsVariablesNotFoundError

func IsVariablesNotFoundError(err error) bool

IsVariablesNotFoundError returns true if the error indicates that not all variables have been found.

Types

type Initializer

type Initializer func(config *InitializerConfig) error

Initializer is a function that is called from the Terraformer to initialize its configuration.

func DefaultInitializer

func DefaultInitializer(c client.Client, main, variables string, tfvars []byte) Initializer

DefaultInitializer is an Initializer that initializes the configuration, variables and state resources based on the given main, variables and tfvars content and on the given InitializerConfig.

type InitializerConfig

type InitializerConfig struct {
	// Namespace is the namespace where all the resources required for the Terraformer shall be
	// deployed.
	Namespace string
	// ConfigurationName is the desired name of the configuration ConfigMap.
	ConfigurationName string
	// VariablesName is the desired name of the variables Secret.
	VariablesName string
	// StateName is the desired name of the state ConfigMap.
	StateName string
	// InitializeState specifies whether an empty state should be initialized or not.
	InitializeState bool
}

InitializerConfig is the configuration about the location and naming of the resources the Terraformer expects.

type Terraformer

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

Terraformer is a struct containing configuration parameters for the Terraform script it acts on.

  • purpose is a one-word description depicting what the Terraformer does (e.g. 'infrastructure').
  • namespace is the namespace in which the Terraformer will act.
  • image is the Docker image name of the Terraformer image.
  • configName is the name of the ConfigMap containing the main Terraform file ('main.tf').
  • variablesName is the name of the Secret containing the Terraform variables ('terraform.tfvars').
  • stateName is the name of the ConfigMap containing the Terraform state ('terraform.tfstate').
  • podName is the name of the Pod which will validate the Terraform file.
  • jobName is the name of the Job which will execute the Terraform file.
  • variablesEnvironment is a map of environment variables which will be injected in the resulting Terraform job/pod. These variables should contain Terraform variables (i.e., must be prefixed with TF_VAR_).
  • configurationDefined indicates whether the required configuration ConfigMaps/Secrets have been successfully defined.

func New

func New(
	logger logrus.FieldLogger,
	client client.Client,
	coreV1Client corev1client.CoreV1Interface,
	purpose,
	namespace,
	name,
	image string,
) *Terraformer

New takes a <logger>, a <k8sClient>, a string <purpose>, which describes for what the Terraformer is used, a <name>, a <namespace> in which the Terraformer will run, and the <image> name for the to-be-used Docker image. It returns a Terraformer struct with initialized values for the namespace and the names which will be used for all the stored resources like ConfigMaps/Secrets.

func NewForConfig

func NewForConfig(
	logger logrus.FieldLogger,
	config *rest.Config,
	purpose,
	namespace,
	name,
	image string,
) (*Terraformer, error)

NewForConfig creates a new Terraformer and its dependencies from the given configuration.

func (*Terraformer) Apply

func (t *Terraformer) Apply() error

Apply executes the Terraform Job by running the 'terraform apply' command.

func (*Terraformer) ConfigExists

func (t *Terraformer) ConfigExists() (bool, error)

ConfigExists returns true if all three Terraform configuration secrets/configmaps exist, and false otherwise.

func (*Terraformer) Destroy

func (t *Terraformer) Destroy() error

Destroy executes the Terraform Job by running the 'terraform destroy' command.

func (*Terraformer) GetState

func (t *Terraformer) GetState() ([]byte, error)

GetState returns the Terraform state as byte slice.

func (*Terraformer) GetStateOutputVariables

func (t *Terraformer) GetStateOutputVariables(variables ...string) (map[string]string, error)

GetStateOutputVariables returns the given <variable> from the given Terraform <stateData>. In case the variable was not found, an error is returned.

func (*Terraformer) InitializeWith

func (t *Terraformer) InitializeWith(initializer Initializer) *Terraformer

InitializeWith initializes the Terraformer with the given Initializer. It is expected from the Initializer to correctly create all the resources as specified in the given InitializerConfig. A default implementation can be found in DefaultInitializer.

func (*Terraformer) SetVariablesEnvironment

func (t *Terraformer) SetVariablesEnvironment(tfvarsEnvironment map[string]string) *Terraformer

SetVariablesEnvironment sets the provided <tfvarsEnvironment> on the Terraformer object.

Jump to

Keyboard shortcuts

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