provider cache: log errors and validate dir exists (#24993)

* providercache: add logging for errors from getproviders.SearchLocalDirectory

providercache.fillMetaCache() was silently swallowing errors when
searching the cache directory. This commit logs the error without
changing the behavior otherwise.

* command/cliconfig: validate plugin cache dir exists

The plugin cache directory must exist for terraform to use it, so we
will add a check at the begining.
This commit is contained in:
Kristin Laemmert 2020-05-19 15:32:36 -04:00 committed by GitHub
parent e1dcae17b7
commit 0d620018fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View File

@ -273,6 +273,15 @@ func (c *Config) Validate() tfdiags.Diagnostics {
)
}
if c.PluginCacheDir != "" {
_, err := os.Stat(c.PluginCacheDir)
if err != nil {
diags = diags.Append(
fmt.Errorf("The specified plugin cache dir %s cannot be opened: %s", c.PluginCacheDir, err),
)
}
}
return diags
}

View File

@ -193,6 +193,12 @@ func TestConfigValidate(t *testing.T) {
},
1, // no more than one provider_installation block allowed
},
"plugin_cache_dir does not exist": {
&Config{
PluginCacheDir: "fake",
},
1, // The specified plugin cache dir %s cannot be opened
},
}
for name, test := range tests {

View File

@ -136,6 +136,7 @@ func (d *Dir) fillMetaCache() error {
allData, err := getproviders.SearchLocalDirectory(d.baseDir)
if err != nil {
log.Printf("[TRACE] providercache.fillMetaCache: error while scanning directory %s: %s", d.baseDir, err)
return err
}