terraformer

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2020 License: Apache-2.0, MIT Imports: 26 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 (
	// TerraformerLabelKeyName is a key for label on a Terraformer Pod indicating the Terraformer name.
	TerraformerLabelKeyName = "terraformer.gardener.cloud/name"
	// TerraformerLabelKeyPurpose is a key for label on a Terraformer Pod indicating the Terraformer purpose.
	TerraformerLabelKeyPurpose = "terraformer.gardener.cloud/purpose"
)
View Source
const (

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

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

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

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

	// NoneEncoding denotes none encoding for the RawState.Data
	NoneEncoding = "none"
)

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 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 CreateStateConfigMap

func CreateStateConfigMap(ctx context.Context, c client.Client, namespace, name, state string) error

CreateStateConfigMap creates the Terraformer state ConfigMap with the given state.

func GenerateVariablesEnvironment

func GenerateVariablesEnvironment(secret *corev1.Secret, keyValueMap map[string]string) map[string]string

GenerateVariablesEnvironment takes a <secret> and a <keyValueMap> and builds an environment which can be injected into the Terraformer pod manifest. The keys of the <keyValueMap> will be prefixed with 'TF_VAR_' and the value will be used to extract the respective data from the <secret>.

func IsVariablesNotFoundError

func IsVariablesNotFoundError(err error) bool

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

Types

type Factory

type Factory interface {
	NewForConfig(logger logrus.FieldLogger, config *rest.Config, purpose, namespace, name, image string) (Terraformer, error)
	New(logger logrus.FieldLogger, client client.Client, coreV1Client corev1client.CoreV1Interface, purpose, namespace, name, image string) Terraformer
	DefaultInitializer(c client.Client, main, variables string, tfVars []byte, state string) 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(config *InitializerConfig) error
}

Initializer can initialize a Terraformer.

func DefaultInitializer

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

DefaultInitializer is an Initializer that initializes the configuration, variables and state resources based on the given main, variables, tfvars and state 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 Terraformer

type Terraformer interface {
	SetVariablesEnvironment(tfVarsEnvironment map[string]string) Terraformer
	SetTerminationGracePeriodSeconds(int64) Terraformer
	SetDeadlineCleaning(time.Duration) Terraformer
	SetDeadlinePod(time.Duration) Terraformer
	InitializeWith(initializer Initializer) Terraformer
	Apply() error
	Destroy() error
	GetRawState(context.Context) (*RawState, error)
	GetState() ([]byte, error)
	IsStateEmpty() bool
	CleanupConfiguration(ctx context.Context) error
	GetStateOutputVariables(variables ...string) (map[string]string, error)
	ConfigExists() (bool, error)
	NumberOfResources(context.Context) (int, error)
}

Terraformer is the Terraformer interface.

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 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 logrus.FieldLogger,
	config *rest.Config,
	purpose,
	namespace,
	name,
	image string,
) (Terraformer, error)

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

Jump to

Keyboard shortcuts

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