forked from cloudfoundry/bosh-bootloader
-
Notifications
You must be signed in to change notification settings - Fork 2
/
terraform_executor.go
133 lines (119 loc) · 2.97 KB
/
terraform_executor.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package fakes
import "github.com/cloudfoundry/bosh-bootloader/storage"
type Import struct {
Addr string
ID string
}
type TerraformExecutor struct {
ApplyCall struct {
CallCount int
Receives struct {
Inputs map[string]string
Template string
TFState string
}
Returns struct {
TFState string
Error error
}
}
DestroyCall struct {
CallCount int
Receives struct {
Inputs map[string]string
Template string
TFState string
}
Returns struct {
TFState string
Error error
}
}
ImportCall struct {
CallCount int
Receives struct {
TFState string
Imports []Import
Creds storage.AWS
}
Returns struct {
TFState string
Error error
}
}
VersionCall struct {
CallCount int
Returns struct {
Version string
Error error
}
}
OutputCall struct {
Stub func(string) (string, error)
CallCount int
Receives struct {
TFState string
OutputName string
}
Returns struct {
Output string
Error error
}
}
OutputsCall struct {
Stub func() (map[string]interface{}, error)
CallCount int
Receives struct {
TFState string
}
Returns struct {
Outputs map[string]interface{}
Error error
}
}
}
func (t *TerraformExecutor) Apply(inputs map[string]string, template, tfState string) (string, error) {
t.ApplyCall.CallCount++
t.ApplyCall.Receives.Inputs = inputs
t.ApplyCall.Receives.Template = template
t.ApplyCall.Receives.TFState = tfState
return t.ApplyCall.Returns.TFState, t.ApplyCall.Returns.Error
}
func (t *TerraformExecutor) Destroy(inputs map[string]string, template, tfState string) (string, error) {
t.DestroyCall.CallCount++
t.DestroyCall.Receives.Inputs = inputs
t.DestroyCall.Receives.Template = template
t.DestroyCall.Receives.TFState = tfState
return t.DestroyCall.Returns.TFState, t.DestroyCall.Returns.Error
}
func (t *TerraformExecutor) Import(addr, id, tfstate string, creds storage.AWS) (string, error) {
t.ImportCall.CallCount++
t.ImportCall.Receives.Imports = append(t.ImportCall.Receives.Imports, Import{
Addr: addr,
ID: id,
})
t.ImportCall.Receives.TFState = tfstate
t.ImportCall.Receives.Creds = creds
return t.ImportCall.Returns.TFState, t.ImportCall.Returns.Error
}
func (t *TerraformExecutor) Version() (string, error) {
t.VersionCall.CallCount++
return t.VersionCall.Returns.Version, t.VersionCall.Returns.Error
}
func (t *TerraformExecutor) Output(tfState, outputName string) (string, error) {
t.OutputCall.CallCount++
t.OutputCall.Receives.TFState = tfState
t.OutputCall.Receives.OutputName = outputName
if t.OutputCall.Stub != nil {
return t.OutputCall.Stub(outputName)
}
return t.OutputCall.Returns.Output, t.OutputCall.Returns.Error
}
func (t *TerraformExecutor) Outputs(tfState string) (map[string]interface{}, error) {
t.OutputsCall.CallCount++
t.OutputsCall.Receives.TFState = tfState
if t.OutputsCall.Stub != nil {
return t.OutputsCall.Stub()
}
return t.OutputsCall.Returns.Outputs, t.OutputsCall.Returns.Error
}