aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/terraform/providers
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/providers')
-rw-r--r--vendor/github.com/hashicorp/terraform/providers/addressed_types.go47
-rw-r--r--vendor/github.com/hashicorp/terraform/providers/doc.go3
-rw-r--r--vendor/github.com/hashicorp/terraform/providers/provider.go351
-rw-r--r--vendor/github.com/hashicorp/terraform/providers/resolver.go112
4 files changed, 513 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/providers/addressed_types.go b/vendor/github.com/hashicorp/terraform/providers/addressed_types.go
new file mode 100644
index 0000000..7ed523f
--- /dev/null
+++ b/vendor/github.com/hashicorp/terraform/providers/addressed_types.go
@@ -0,0 +1,47 @@
1package providers
2
3import (
4 "sort"
5
6 "github.com/hashicorp/terraform/addrs"
7)
8
9// AddressedTypes is a helper that extracts all of the distinct provider
10// types from the given list of relative provider configuration addresses.
11func AddressedTypes(providerAddrs []addrs.ProviderConfig) []string {
12 if len(providerAddrs) == 0 {
13 return nil
14 }
15 m := map[string]struct{}{}
16 for _, addr := range providerAddrs {
17 m[addr.Type] = struct{}{}
18 }
19
20 names := make([]string, 0, len(m))
21 for typeName := range m {
22 names = append(names, typeName)
23 }
24
25 sort.Strings(names) // Stable result for tests
26 return names
27}
28
29// AddressedTypesAbs is a helper that extracts all of the distinct provider
30// types from the given list of absolute provider configuration addresses.
31func AddressedTypesAbs(providerAddrs []addrs.AbsProviderConfig) []string {
32 if len(providerAddrs) == 0 {
33 return nil
34 }
35 m := map[string]struct{}{}
36 for _, addr := range providerAddrs {
37 m[addr.ProviderConfig.Type] = struct{}{}
38 }
39
40 names := make([]string, 0, len(m))
41 for typeName := range m {
42 names = append(names, typeName)
43 }
44
45 sort.Strings(names) // Stable result for tests
46 return names
47}
diff --git a/vendor/github.com/hashicorp/terraform/providers/doc.go b/vendor/github.com/hashicorp/terraform/providers/doc.go
new file mode 100644
index 0000000..39aa1de
--- /dev/null
+++ b/vendor/github.com/hashicorp/terraform/providers/doc.go
@@ -0,0 +1,3 @@
1// Package providers contains the interface and primary types required to
2// implement a Terraform resource provider.
3package providers
diff --git a/vendor/github.com/hashicorp/terraform/providers/provider.go b/vendor/github.com/hashicorp/terraform/providers/provider.go
new file mode 100644
index 0000000..1aa08c2
--- /dev/null
+++ b/vendor/github.com/hashicorp/terraform/providers/provider.go
@@ -0,0 +1,351 @@
1package providers
2
3import (
4 "github.com/zclconf/go-cty/cty"
5
6 "github.com/hashicorp/terraform/configs/configschema"
7 "github.com/hashicorp/terraform/states"
8 "github.com/hashicorp/terraform/tfdiags"
9)
10
11// Interface represents the set of methods required for a complete resource
12// provider plugin.
13type Interface interface {
14 // GetSchema returns the complete schema for the provider.
15 GetSchema() GetSchemaResponse
16
17 // PrepareProviderConfig allows the provider to validate the configuration
18 // values, and set or override any values with defaults.
19 PrepareProviderConfig(PrepareProviderConfigRequest) PrepareProviderConfigResponse
20
21 // ValidateResourceTypeConfig allows the provider to validate the resource
22 // configuration values.
23 ValidateResourceTypeConfig(ValidateResourceTypeConfigRequest) ValidateResourceTypeConfigResponse
24
25 // ValidateDataSource allows the provider to validate the data source
26 // configuration values.
27 ValidateDataSourceConfig(ValidateDataSourceConfigRequest) ValidateDataSourceConfigResponse
28
29 // UpgradeResourceState is called when the state loader encounters an
30 // instance state whose schema version is less than the one reported by the
31 // currently-used version of the corresponding provider, and the upgraded
32 // result is used for any further processing.
33 UpgradeResourceState(UpgradeResourceStateRequest) UpgradeResourceStateResponse
34
35 // Configure configures and initialized the provider.
36 Configure(ConfigureRequest) ConfigureResponse
37
38 // Stop is called when the provider should halt any in-flight actions.
39 //
40 // Stop should not block waiting for in-flight actions to complete. It
41 // should take any action it wants and return immediately acknowledging it
42 // has received the stop request. Terraform will not make any further API
43 // calls to the provider after Stop is called.
44 //
45 // The error returned, if non-nil, is assumed to mean that signaling the
46 // stop somehow failed and that the user should expect potentially waiting
47 // a longer period of time.
48 Stop() error
49
50 // ReadResource refreshes a resource and returns its current state.
51 ReadResource(ReadResourceRequest) ReadResourceResponse
52
53 // PlanResourceChange takes the current state and proposed state of a
54 // resource, and returns the planned final state.
55 PlanResourceChange(PlanResourceChangeRequest) PlanResourceChangeResponse
56
57 // ApplyResourceChange takes the planned state for a resource, which may
58 // yet contain unknown computed values, and applies the changes returning
59 // the final state.
60 ApplyResourceChange(ApplyResourceChangeRequest) ApplyResourceChangeResponse
61
62 // ImportResourceState requests that the given resource be imported.
63 ImportResourceState(ImportResourceStateRequest) ImportResourceStateResponse
64
65 // ReadDataSource returns the data source's current state.
66 ReadDataSource(ReadDataSourceRequest) ReadDataSourceResponse
67
68 // Close shuts down the plugin process if applicable.
69 Close() error
70}
71
72type GetSchemaResponse struct {
73 // Provider is the schema for the provider itself.
74 Provider Schema
75
76 // ResourceTypes map the resource type name to that type's schema.
77 ResourceTypes map[string]Schema
78
79 // DataSources maps the data source name to that data source's schema.
80 DataSources map[string]Schema
81
82 // Diagnostics contains any warnings or errors from the method call.
83 Diagnostics tfdiags.Diagnostics
84}
85
86// Schema pairs a provider or resource schema with that schema's version.
87// This is used to be able to upgrade the schema in UpgradeResourceState.
88type Schema struct {
89 Version int64
90 Block *configschema.Block
91}
92
93type PrepareProviderConfigRequest struct {
94 // Config is the raw configuration value for the provider.
95 Config cty.Value
96}
97
98type PrepareProviderConfigResponse struct {
99 // PreparedConfig is the configuration as prepared by the provider.
100 PreparedConfig cty.Value
101 // Diagnostics contains any warnings or errors from the method call.
102 Diagnostics tfdiags.Diagnostics
103}
104
105type ValidateResourceTypeConfigRequest struct {
106 // TypeName is the name of the resource type to validate.
107 TypeName string
108
109 // Config is the configuration value to validate, which may contain unknown
110 // values.
111 Config cty.Value
112}
113
114type ValidateResourceTypeConfigResponse struct {
115 // Diagnostics contains any warnings or errors from the method call.
116 Diagnostics tfdiags.Diagnostics
117}
118
119type ValidateDataSourceConfigRequest struct {
120 // TypeName is the name of the data source type to validate.
121 TypeName string
122
123 // Config is the configuration value to validate, which may contain unknown
124 // values.
125 Config cty.Value
126}
127
128type ValidateDataSourceConfigResponse struct {
129 // Diagnostics contains any warnings or errors from the method call.
130 Diagnostics tfdiags.Diagnostics
131}
132
133type UpgradeResourceStateRequest struct {
134 // TypeName is the name of the resource type being upgraded
135 TypeName string
136
137 // Version is version of the schema that created the current state.
138 Version int64
139
140 // RawStateJSON and RawStateFlatmap contiain the state that needs to be
141 // upgraded to match the current schema version. Because the schema is
142 // unknown, this contains only the raw data as stored in the state.
143 // RawStateJSON is the current json state encoding.
144 // RawStateFlatmap is the legacy flatmap encoding.
145 // Only on of these fields may be set for the upgrade request.
146 RawStateJSON []byte
147 RawStateFlatmap map[string]string
148}
149
150type UpgradeResourceStateResponse struct {
151 // UpgradedState is the newly upgraded resource state.
152 UpgradedState cty.Value
153
154 // Diagnostics contains any warnings or errors from the method call.
155 Diagnostics tfdiags.Diagnostics
156}
157
158type ConfigureRequest struct {
159 // Terraform version is the version string from the running instance of
160 // terraform. Providers can use TerraformVersion to verify compatibility,
161 // and to store for informational purposes.
162 TerraformVersion string
163
164 // Config is the complete configuration value for the provider.
165 Config cty.Value
166}
167
168type ConfigureResponse struct {
169 // Diagnostics contains any warnings or errors from the method call.
170 Diagnostics tfdiags.Diagnostics
171}
172
173type ReadResourceRequest struct {
174 // TypeName is the name of the resource type being read.
175 TypeName string
176
177 // PriorState contains the previously saved state value for this resource.
178 PriorState cty.Value
179}
180
181type ReadResourceResponse struct {
182 // NewState contains the current state of the resource.
183 NewState cty.Value
184
185 // Diagnostics contains any warnings or errors from the method call.
186 Diagnostics tfdiags.Diagnostics
187}
188
189type PlanResourceChangeRequest struct {
190 // TypeName is the name of the resource type to plan.
191 TypeName string
192
193 // PriorState is the previously saved state value for this resource.
194 PriorState cty.Value
195
196 // ProposedNewState is the expected state after the new configuration is
197 // applied. This is created by directly applying the configuration to the
198 // PriorState. The provider is then responsible for applying any further
199 // changes required to create the proposed final state.
200 ProposedNewState cty.Value
201
202 // Config is the resource configuration, before being merged with the
203 // PriorState. Any value not explicitly set in the configuration will be
204 // null. Config is supplied for reference, but Provider implementations
205 // should prefer the ProposedNewState in most circumstances.
206 Config cty.Value
207
208 // PriorPrivate is the previously saved private data returned from the
209 // provider during the last apply.
210 PriorPrivate []byte
211}
212
213type PlanResourceChangeResponse struct {
214 // PlannedState is the expected state of the resource once the current
215 // configuration is applied.
216 PlannedState cty.Value
217
218 // RequiresReplace is the list of thee attributes that are requiring
219 // resource replacement.
220 RequiresReplace []cty.Path
221
222 // PlannedPrivate is an opaque blob that is not interpreted by terraform
223 // core. This will be saved and relayed back to the provider during
224 // ApplyResourceChange.
225 PlannedPrivate []byte
226
227 // Diagnostics contains any warnings or errors from the method call.
228 Diagnostics tfdiags.Diagnostics
229
230 // LegacyTypeSystem is set only if the provider is using the legacy SDK
231 // whose type system cannot be precisely mapped into the Terraform type
232 // system. We use this to bypass certain consistency checks that would
233 // otherwise fail due to this imprecise mapping. No other provider or SDK
234 // implementation is permitted to set this.
235 LegacyTypeSystem bool
236}
237
238type ApplyResourceChangeRequest struct {
239 // TypeName is the name of the resource type being applied.
240 TypeName string
241
242 // PriorState is the current state of resource.
243 PriorState cty.Value
244
245 // Planned state is the state returned from PlanResourceChange, and should
246 // represent the new state, minus any remaining computed attributes.
247 PlannedState cty.Value
248
249 // Config is the resource configuration, before being merged with the
250 // PriorState. Any value not explicitly set in the configuration will be
251 // null. Config is supplied for reference, but Provider implementations
252 // should prefer the PlannedState in most circumstances.
253 Config cty.Value
254
255 // PlannedPrivate is the same value as returned by PlanResourceChange.
256 PlannedPrivate []byte
257}
258
259type ApplyResourceChangeResponse struct {
260 // NewState is the new complete state after applying the planned change.
261 // In the event of an error, NewState should represent the most recent
262 // known state of the resource, if it exists.
263 NewState cty.Value
264
265 // Private is an opaque blob that will be stored in state along with the
266 // resource. It is intended only for interpretation by the provider itself.
267 Private []byte
268
269 // Diagnostics contains any warnings or errors from the method call.
270 Diagnostics tfdiags.Diagnostics
271
272 // LegacyTypeSystem is set only if the provider is using the legacy SDK
273 // whose type system cannot be precisely mapped into the Terraform type
274 // system. We use this to bypass certain consistency checks that would
275 // otherwise fail due to this imprecise mapping. No other provider or SDK
276 // implementation is permitted to set this.
277 LegacyTypeSystem bool
278}
279
280type ImportResourceStateRequest struct {
281 // TypeName is the name of the resource type to be imported.
282 TypeName string
283
284 // ID is a string with which the provider can identify the resource to be
285 // imported.
286 ID string
287}
288
289type ImportResourceStateResponse struct {
290 // ImportedResources contains one or more state values related to the
291 // imported resource. It is not required that these be complete, only that
292 // there is enough identifying information for the provider to successfully
293 // update the states in ReadResource.
294 ImportedResources []ImportedResource
295
296 // Diagnostics contains any warnings or errors from the method call.
297 Diagnostics tfdiags.Diagnostics
298}
299
300// ImportedResource represents an object being imported into Terraform with the
301// help of a provider. An ImportedObject is a RemoteObject that has been read
302// by the provider's import handler but hasn't yet been committed to state.
303type ImportedResource struct {
304 // TypeName is the name of the resource type associated with the
305 // returned state. It's possible for providers to import multiple related
306 // types with a single import request.
307 TypeName string
308
309 // State is the state of the remote object being imported. This may not be
310 // complete, but must contain enough information to uniquely identify the
311 // resource.
312 State cty.Value
313
314 // Private is an opaque blob that will be stored in state along with the
315 // resource. It is intended only for interpretation by the provider itself.
316 Private []byte
317}
318
319// AsInstanceObject converts the receiving ImportedObject into a
320// ResourceInstanceObject that has status ObjectReady.
321//
322// The returned object does not know its own resource type, so the caller must
323// retain the ResourceType value from the source object if this information is
324// needed.
325//
326// The returned object also has no dependency addresses, but the caller may
327// freely modify the direct fields of the returned object without affecting
328// the receiver.
329func (ir ImportedResource) AsInstanceObject() *states.ResourceInstanceObject {
330 return &states.ResourceInstanceObject{
331 Status: states.ObjectReady,
332 Value: ir.State,
333 Private: ir.Private,
334 }
335}
336
337type ReadDataSourceRequest struct {
338 // TypeName is the name of the data source type to Read.
339 TypeName string
340
341 // Config is the complete configuration for the requested data source.
342 Config cty.Value
343}
344
345type ReadDataSourceResponse struct {
346 // State is the current state of the requested data source.
347 State cty.Value
348
349 // Diagnostics contains any warnings or errors from the method call.
350 Diagnostics tfdiags.Diagnostics
351}
diff --git a/vendor/github.com/hashicorp/terraform/providers/resolver.go b/vendor/github.com/hashicorp/terraform/providers/resolver.go
new file mode 100644
index 0000000..4de8e0a
--- /dev/null
+++ b/vendor/github.com/hashicorp/terraform/providers/resolver.go
@@ -0,0 +1,112 @@
1package providers
2
3import (
4 "fmt"
5
6 "github.com/hashicorp/terraform/plugin/discovery"
7)
8
9// Resolver is an interface implemented by objects that are able to resolve
10// a given set of resource provider version constraints into Factory
11// callbacks.
12type Resolver interface {
13 // Given a constraint map, return a Factory for each requested provider.
14 // If some or all of the constraints cannot be satisfied, return a non-nil
15 // slice of errors describing the problems.
16 ResolveProviders(reqd discovery.PluginRequirements) (map[string]Factory, []error)
17}
18
19// ResolverFunc wraps a callback function and turns it into a Resolver
20// implementation, for convenience in situations where a function and its
21// associated closure are sufficient as a resolver implementation.
22type ResolverFunc func(reqd discovery.PluginRequirements) (map[string]Factory, []error)
23
24// ResolveProviders implements Resolver by calling the
25// wrapped function.
26func (f ResolverFunc) ResolveProviders(reqd discovery.PluginRequirements) (map[string]Factory, []error) {
27 return f(reqd)
28}
29
30// ResolverFixed returns a Resolver that has a fixed set of provider factories
31// provided by the caller. The returned resolver ignores version constraints
32// entirely and just returns the given factory for each requested provider
33// name.
34//
35// This function is primarily used in tests, to provide mock providers or
36// in-process providers under test.
37func ResolverFixed(factories map[string]Factory) Resolver {
38 return ResolverFunc(func(reqd discovery.PluginRequirements) (map[string]Factory, []error) {
39 ret := make(map[string]Factory, len(reqd))
40 var errs []error
41 for name := range reqd {
42 if factory, exists := factories[name]; exists {
43 ret[name] = factory
44 } else {
45 errs = append(errs, fmt.Errorf("provider %q is not available", name))
46 }
47 }
48 return ret, errs
49 })
50}
51
52// Factory is a function type that creates a new instance of a resource
53// provider, or returns an error if that is impossible.
54type Factory func() (Interface, error)
55
56// FactoryFixed is a helper that creates a Factory that just returns some given
57// single provider.
58//
59// Unlike usual factories, the exact same instance is returned for each call
60// to the factory and so this must be used in only specialized situations where
61// the caller can take care to either not mutate the given provider at all
62// or to mutate it in ways that will not cause unexpected behavior for others
63// holding the same reference.
64func FactoryFixed(p Interface) Factory {
65 return func() (Interface, error) {
66 return p, nil
67 }
68}
69
70// ProviderHasResource is a helper that requests schema from the given provider
71// and checks if it has a resource type of the given name.
72//
73// This function is more expensive than it may first appear since it must
74// retrieve the entire schema from the underlying provider, and so it should
75// be used sparingly and especially not in tight loops.
76//
77// Since retrieving the provider may fail (e.g. if the provider is accessed
78// over an RPC channel that has operational problems), this function will
79// return false if the schema cannot be retrieved, under the assumption that
80// a subsequent call to do anything with the resource type would fail
81// anyway.
82func ProviderHasResource(provider Interface, typeName string) bool {
83 resp := provider.GetSchema()
84 if resp.Diagnostics.HasErrors() {
85 return false
86 }
87
88 _, exists := resp.ResourceTypes[typeName]
89 return exists
90}
91
92// ProviderHasDataSource is a helper that requests schema from the given
93// provider and checks if it has a data source of the given name.
94//
95// This function is more expensive than it may first appear since it must
96// retrieve the entire schema from the underlying provider, and so it should
97// be used sparingly and especially not in tight loops.
98//
99// Since retrieving the provider may fail (e.g. if the provider is accessed
100// over an RPC channel that has operational problems), this function will
101// return false if the schema cannot be retrieved, under the assumption that
102// a subsequent call to do anything with the data source would fail
103// anyway.
104func ProviderHasDataSource(provider Interface, dataSourceName string) bool {
105 resp := provider.GetSchema()
106 if resp.Diagnostics.HasErrors() {
107 return false
108 }
109
110 _, exists := resp.DataSources[dataSourceName]
111 return exists
112}