-
Notifications
You must be signed in to change notification settings - Fork 41
/
shim.go
174 lines (141 loc) · 4.05 KB
/
shim.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package shim
import (
"time"
)
type ResourceConfig interface {
IsSet(k string) bool
}
type InstanceState interface {
Type() string
ID() string
Object(sch SchemaMap) (map[string]interface{}, error)
Meta() map[string]interface{}
}
type DiffAttrType byte
const (
DiffAttrUnknown DiffAttrType = iota
DiffAttrInput
DiffAttrOutput
)
type ResourceAttrDiff struct {
Old string
New string
NewComputed bool
NewRemoved bool
NewExtra interface{}
RequiresNew bool
Sensitive bool
Type DiffAttrType
}
type InstanceDiff interface {
Attribute(key string) *ResourceAttrDiff
Attributes() map[string]ResourceAttrDiff
ProposedState(res Resource, priorState InstanceState) (InstanceState, error)
Destroy() bool
RequiresNew() bool
IgnoreChanges(ignored map[string]bool)
EncodeTimeouts(timeouts *ResourceTimeout) error
SetTimeout(timeout float64, timeoutKey string)
}
type ValueType int
const (
TypeInvalid ValueType = iota
TypeBool
TypeInt
TypeFloat
TypeString
TypeList
TypeMap
TypeSet
)
type SchemaDefaultFunc func() (interface{}, error)
type SchemaStateFunc func(interface{}) string
type Schema interface {
Type() ValueType
Optional() bool
Required() bool
Default() interface{}
DefaultFunc() SchemaDefaultFunc
DefaultValue() (interface{}, error)
Description() string
Computed() bool
ForceNew() bool
StateFunc() SchemaStateFunc
// s.Elem() may return a nil, a Schema value, or a Resource value.
//
// If s represents an element or block of a compound type such TypeList, TypeSet or TypeMap, s.Elem() returns a
// Schema value representing its element type. That is, if s ~ List[String] then s.Elem() ~ String.
//
// If s.Elem() returns a Resource, s represens a configuration block, and s.Elem() Resource only implements the
// Schema field, denoting the schema of the block.
//
// The design of Elem() follows Terraform Plugin SDK directly.
//
// See also: https://github.com/hashicorp/terraform-plugin-sdk/blob/main/helper/schema/schema.go#L231
Elem() interface{}
MaxItems() int
MinItems() int
ConflictsWith() []string
ExactlyOneOf() []string
Deprecated() string
Removed() string
Sensitive() bool
UnknownValue() interface{}
SetElement(config interface{}) (interface{}, error)
SetHash(v interface{}) int
}
type SchemaMap interface {
Len() int
Get(key string) Schema
GetOk(key string) (Schema, bool)
Range(each func(key string, value Schema) bool)
Set(key string, value Schema)
Delete(key string)
}
type ImportFunc func(t, id string, meta interface{}) ([]InstanceState, error)
const (
TimeoutCreate = "create"
TimeoutRead = "read"
TimeoutUpdate = "update"
TimeoutDelete = "delete"
TimeoutDefault = "default"
)
type ResourceTimeout struct {
Create, Read, Update, Delete, Default *time.Duration
}
type Resource interface {
Schema() SchemaMap
SchemaVersion() int
Importer() ImportFunc
DeprecationMessage() string
Timeouts() *ResourceTimeout
InstanceState(id string, object, meta map[string]interface{}) (InstanceState, error)
DecodeTimeouts(config ResourceConfig) (*ResourceTimeout, error)
}
type ResourceMap interface {
Len() int
Get(key string) Resource
GetOk(key string) (Resource, bool)
Range(each func(key string, value Resource) bool)
Set(key string, value Resource)
}
type Provider interface {
Schema() SchemaMap
ResourcesMap() ResourceMap
DataSourcesMap() ResourceMap
Validate(c ResourceConfig) ([]string, []error)
ValidateResource(t string, c ResourceConfig) ([]string, []error)
ValidateDataSource(t string, c ResourceConfig) ([]string, []error)
Configure(c ResourceConfig) error
Diff(t string, s InstanceState, c ResourceConfig) (InstanceDiff, error)
Apply(t string, s InstanceState, d InstanceDiff) (InstanceState, error)
Refresh(t string, s InstanceState) (InstanceState, error)
ReadDataDiff(t string, c ResourceConfig) (InstanceDiff, error)
ReadDataApply(t string, d InstanceDiff) (InstanceState, error)
Meta() interface{}
Stop() error
InitLogging()
NewDestroyDiff() InstanceDiff
NewResourceConfig(object map[string]interface{}) ResourceConfig
IsSet(v interface{}) ([]interface{}, bool)
}