forked from cloudfoundry/bosh-bootloader
/
validate.go
43 lines (34 loc) · 993 Bytes
/
validate.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
package commands
import (
"errors"
"github.com/cloudfoundry/bosh-bootloader/storage"
)
type Validate struct {
plan plan
stateStore stateStore
terraformManager terraformManager
}
func NewValidate(plan plan, stateStore stateStore, terraformManager terraformManager) Validate {
return Validate{
plan: plan,
stateStore: stateStore,
terraformManager: terraformManager,
}
}
func (v Validate) CheckFastFails(args []string, state storage.State) error {
return v.plan.CheckFastFails(args, state)
}
func (v Validate) Execute(args []string, state storage.State) error {
if !v.plan.IsInitialized(state) {
return errors.New("bbl state has not been initialized yet, please run bbl plan")
}
err := v.terraformManager.Init(state)
if err != nil {
return handleTerraformError(err, state, v.stateStore)
}
state, err = v.terraformManager.Validate(state)
if err != nil {
return handleTerraformError(err, state, v.stateStore)
}
return nil
}