-
Notifications
You must be signed in to change notification settings - Fork 37
/
types.go
91 lines (77 loc) · 3.11 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// SPDX-FileCopyrightText: 2020 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package terraformer
import (
"github.com/go-logr/logr"
"go.uber.org/zap/zapcore"
"k8s.io/client-go/rest"
"k8s.io/client-go/util/workqueue"
"k8s.io/utils/clock"
"sigs.k8s.io/controller-runtime/pkg/client"
)
// Command is a terraform command
type Command string
// known terraform commands
const (
// Init is the terraform `init` command.
Init Command = "init"
// Apply is the terraform `apply` command.
Apply Command = "apply"
// Destroy is the terraform `destroy` command.
Destroy Command = "destroy"
// Validate is the terraform `validate` command.
Validate Command = "validate"
// Plan is the terraform `plan` command.
Plan Command = "plan"
// StateReplaceProvider is the terraform `state` command with the `replace-provider` subcommand.
StateReplaceProvider Command = "state replace-provider"
)
const (
// TerraformerFinalizer is the finalizer used by the terraformer on the terraform configmaps and secrets
TerraformerFinalizer = "gardener.cloud/terraformer"
)
// SupportedCommands contains the set of supported terraform commands, that can be run as `terraformer <command>`.
var SupportedCommands = map[Command]struct{}{
Apply: {},
Destroy: {},
Validate: {},
}
// Terraformer can execute terraform commands and fetch/store config and state from/into Secrets/ConfigMaps
type Terraformer struct {
config *Config
paths *PathSet
log logr.Logger
client client.Client
// StateUpdateQueue is the queue in which file watch events are inserted to trigger a state update.
// It is also used for triggering the final state update.
StateUpdateQueue workqueue.RateLimitingInterface
// FinalStateUpdateSucceeded is a channel over which a value will be send by the state update worker
// to signal that the final state update has succeeded and terraformer can safely exit.
FinalStateUpdateSucceeded chan struct{}
// clock allows faking some time operations in tests
clock clock.Clock
}
// Config holds configuration options for Terraformer.
type Config struct {
// ConfigurationConfigMapName is the name of the ConfigMap that holds the `main.tf` and `variables.tf` files.
ConfigurationConfigMapName string
// StateConfigMapName is the name of the ConfigMap that the `terraform.tfstate` file should be stored in.
StateConfigMapName string
// VariablesSecretName is the name of the Secret that holds the `terraform.tfvars` file.
VariablesSecretName string
// Namespace is the namespace to store the configuration resources in.
Namespace string
// RESTConfig holds the completed rest.Config.
RESTConfig *rest.Config
// BaseDir is the base directory to be used for all terraform files (defaults to '/').
BaseDir string
}
// MarshalLogObject implements zapcore.ObjectMarshaler.
func (c *Config) MarshalLogObject(enc zapcore.ObjectEncoder) error {
enc.AddString("configurationConfigMapName", c.ConfigurationConfigMapName)
enc.AddString("stateConfigMapName", c.StateConfigMapName)
enc.AddString("variablesSecretName", c.VariablesSecretName)
enc.AddString("namespace", c.Namespace)
return nil
}