terraform: ResourceProvider (shadow) ValidateResource

This commit is contained in:
Mitchell Hashimoto 2016-10-05 19:05:08 -07:00
parent 3edb8599b1
commit 24456c042a
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
1 changed files with 40 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package terraform
import ( import (
"fmt" "fmt"
"io" "io"
"log"
"sync" "sync"
"github.com/hashicorp/go-multierror" "github.com/hashicorp/go-multierror"
@ -102,6 +103,45 @@ func (p *shadowResourceProviderReal) Configure(c *ResourceConfig) error {
return err return err
} }
func (p *shadowResourceProviderReal) ValidateResource(
t string, c *ResourceConfig) ([]string, []error) {
key := t
// Real operation
warns, errs := p.ResourceProvider.ValidateResource(t, c)
// Get the result
raw, ok := p.Shared.ValidateResource.ValueOk(key)
if !ok {
raw = new(shadowResourceProviderValidateResourceWrapper)
}
wrapper, ok := raw.(*shadowResourceProviderValidateResourceWrapper)
if !ok {
// If this fails then we just continue with our day... the shadow
// will fail to but there isn't much we can do.
log.Printf(
"[ERROR] unknown value in ValidateResource shadow value: %#v", raw)
return warns, errs
}
// Lock the wrapper for writing and record our call
wrapper.Lock()
defer wrapper.Unlock()
wrapper.Calls = append(wrapper.Calls, &shadowResourceProviderValidateResource{
Config: c,
Warns: warns,
Errors: errs,
})
// Set it
p.Shared.ValidateResource.SetValue(key, wrapper)
// Return the result
return warns, errs
}
func (p *shadowResourceProviderReal) Apply( func (p *shadowResourceProviderReal) Apply(
info *InstanceInfo, info *InstanceInfo,
state *InstanceState, state *InstanceState,