terraform: add Diff to ResourceProvider
rpc and plugin don't compile yet
This commit is contained in:
parent
8af8ecca20
commit
9480783ee4
|
@ -13,6 +13,42 @@ type ResourceProvider interface {
|
||||||
// Resources returns all the available resource types that this provider
|
// Resources returns all the available resource types that this provider
|
||||||
// knows how to manage.
|
// knows how to manage.
|
||||||
Resources() []ResourceType
|
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.
|
// ResourceType is a type of resource that a resource provider can manage.
|
||||||
|
|
|
@ -10,6 +10,11 @@ type MockResourceProvider struct {
|
||||||
ConfigureConfig map[string]interface{}
|
ConfigureConfig map[string]interface{}
|
||||||
ConfigureReturnWarnings []string
|
ConfigureReturnWarnings []string
|
||||||
ConfigureReturnError error
|
ConfigureReturnError error
|
||||||
|
ResourceDiffCalled bool
|
||||||
|
ResourceDiffState ResourceState
|
||||||
|
ResourceDiffDesired map[string]interface{}
|
||||||
|
ResourceDiffReturn ResourceDiff
|
||||||
|
ResourceDiffReturnError error
|
||||||
ResourcesCalled bool
|
ResourcesCalled bool
|
||||||
ResourcesReturn []ResourceType
|
ResourcesReturn []ResourceType
|
||||||
}
|
}
|
||||||
|
@ -20,6 +25,15 @@ func (p *MockResourceProvider) Configure(c map[string]interface{}) ([]string, er
|
||||||
return p.ConfigureReturnWarnings, p.ConfigureReturnError
|
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 {
|
func (p *MockResourceProvider) Resources() []ResourceType {
|
||||||
p.ResourcesCalled = true
|
p.ResourcesCalled = true
|
||||||
return p.ResourcesReturn
|
return p.ResourcesReturn
|
||||||
|
|
Loading…
Reference in New Issue