helper/schema: Provider implements ResourceProvider

This commit is contained in:
Mitchell Hashimoto 2014-08-17 20:23:25 -07:00
parent c418681cc3
commit d321240042
2 changed files with 39 additions and 0 deletions

View File

@ -75,6 +75,41 @@ func (p *Provider) Configure(c *terraform.ResourceConfig) error {
return nil return nil
} }
// Apply implementation of terraform.ResourceProvider interface.
func (p *Provider) Apply(
s *terraform.ResourceState,
d *terraform.ResourceDiff) (*terraform.ResourceState, error) {
r, ok := p.ResourcesMap[s.Type]
if !ok {
return nil, fmt.Errorf("unknown resource type: %s", s.Type)
}
return r.Apply(s, d, p.meta)
}
// Diff implementation of terraform.ResourceProvider interface.
func (p *Provider) Diff(
s *terraform.ResourceState,
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
r, ok := p.ResourcesMap[s.Type]
if !ok {
return nil, fmt.Errorf("unknown resource type: %s", s.Type)
}
return r.Diff(s, c)
}
// Refresh implementation of terraform.ResourceProvider interface.
func (p *Provider) Refresh(
s *terraform.ResourceState) (*terraform.ResourceState, error) {
r, ok := p.ResourcesMap[s.Type]
if !ok {
return nil, fmt.Errorf("unknown resource type: %s", s.Type)
}
return r.Refresh(s, p.meta)
}
// Resources implementation of terraform.ResourceProvider interface. // Resources implementation of terraform.ResourceProvider interface.
func (p *Provider) Resources() []terraform.ResourceType { func (p *Provider) Resources() []terraform.ResourceType {
keys := make([]string, 0, len(p.ResourcesMap)) keys := make([]string, 0, len(p.ResourcesMap))

View File

@ -9,6 +9,10 @@ import (
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
func TestProvider_impl(t *testing.T) {
var _ terraform.ResourceProvider = new(Provider)
}
func TestProviderConfigure(t *testing.T) { func TestProviderConfigure(t *testing.T) {
cases := []struct { cases := []struct {
P *Provider P *Provider