2014-05-24 14:04:43 -05:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
// ResourceProvider is an interface that must be implemented by any
|
|
|
|
// resource provider: the thing that creates and manages the resources in
|
|
|
|
// a Terraform configuration.
|
|
|
|
type ResourceProvider interface {
|
2014-06-13 00:30:09 -05:00
|
|
|
// Validate is called once at the beginning with the raw configuration
|
|
|
|
// (no interpolation done) and can return a list of warnings and/or
|
|
|
|
// errors.
|
|
|
|
//
|
2014-07-02 22:35:03 -05:00
|
|
|
// This is called once with the provider configuration only. It may not
|
|
|
|
// be called at all if no provider configuration is given.
|
|
|
|
//
|
2014-06-13 00:30:09 -05:00
|
|
|
// This should not assume that any values of the configurations are valid.
|
|
|
|
// The primary use case of this call is to check that required keys are
|
|
|
|
// set.
|
|
|
|
Validate(*ResourceConfig) ([]string, []error)
|
|
|
|
|
2014-07-02 22:35:03 -05:00
|
|
|
// ValidateResource is called once at the beginning with the raw
|
|
|
|
// configuration (no interpolation done) and can return a list of warnings
|
|
|
|
// and/or errors.
|
|
|
|
//
|
|
|
|
// This is called once per resource.
|
|
|
|
//
|
|
|
|
// This should not assume any of the values in the resource configuration
|
|
|
|
// are valid since it is possible they have to be interpolated still.
|
|
|
|
// The primary use case of this call is to check that the required keys
|
|
|
|
// are set and that the general structure is correct.
|
|
|
|
ValidateResource(string, *ResourceConfig) ([]string, []error)
|
|
|
|
|
2014-05-24 14:04:43 -05:00
|
|
|
// Configure configures the provider itself with the configuration
|
|
|
|
// given. This is useful for setting things like access keys.
|
|
|
|
//
|
2014-07-02 22:35:03 -05:00
|
|
|
// This won't be called at all if no provider configuration is given.
|
|
|
|
//
|
2014-06-06 02:28:57 -05:00
|
|
|
// Configure returns an error if it occurred.
|
2014-06-12 19:59:59 -05:00
|
|
|
Configure(*ResourceConfig) error
|
2014-05-24 14:04:43 -05:00
|
|
|
|
|
|
|
// Resources returns all the available resource types that this provider
|
|
|
|
// knows how to manage.
|
2014-06-03 16:26:31 -05:00
|
|
|
Resources() []ResourceType
|
2014-06-03 18:42:21 -05:00
|
|
|
|
|
|
|
// Apply applies a diff to a specific resource and returns the new
|
|
|
|
// resource state along with an error.
|
|
|
|
//
|
|
|
|
// If the resource state given has an empty ID, then a new resource
|
|
|
|
// is expected to be created.
|
2014-06-18 17:35:03 -05:00
|
|
|
Apply(
|
|
|
|
*ResourceState,
|
|
|
|
*ResourceDiff) (*ResourceState, error)
|
2014-06-03 18:42:21 -05:00
|
|
|
|
|
|
|
// Diff diffs a resource versus a desired state and returns
|
|
|
|
// a diff.
|
|
|
|
Diff(
|
2014-06-05 09:27:01 -05:00
|
|
|
*ResourceState,
|
2014-06-12 19:59:59 -05:00
|
|
|
*ResourceConfig) (*ResourceDiff, error)
|
2014-06-19 23:22:07 -05:00
|
|
|
|
|
|
|
// Refresh refreshes a resource and updates all of its attributes
|
|
|
|
// with the latest information.
|
|
|
|
Refresh(*ResourceState) (*ResourceState, error)
|
2014-06-12 19:59:59 -05:00
|
|
|
}
|
|
|
|
|
2014-05-24 14:04:43 -05:00
|
|
|
// ResourceType is a type of resource that a resource provider can manage.
|
|
|
|
type ResourceType struct {
|
|
|
|
Name string
|
|
|
|
}
|
2014-05-28 15:56:43 -05:00
|
|
|
|
|
|
|
// ResourceProviderFactory is a function type that creates a new instance
|
|
|
|
// of a resource provider.
|
|
|
|
type ResourceProviderFactory func() (ResourceProvider, error)
|
2014-06-03 17:08:00 -05:00
|
|
|
|
2014-07-10 11:46:21 -05:00
|
|
|
// ResourceProviderFactoryFixed is a helper that creates a
|
|
|
|
// ResourceProviderFactory that just returns some fixed provider.
|
|
|
|
func ResourceProviderFactoryFixed(p ResourceProvider) ResourceProviderFactory {
|
|
|
|
return func() (ResourceProvider, error) {
|
|
|
|
return p, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-03 17:08:00 -05:00
|
|
|
func ProviderSatisfies(p ResourceProvider, n string) bool {
|
|
|
|
for _, rt := range p.Resources() {
|
|
|
|
if rt.Name == n {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|