main: Properly handle provider installation method exclusions

Previously we were incorrectly using the Include configuration for both
the include and exclude list, making the include portion totally
ineffective.
This commit is contained in:
Martin Atkins 2020-04-22 17:31:57 -07:00
parent 3167067029
commit 6b2050f42a
3 changed files with 24 additions and 4 deletions

View File

@ -229,13 +229,17 @@ type ProviderInstallationLocation interface {
providerInstallationLocation() providerInstallationLocation()
} }
type configProviderInstallationDirect [0]byte type providerInstallationDirect [0]byte
func (i configProviderInstallationDirect) providerInstallationLocation() {} func (i providerInstallationDirect) providerInstallationLocation() {}
// ProviderInstallationDirect is a ProviderInstallationSourceLocation // ProviderInstallationDirect is a ProviderInstallationSourceLocation
// representing installation from a provider's origin registry. // representing installation from a provider's origin registry.
var ProviderInstallationDirect ProviderInstallationLocation = configProviderInstallationDirect{} var ProviderInstallationDirect ProviderInstallationLocation = providerInstallationDirect{}
func (i providerInstallationDirect) GoString() string {
return "cliconfig.ProviderInstallationDirect"
}
// ProviderInstallationFilesystemMirror is a ProviderInstallationSourceLocation // ProviderInstallationFilesystemMirror is a ProviderInstallationSourceLocation
// representing installation from a particular local filesystem mirror. The // representing installation from a particular local filesystem mirror. The
@ -244,6 +248,10 @@ type ProviderInstallationFilesystemMirror string
func (i ProviderInstallationFilesystemMirror) providerInstallationLocation() {} func (i ProviderInstallationFilesystemMirror) providerInstallationLocation() {}
func (i ProviderInstallationFilesystemMirror) GoString() string {
return fmt.Sprintf("cliconfig.ProviderInstallationFilesystemMirror(%q)", i)
}
// ProviderInstallationNetworkMirror is a ProviderInstallationSourceLocation // ProviderInstallationNetworkMirror is a ProviderInstallationSourceLocation
// representing installation from a particular local network mirror. The // representing installation from a particular local network mirror. The
// string value is the HTTP base URL exactly as written in the configuration, // string value is the HTTP base URL exactly as written in the configuration,
@ -251,3 +259,7 @@ func (i ProviderInstallationFilesystemMirror) providerInstallationLocation() {}
type ProviderInstallationNetworkMirror string type ProviderInstallationNetworkMirror string
func (i ProviderInstallationNetworkMirror) providerInstallationLocation() {} func (i ProviderInstallationNetworkMirror) providerInstallationLocation() {}
func (i ProviderInstallationNetworkMirror) GoString() string {
return fmt.Sprintf("cliconfig.ProviderInstallationNetworkMirror(%q)", i)
}

View File

@ -2,4 +2,7 @@ provider_installation {
filesystem_mirror { filesystem_mirror {
path = "./fs-mirror" path = "./fs-mirror"
} }
direct {
exclude = ["example.com/*/*"]
}
} }

View File

@ -39,6 +39,7 @@ func explicitProviderSource(config *cliconfig.ProviderInstallation, services *di
var diags tfdiags.Diagnostics var diags tfdiags.Diagnostics
var searchRules []getproviders.MultiSourceSelector var searchRules []getproviders.MultiSourceSelector
log.Printf("[DEBUG] Explicit provider installation configuration is set")
for _, methodConfig := range config.Methods { for _, methodConfig := range config.Methods {
source, moreDiags := providerSourceForCLIConfigLocation(methodConfig.Location, services) source, moreDiags := providerSourceForCLIConfigLocation(methodConfig.Location, services)
diags = diags.Append(moreDiags) diags = diags.Append(moreDiags)
@ -53,14 +54,16 @@ func explicitProviderSource(config *cliconfig.ProviderInstallation, services *di
"Invalid provider source inclusion patterns", "Invalid provider source inclusion patterns",
fmt.Sprintf("CLI config specifies invalid provider inclusion patterns: %s.", err), fmt.Sprintf("CLI config specifies invalid provider inclusion patterns: %s.", err),
)) ))
continue
} }
exclude, err := getproviders.ParseMultiSourceMatchingPatterns(methodConfig.Include) exclude, err := getproviders.ParseMultiSourceMatchingPatterns(methodConfig.Exclude)
if err != nil { if err != nil {
diags = diags.Append(tfdiags.Sourceless( diags = diags.Append(tfdiags.Sourceless(
tfdiags.Error, tfdiags.Error,
"Invalid provider source exclusion patterns", "Invalid provider source exclusion patterns",
fmt.Sprintf("CLI config specifies invalid provider exclusion patterns: %s.", err), fmt.Sprintf("CLI config specifies invalid provider exclusion patterns: %s.", err),
)) ))
continue
} }
searchRules = append(searchRules, getproviders.MultiSourceSelector{ searchRules = append(searchRules, getproviders.MultiSourceSelector{
@ -68,6 +71,8 @@ func explicitProviderSource(config *cliconfig.ProviderInstallation, services *di
Include: include, Include: include,
Exclude: exclude, Exclude: exclude,
}) })
log.Printf("[TRACE] Selected provider installation method %#v with includes %s and excludes %s", methodConfig.Location, include, exclude)
} }
return getproviders.MultiSource(searchRules), diags return getproviders.MultiSource(searchRules), diags