opentofu/terraform/context_components.go
Kristin Laemmert e3416124cc
addrs: replace "Type string" with "Type Provider" in ProviderConfig
* huge change to weave new addrs.Provider into addrs.ProviderConfig
* terraform: do not include an empty string in the returned Providers /
Provisioners
- Fixed a minor bug where results included an extra empty string
2019-12-06 08:00:18 -05:00

69 lines
2.0 KiB
Go

package terraform
import (
"fmt"
"github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/providers"
"github.com/hashicorp/terraform/provisioners"
)
// contextComponentFactory is the interface that Context uses
// to initialize various components such as providers and provisioners.
// This factory gets more information than the raw maps using to initialize
// a Context. This information is used for debugging.
type contextComponentFactory interface {
// ResourceProvider creates a new ResourceProvider with the given
// type. The "uid" is a unique identifier for this provider being
// initialized that can be used for internal tracking.
ResourceProvider(typ, uid string) (providers.Interface, error)
ResourceProviders() []string
// ResourceProvisioner creates a new ResourceProvisioner with the
// given type. The "uid" is a unique identifier for this provisioner
// being initialized that can be used for internal tracking.
ResourceProvisioner(typ, uid string) (provisioners.Interface, error)
ResourceProvisioners() []string
}
// basicComponentFactory just calls a factory from a map directly.
type basicComponentFactory struct {
providers map[addrs.Provider]providers.Factory
provisioners map[string]ProvisionerFactory
}
func (c *basicComponentFactory) ResourceProviders() []string {
var result []string
for k := range c.providers {
result = append(result, k.LegacyString())
}
return result
}
func (c *basicComponentFactory) ResourceProvisioners() []string {
var result []string
for k := range c.provisioners {
result = append(result, k)
}
return result
}
func (c *basicComponentFactory) ResourceProvider(typ, uid string) (providers.Interface, error) {
f, ok := c.providers[addrs.NewLegacyProvider(typ)]
if !ok {
return nil, fmt.Errorf("unknown provider %q", typ)
}
return f()
}
func (c *basicComponentFactory) ResourceProvisioner(typ, uid string) (provisioners.Interface, error) {
f, ok := c.provisioners[typ]
if !ok {
return nil, fmt.Errorf("unknown provisioner %q", typ)
}
return f()
}