mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 08:51:02 -06:00
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:
parent
e1dcae17b7
commit
0d620018fe
@ -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
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user