prune ResourceProviderFullName and its callers

This commit is contained in:
Alex Pilon 2019-07-18 15:24:34 -04:00
parent b143c04216
commit c2bc88fc23
No known key found for this signature in database
GPG Key ID: 95659F6AEFC48D7E
4 changed files with 0 additions and 127 deletions

View File

@ -252,35 +252,6 @@ func (r *Resource) Id() string {
}
}
// ProviderFullName returns the full name of the provider for this resource,
// which may either be specified explicitly using the "provider" meta-argument
// or implied by the prefix on the resource type name.
func (r *Resource) ProviderFullName() string {
return ResourceProviderFullName(r.Type, r.Provider)
}
// ResourceProviderFullName returns the full (dependable) name of the
// provider for a hypothetical resource with the given resource type and
// explicit provider string. If the explicit provider string is empty then
// the provider name is inferred from the resource type name.
func ResourceProviderFullName(resourceType, explicitProvider string) string {
if explicitProvider != "" {
// check for an explicit provider name, or return the original
parts := strings.SplitAfter(explicitProvider, "provider.")
return parts[len(parts)-1]
}
idx := strings.IndexRune(resourceType, '_')
if idx == -1 {
// If no underscores, the resource name is assumed to be
// also the provider name, e.g. if the provider exposes
// only a single resource of each type.
return resourceType
}
return resourceType[:idx]
}
// Validate does some basic semantic checking of the configuration.
func (c *Config) Validate() tfdiags.Diagnostics {
if c == nil {

View File

@ -795,56 +795,6 @@ func TestConfigProviderVersion(t *testing.T) {
}
}
func TestResourceProviderFullName(t *testing.T) {
type testCase struct {
ResourceName string
Alias string
Expected string
}
tests := []testCase{
{
// If no alias is provided, the first underscore-separated segment
// is assumed to be the provider name.
ResourceName: "aws_thing",
Alias: "",
Expected: "aws",
},
{
// If we have more than one underscore then it's the first one that we'll use.
ResourceName: "aws_thingy_thing",
Alias: "",
Expected: "aws",
},
{
// A provider can export a resource whose name is just the bare provider name,
// e.g. because the provider only has one resource and so any additional
// parts would be redundant.
ResourceName: "external",
Alias: "",
Expected: "external",
},
{
// Alias always overrides the default extraction of the name
ResourceName: "aws_thing",
Alias: "tls.baz",
Expected: "tls.baz",
},
}
for _, test := range tests {
got := ResourceProviderFullName(test.ResourceName, test.Alias)
if got != test.Expected {
t.Errorf(
"(%q, %q) produced %q; want %q",
test.ResourceName, test.Alias,
got,
test.Expected,
)
}
}
}
func TestConfigModuleProviders(t *testing.T) {
c := testConfig(t, "module-providers")

View File

@ -13,48 +13,6 @@ type ProviderVersionConstraint struct {
// ProviderVersionConstraint, as produced by Config.RequiredProviders.
type ProviderVersionConstraints map[string]ProviderVersionConstraint
// RequiredProviders returns the ProviderVersionConstraints for this
// module.
//
// This includes both providers that are explicitly requested by provider
// blocks and those that are used implicitly by instantiating one of their
// resource types. In the latter case, the returned semver Range will
// accept any version of the provider.
func (c *Config) RequiredProviders() ProviderVersionConstraints {
ret := make(ProviderVersionConstraints, len(c.ProviderConfigs))
configs := c.ProviderConfigsByFullName()
// In order to find the *implied* dependencies (those without explicit
// "provider" blocks) we need to walk over all of the resources and
// cross-reference with the provider configs.
for _, rc := range c.Resources {
providerName := rc.ProviderFullName()
var providerType string
// Default to (effectively) no constraint whatsoever, but we might
// override if there's an explicit constraint in config.
constraint := ">=0.0.0"
config, ok := configs[providerName]
if ok {
if config.Version != "" {
constraint = config.Version
}
providerType = config.Name
} else {
providerType = providerName
}
ret[providerName] = ProviderVersionConstraint{
ProviderType: providerType,
Constraint: constraint,
}
}
return ret
}
// RequiredRanges returns a semver.Range for each distinct provider type in
// the constraint map. If the same provider type appears more than once
// (e.g. because aliases are in use) then their respective constraints are

View File

@ -2,8 +2,6 @@ package terraform
import (
"sort"
"github.com/hashicorp/terraform/config"
)
// Semaphore is a wrapper around a channel to provide
@ -48,10 +46,6 @@ func (s Semaphore) Release() {
}
}
func resourceProvider(resourceType, explicitProvider string) string {
return config.ResourceProviderFullName(resourceType, explicitProvider)
}
// strSliceContains checks if a given string is contained in a slice
// When anybody asks why Go needs generics, here you go.
func strSliceContains(haystack []string, needle string) bool {