terraform: add Diff to ResourceProvider

rpc and plugin don't compile yet
This commit is contained in:
Mitchell Hashimoto 2014-06-03 16:42:21 -07:00
parent 8af8ecca20
commit 9480783ee4
2 changed files with 50 additions and 0 deletions

View File

@ -13,6 +13,42 @@ type ResourceProvider interface {
// Resources returns all the available resource types that this provider
// knows how to manage.
Resources() []ResourceType
// 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.
//Apply(ResourceState, ResourceDiff) (ResourceState, error)
// Diff diffs a resource versus a desired state and returns
// a diff.
Diff(
ResourceState,
map[string]interface{}) (ResourceDiff, error)
}
// ResourceDiff is the diff of a resource from some state to another.
type ResourceDiff struct {
Attributes map[string]ResourceDiffAttribute
}
// ResourceDiffAttribute is the diff of a single attribute of a resource.
type ResourceDiffAttribute struct {
Old string
New string
RequiresNew bool
}
// ResourceState holds the state of a resource that is used so that
// a provider can find and manage an existing resource as well as for
// storing attributes that are uesd to populate variables of child
// resources.
type ResourceState struct {
Type string
ID string
Attributes map[string]string
Extra map[string]interface{}
}
// ResourceType is a type of resource that a resource provider can manage.

View File

@ -10,6 +10,11 @@ type MockResourceProvider struct {
ConfigureConfig map[string]interface{}
ConfigureReturnWarnings []string
ConfigureReturnError error
ResourceDiffCalled bool
ResourceDiffState ResourceState
ResourceDiffDesired map[string]interface{}
ResourceDiffReturn ResourceDiff
ResourceDiffReturnError error
ResourcesCalled bool
ResourcesReturn []ResourceType
}
@ -20,6 +25,15 @@ func (p *MockResourceProvider) Configure(c map[string]interface{}) ([]string, er
return p.ConfigureReturnWarnings, p.ConfigureReturnError
}
func (p *MockResourceProvider) Diff(
state ResourceState,
desired map[string]interface{}) (ResourceDiff, error) {
p.ResourceDiffCalled = true
p.ResourceDiffState = state
p.ResourceDiffDesired = desired
return p.ResourceDiffReturn, p.ResourceDiffReturnError
}
func (p *MockResourceProvider) Resources() []ResourceType {
p.ResourcesCalled = true
return p.ResourcesReturn