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