From a2a37ae40daaa6c300994224295c2a824d8775bc Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Sat, 29 Sep 2018 09:14:33 -0700 Subject: [PATCH] provisioners: Add Factory type and FactoryFixed helper These are similar to the symbols of the same name in package "providers". terraform.ProvisionerFactory is now an alias for provisioners.Factory, so we can defer updating all of the existing users of it. --- provisioners/factory.go | 19 +++++++++++++++++++ terraform/resource_provisioner.go | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 provisioners/factory.go diff --git a/provisioners/factory.go b/provisioners/factory.go new file mode 100644 index 000000000..590b97a84 --- /dev/null +++ b/provisioners/factory.go @@ -0,0 +1,19 @@ +package provisioners + +// Factory is a function type that creates a new instance of a resource +// provisioner, or returns an error if that is impossible. +type Factory func() (Interface, error) + +// FactoryFixed is a helper that creates a Factory that just returns some given +// single provisioner. +// +// Unlike usual factories, the exact same instance is returned for each call +// to the factory and so this must be used in only specialized situations where +// the caller can take care to either not mutate the given provider at all +// or to mutate it in ways that will not cause unexpected behavior for others +// holding the same reference. +func FactoryFixed(p Interface) Factory { + return func() (Interface, error) { + return p, nil + } +} diff --git a/terraform/resource_provisioner.go b/terraform/resource_provisioner.go index d40262aeb..2743dd7e9 100644 --- a/terraform/resource_provisioner.go +++ b/terraform/resource_provisioner.go @@ -67,4 +67,4 @@ type ResourceProvisionerFactory func() (ResourceProvisioner, error) // ProvisionerFactory is a function type that creates a new instance // of a provisioners.Interface. -type ProvisionerFactory func() (provisioners.Interface, error) +type ProvisionerFactory = provisioners.Factory