terraformer

package
v1.7.1-0...-23dd39d Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2021 License: Apache-2.0, BSD-2-Clause, MIT, + 1 more Imports: 29 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"
)
View Source
const (
	// LabelKeyName is a key for label on a Terraformer Pod indicating the Terraformer name.
	LabelKeyName = "terraformer.gardener.cloud/name"
	// LabelKeyPurpose is a key for label on a Terraformer Pod indicating the Terraformer purpose.
	LabelKeyPurpose = "terraformer.gardener.cloud/purpose"
)
View Source
const (
	// CommandApply is a constant for the "apply" command.
	CommandApply = "apply"
	// CommandDestroy is a constant for the "destroy" command.
	CommandDestroy = "destroy"
)
View Source
const (

	// ConfigSuffix is the suffix used for the ConfigMap which stores the Terraform configuration and variables declaration.
	ConfigSuffix = ".tf-config"

	// VariablesSuffix is the suffix used for the Secret which stores the Terraform variables definition.
	VariablesSuffix = ".tf-vars"

	// StateSuffix is the suffix used for the ConfigMap which stores the Terraform state.
	StateSuffix = ".tf-state"

	// Base64Encoding denotes base64 encoding for the RawState.Data
	Base64Encoding = "base64"

	// NoneEncoding denotes none encoding for the RawState.Data
	NoneEncoding = "none"
)
View Source
const (
	// TerraformerFinalizer is the finalizer key set by the terraformer on the configmaps and secrets
	TerraformerFinalizer = "gardener.cloud/terraformer"
)

Variables

This section is empty.

Functions

func CreateOrUpdateConfigurationConfigMap

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

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

func CreateOrUpdateTFVarsSecret

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

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

func CreateState

func CreateState(ctx context.Context, c client.Client, namespace, name string, ownerRef *metav1.OwnerReference) error

CreateState create terraform state config map and use empty state. It does not create or update state ConfigMap if already exists,

func IsVariablesNotFoundError

func IsVariablesNotFoundError(err error) bool

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

Types

type CreateOrUpdateState

type CreateOrUpdateState struct {
	State *string
}

CreateOrUpdateState implements StateConfigMapInitializer. It use it field state for creating or updating the state ConfigMap

func (CreateOrUpdateState) Initialize

func (cus CreateOrUpdateState) Initialize(ctx context.Context, c client.Client, namespace, name string, ownerRef *metav1.OwnerReference) error

Initialize implements StateConfigMapInitializer

type Factory

type Factory interface {
	NewForConfig(logger logr.Logger, config *rest.Config, purpose, namespace, name, image string) (Terraformer, error)
	New(logger logr.Logger, client client.Client, coreV1Client corev1client.CoreV1Interface, purpose, namespace, name, image string) Terraformer
	DefaultInitializer(c client.Client, main, variables string, tfVars []byte, stateInitializer StateConfigMapInitializer) Initializer
}

Factory is a factory that can produce Terraformer and Initializer.

func DefaultFactory

func DefaultFactory() Factory

DefaultFactory returns the default factory.

type Initializer

type Initializer interface {
	Initialize(ctx context.Context, config *InitializerConfig, ownerRef *metav1.OwnerReference) error
}

Initializer can initialize a Terraformer.

func DefaultInitializer

func DefaultInitializer(c client.Client, main, variables string, tfvars []byte, stateInitializer StateConfigMapInitializer) 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 RawState

type RawState struct {
	Data     string `json:"data"`
	Encoding string `json:"encoding"`
}

RawState represent the terraformer state's raw data

func UnmarshalRawState

func UnmarshalRawState(rawState interface{}) (*RawState, error)

UnmarshalRawState transform passed rawState to RawState struct. It tries to decode the state

func (*RawState) Marshal

func (trs *RawState) Marshal() ([]byte, error)

Marshal transform RawState to []byte representation. It encodes the raw state data

type StateConfigMapInitializer

type StateConfigMapInitializer interface {
	Initialize(ctx context.Context, c client.Client, namespace, name string, ownerRef *metav1.OwnerReference) error
}

StateConfigMapInitializer initialize terraformer state ConfigMap

type StateConfigMapInitializerFunc

type StateConfigMapInitializerFunc func(ctx context.Context, c client.Client, namespace, name string, ownerRef *metav1.OwnerReference) error

StateConfigMapInitializerFunc implements StateConfigMapInitializer

func (StateConfigMapInitializerFunc) Initialize

func (f StateConfigMapInitializerFunc) Initialize(ctx context.Context, c client.Client, namespace, name string, ownerRef *metav1.OwnerReference) error

Initialize implements StateConfigMapInitializer

type TerraformFiles

type TerraformFiles struct {
	Main      string
	Variables string
	TFVars    []byte
}

TerraformFiles contains all files necessary for initializing a Terraformer.

func ExtractTerraformFiles

func ExtractTerraformFiles(release *chartrenderer.RenderedChart) (*TerraformFiles, error)

ExtractTerraformFiles extracts TerraformFiles from the given RenderedChart.

It errors if a file is not contained in the chart.

type Terraformer

type Terraformer interface {
	UseV2(bool) Terraformer
	SetLogLevel(string) Terraformer
	SetEnvVars(envVars ...corev1.EnvVar) Terraformer
	SetTerminationGracePeriodSeconds(int64) Terraformer
	SetDeadlineCleaning(time.Duration) Terraformer
	SetDeadlinePod(time.Duration) Terraformer
	SetOwnerRef(*metav1.OwnerReference) Terraformer
	InitializeWith(ctx context.Context, initializer Initializer) Terraformer
	Apply(ctx context.Context) error
	Destroy(ctx context.Context) error
	GetRawState(ctx context.Context) (*RawState, error)
	GetState(ctx context.Context) ([]byte, error)
	IsStateEmpty(ctx context.Context) bool
	CleanupConfiguration(ctx context.Context) error
	RemoveTerraformerFinalizerFromConfig(ctx context.Context) error
	GetStateOutputVariables(ctx context.Context, variables ...string) (map[string]string, error)
	ConfigExists(ctx context.Context) (bool, error)
	NumberOfResources(ctx context.Context) (int, error)
	EnsureCleanedUp(ctx context.Context) error
	WaitForCleanEnvironment(ctx context.Context) error
}

Terraformer is the Terraformer interface.

func New

func New(
	logger logr.Logger,
	c 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 interface 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 logr.Logger,
	config *rest.Config,
	purpose,
	namespace,
	name,
	image string,
) (
	Terraformer,
	error,
)

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

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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