mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 18:01:01 -06:00
terraform: add ValidateResource API to ResourceProvider
This commit is contained in:
parent
770d4e1e71
commit
d0577fda02
@ -17,14 +17,31 @@ type ResourceProvider interface {
|
||||
// (no interpolation done) and can return a list of warnings and/or
|
||||
// errors.
|
||||
//
|
||||
// This is called once with the provider configuration only. It may not
|
||||
// be called at all if no provider configuration is given.
|
||||
//
|
||||
// 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)
|
||||
|
||||
// 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)
|
||||
|
||||
// Configure configures the provider itself with the configuration
|
||||
// given. This is useful for setting things like access keys.
|
||||
//
|
||||
// This won't be called at all if no provider configuration is given.
|
||||
//
|
||||
// Configure returns an error if it occurred.
|
||||
Configure(*ResourceConfig) error
|
||||
|
||||
|
@ -32,6 +32,11 @@ type MockResourceProvider struct {
|
||||
ValidateConfig *ResourceConfig
|
||||
ValidateReturnWarns []string
|
||||
ValidateReturnErrors []error
|
||||
ValidateResourceCalled bool
|
||||
ValidateResourceType string
|
||||
ValidateResourceConfig *ResourceConfig
|
||||
ValidateResourceReturnWarns []string
|
||||
ValidateResourceReturnErrors []error
|
||||
}
|
||||
|
||||
func (p *MockResourceProvider) Validate(c *ResourceConfig) ([]string, []error) {
|
||||
@ -40,6 +45,13 @@ func (p *MockResourceProvider) Validate(c *ResourceConfig) ([]string, []error) {
|
||||
return p.ValidateReturnWarns, p.ValidateReturnErrors
|
||||
}
|
||||
|
||||
func (p *MockResourceProvider) ValidateResource(t string, c *ResourceConfig) ([]string, []error) {
|
||||
p.ValidateResourceCalled = true
|
||||
p.ValidateResourceType = t
|
||||
p.ValidateResourceConfig = c
|
||||
return p.ValidateResourceReturnWarns, p.ValidateResourceReturnErrors
|
||||
}
|
||||
|
||||
func (p *MockResourceProvider) Configure(c *ResourceConfig) error {
|
||||
p.ConfigureCalled = true
|
||||
p.ConfigureConfig = c
|
||||
|
Loading…
Reference in New Issue
Block a user