From c2bc88fc23e144e80f5b4a021376ce800330694a Mon Sep 17 00:00:00 2001 From: Alex Pilon Date: Thu, 18 Jul 2019 15:24:34 -0400 Subject: [PATCH] prune ResourceProviderFullName and its callers --- config/config.go | 29 ------------------------- config/config_test.go | 50 ------------------------------------------- config/providers.go | 42 ------------------------------------ terraform/util.go | 6 ------ 4 files changed, 127 deletions(-) diff --git a/config/config.go b/config/config.go index 1772fd7e3..f13a046c6 100644 --- a/config/config.go +++ b/config/config.go @@ -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 { diff --git a/config/config_test.go b/config/config_test.go index 8de5d764f..93ac8ece6 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -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") diff --git a/config/providers.go b/config/providers.go index 7a50782f3..eeddabc32 100644 --- a/config/providers.go +++ b/config/providers.go @@ -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 diff --git a/terraform/util.go b/terraform/util.go index 752241af1..5428cd5a0 100644 --- a/terraform/util.go +++ b/terraform/util.go @@ -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 {