remove legacy provisioner types

This commit is contained in:
James Bardin 2020-11-13 12:43:28 -05:00
parent 811a3a81e9
commit 8a325ea54b
11 changed files with 41 additions and 203 deletions

View File

@ -1864,7 +1864,7 @@ func TestContext2Apply_cancelProvisioner(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -2302,7 +2302,7 @@ func TestContext2Apply_provisionerInterpCount(t *testing.T) {
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
}
provisioners := map[string]ProvisionerFactory{
provisioners := map[string]provisioners.Factory{
"local-exec": testProvisionerFuncFixed(pr),
}
ctx := testContext2(t, &ContextOpts{
@ -4086,7 +4086,7 @@ func TestContext2Apply_provisionerModule(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -4135,7 +4135,7 @@ func TestContext2Apply_Provisioner_compute(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
Variables: InputValues{
@ -4193,7 +4193,7 @@ func TestContext2Apply_provisionerCreateFail(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -4230,7 +4230,7 @@ func TestContext2Apply_provisionerCreateFailNoId(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -4267,7 +4267,7 @@ func TestContext2Apply_provisionerFail(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -4315,7 +4315,7 @@ func TestContext2Apply_provisionerFail_createBeforeDestroy(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
State: state,
@ -4666,7 +4666,7 @@ func TestContext2Apply_provisionerFailContinue(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -4714,7 +4714,7 @@ func TestContext2Apply_provisionerFailContinueHook(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -4768,7 +4768,7 @@ func TestContext2Apply_provisionerDestroy(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -4820,7 +4820,7 @@ func TestContext2Apply_provisionerDestroyFail(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -4889,7 +4889,7 @@ func TestContext2Apply_provisionerDestroyFailContinue(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -4959,7 +4959,7 @@ func TestContext2Apply_provisionerDestroyFailContinueFail(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -5026,7 +5026,7 @@ func TestContext2Apply_provisionerDestroyTainted(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
Variables: InputValues{
@ -5087,7 +5087,7 @@ func TestContext2Apply_provisionerResourceRef(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -5133,7 +5133,7 @@ func TestContext2Apply_provisionerSelfRef(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -5186,7 +5186,7 @@ func TestContext2Apply_provisionerMultiSelfRef(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -5246,7 +5246,7 @@ func TestContext2Apply_provisionerMultiSelfRefSingle(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -5301,7 +5301,7 @@ func TestContext2Apply_provisionerExplicitSelfRef(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -5330,7 +5330,7 @@ func TestContext2Apply_provisionerExplicitSelfRef(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -5370,7 +5370,7 @@ func TestContext2Apply_provisionerForEachSelfRef(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -5397,7 +5397,7 @@ func TestContext2Apply_Provisioner_Diff(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -5445,7 +5445,7 @@ func TestContext2Apply_Provisioner_Diff(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
State: state,
@ -6250,7 +6250,7 @@ func TestContext2Apply_destroyTaintedProvisioner(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
State: state,
@ -9834,7 +9834,7 @@ func TestContext2Apply_plannedConnectionRefs(t *testing.T) {
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
}
provisioners := map[string]ProvisionerFactory{
provisioners := map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
}
@ -12194,7 +12194,7 @@ func TestContext2Apply_provisionerSensitive(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
Variables: InputValues{

View File

@ -26,7 +26,7 @@ type contextComponentFactory interface {
// basicComponentFactory just calls a factory from a map directly.
type basicComponentFactory struct {
providers map[addrs.Provider]providers.Factory
provisioners map[string]ProvisionerFactory
provisioners map[string]provisioners.Factory
}
func (c *basicComponentFactory) ResourceProviders() []string {

View File

@ -32,7 +32,7 @@ func simpleMockComponentFactory() *basicComponentFactory {
return provider, nil
},
},
provisioners: map[string]ProvisionerFactory{
provisioners: map[string]provisioners.Factory{
"test": func() (provisioners.Interface, error) {
return provisioner, nil
},

View File

@ -7,6 +7,7 @@ import (
"github.com/hashicorp/terraform/configs"
"github.com/hashicorp/terraform/configs/configschema"
"github.com/hashicorp/terraform/providers"
"github.com/hashicorp/terraform/provisioners"
"github.com/zclconf/go-cty/cty"
)
@ -16,7 +17,7 @@ import (
type contextTestFixture struct {
Config *configs.Config
Providers map[addrs.Provider]providers.Factory
Provisioners map[string]ProvisionerFactory
Provisioners map[string]provisioners.Factory
}
// ContextOpts returns a ContextOps pre-populated with the elements of this

View File

@ -20,6 +20,7 @@ import (
"github.com/hashicorp/terraform/configs/hcl2shim"
"github.com/hashicorp/terraform/plans"
"github.com/hashicorp/terraform/providers"
"github.com/hashicorp/terraform/provisioners"
"github.com/hashicorp/terraform/states"
"github.com/hashicorp/terraform/tfdiags"
)
@ -930,7 +931,7 @@ func TestContext2Plan_moduleOrphansWithProvisioner(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
State: state,
@ -1654,7 +1655,7 @@ func TestContext2Plan_provisionerCycle(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"local-exec": testProvisionerFuncFixed(pr),
},
})

View File

@ -709,7 +709,7 @@ func TestContext2Validate_provisionerConfig_bad(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -744,7 +744,7 @@ func TestContext2Validate_badResourceConnection(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -776,7 +776,7 @@ func TestContext2Validate_badProvisionerConnection(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -822,7 +822,7 @@ func TestContext2Validate_provisionerConfig_good(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
})
@ -983,7 +983,7 @@ func TestContext2Validate_targetedDestroy(t *testing.T) {
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Provisioners: map[string]ProvisionerFactory{
Provisioners: map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
},
State: state,

View File

@ -1,15 +1,9 @@
package terraform
import (
"testing"
"github.com/hashicorp/terraform/provisioners"
)
func TestMockResourceProvisioner_impl(t *testing.T) {
var _ ResourceProvisioner = new(MockResourceProvisioner)
}
// simpleMockProvisioner returns a MockProvisioner that is pre-configured
// with schema for its own config, with the same content as returned by
// function simpleTestSchema.

View File

@ -1,69 +0,0 @@
package terraform
import (
"github.com/hashicorp/terraform/configs/configschema"
"github.com/hashicorp/terraform/provisioners"
)
// ResourceProvisioner is an interface that must be implemented by any
// resource provisioner: the thing that initializes resources in
// a Terraform configuration.
type ResourceProvisioner interface {
// GetConfigSchema returns the schema for the provisioner type's main
// configuration block. This is called prior to Validate to enable some
// basic structural validation to be performed automatically and to allow
// the configuration to be properly extracted from potentially-ambiguous
// configuration file formats.
GetConfigSchema() (*configschema.Block, error)
// Validate 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.
Validate(*ResourceConfig) ([]string, []error)
// Apply runs the provisioner on a specific resource and returns an error.
// Instead of a diff, the ResourceConfig is provided since provisioners
// only run after a resource has been newly created.
Apply(UIOutput, *InstanceState, *ResourceConfig) error
// Stop is called when the provisioner should halt any in-flight actions.
//
// This can be used to make a nicer Ctrl-C experience for Terraform.
// Even if this isn't implemented to do anything (just returns nil),
// Terraform will still cleanly stop after the currently executing
// graph node is complete. However, this API can be used to make more
// efficient halts.
//
// Stop doesn't have to and shouldn't block waiting for in-flight actions
// to complete. It should take any action it wants and return immediately
// acknowledging it has received the stop request. Terraform core will
// automatically not make any further API calls to the provider soon
// after Stop is called (technically exactly once the currently executing
// graph nodes are complete).
//
// The error returned, if non-nil, is assumed to mean that signaling the
// stop somehow failed and that the user should expect potentially waiting
// a longer period of time.
Stop() error
}
// ResourceProvisionerCloser is an interface that provisioners that can close
// connections that aren't needed anymore must implement.
type ResourceProvisionerCloser interface {
Close() error
}
// ResourceProvisionerFactory is a function type that creates a new instance
// of a resource provisioner.
type ResourceProvisionerFactory func() (ResourceProvisioner, error)
// ProvisionerFactory is a function type that creates a new instance
// of a provisioners.Interface.
type ProvisionerFactory = provisioners.Factory

View File

@ -1,87 +0,0 @@
package terraform
import (
"sync"
"github.com/hashicorp/terraform/configs/configschema"
)
// MockResourceProvisioner implements ResourceProvisioner but mocks out all the
// calls for testing purposes.
type MockResourceProvisioner struct {
sync.Mutex
// Anything you want, in case you need to store extra data with the mock.
Meta interface{}
GetConfigSchemaCalled bool
GetConfigSchemaReturnSchema *configschema.Block
GetConfigSchemaReturnError error
ApplyCalled bool
ApplyOutput UIOutput
ApplyState *InstanceState
ApplyConfig *ResourceConfig
ApplyFn func(*InstanceState, *ResourceConfig) error
ApplyReturnError error
ValidateCalled bool
ValidateConfig *ResourceConfig
ValidateFn func(c *ResourceConfig) ([]string, []error)
ValidateReturnWarns []string
ValidateReturnErrors []error
StopCalled bool
StopFn func() error
StopReturnError error
}
var _ ResourceProvisioner = (*MockResourceProvisioner)(nil)
func (p *MockResourceProvisioner) GetConfigSchema() (*configschema.Block, error) {
p.GetConfigSchemaCalled = true
return p.GetConfigSchemaReturnSchema, p.GetConfigSchemaReturnError
}
func (p *MockResourceProvisioner) Validate(c *ResourceConfig) ([]string, []error) {
p.Lock()
defer p.Unlock()
p.ValidateCalled = true
p.ValidateConfig = c
if p.ValidateFn != nil {
return p.ValidateFn(c)
}
return p.ValidateReturnWarns, p.ValidateReturnErrors
}
func (p *MockResourceProvisioner) Apply(
output UIOutput,
state *InstanceState,
c *ResourceConfig) error {
p.Lock()
p.ApplyCalled = true
p.ApplyOutput = output
p.ApplyState = state
p.ApplyConfig = c
if p.ApplyFn != nil {
fn := p.ApplyFn
p.Unlock()
return fn(state, c)
}
defer p.Unlock()
return p.ApplyReturnError
}
func (p *MockResourceProvisioner) Stop() error {
p.Lock()
defer p.Unlock()
p.StopCalled = true
if p.StopFn != nil {
return p.StopFn()
}
return p.StopReturnError
}

View File

@ -205,9 +205,7 @@ func loadProvisionerSchemas(schemas map[string]*configschema.Block, config *conf
return
}
defer func() {
if closer, ok := provisioner.(ResourceProvisionerCloser); ok {
closer.Close()
}
provisioner.Close()
}()
resp := provisioner.GetSchema()

View File

@ -228,7 +228,7 @@ func testProviderFuncFixed(rp providers.Interface) providers.Factory {
}
}
func testProvisionerFuncFixed(rp provisioners.Interface) ProvisionerFactory {
func testProvisionerFuncFixed(rp provisioners.Interface) provisioners.Factory {
return func() (provisioners.Interface, error) {
return rp, nil
}