github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/provisioners/factory.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package provisioners
     5  
     6  // Factory is a function type that creates a new instance of a resource
     7  // provisioner, or returns an error if that is impossible.
     8  type Factory func() (Interface, error)
     9  
    10  // FactoryFixed is a helper that creates a Factory that just returns some given
    11  // single provisioner.
    12  //
    13  // Unlike usual factories, the exact same instance is returned for each call
    14  // to the factory and so this must be used in only specialized situations where
    15  // the caller can take care to either not mutate the given provider at all
    16  // or to mutate it in ways that will not cause unexpected behavior for others
    17  // holding the same reference.
    18  func FactoryFixed(p Interface) Factory {
    19  	return func() (Interface, error) {
    20  		return p, nil
    21  	}
    22  }