forked from camptocamp/terraboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate.go
92 lines (81 loc) · 1.92 KB
/
state.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
package state
import (
"time"
"github.com/camptocamp/terraboard/config"
"github.com/camptocamp/terraboard/internal/terraform/states/statefile"
log "github.com/sirupsen/logrus"
)
// LockInfo stores information on a State Lock
type LockInfo struct {
ID string
Operation string
Info string
Who string
Version string
Created *time.Time
Path string
}
// Lock is a single State Lock
type Lock struct {
LockID string
Info string
}
// Version is a handler for state versions
type Version struct {
ID string
LastModified time.Time
}
// Provider is an interface for supported state providers
type Provider interface {
GetLocks() (map[string]LockInfo, error)
GetVersions(string) ([]Version, error)
GetStates() ([]string, error)
GetState(string, string) (*statefile.File, error)
}
// Configure the state provider
func Configure(c *config.Config) ([]Provider, error) {
var providers []Provider
if len(c.TFE) > 0 {
objs, err := NewTFECollection(c)
if err != nil {
return []Provider{}, err
}
if len(objs) > 0 {
log.Info("Using Terraform Enterprise as state/locks provider")
for _, tfeObj := range objs {
providers = append(providers, tfeObj)
}
}
}
if len(c.GCP) > 0 {
objs, err := NewGCPCollection(c)
if err != nil {
return []Provider{}, err
}
if len(objs) > 0 {
log.Info("Using Google Cloud as state/locks provider")
for _, gcpObj := range objs {
providers = append(providers, gcpObj)
}
}
}
if len(c.Gitlab) > 0 {
objs := NewGitlabCollection(c)
if len(objs) > 0 {
log.Info("Using Gitab as state/locks provider")
for _, glObj := range objs {
providers = append(providers, glObj)
}
}
}
if len(c.AWS) > 0 {
objs := NewAWSCollection(c)
if len(objs) > 0 {
log.Info("Using AWS (S3+DynamoDB) as state/locks provider")
for _, awsObj := range objs {
providers = append(providers, awsObj)
}
}
}
return providers, nil
}