Skip to content

Commit

Permalink
provider cache: log errors and validate dir exists (#24993)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
mildwonkey authored May 19, 2020
1 parent e1dcae1 commit 0d62001
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions command/cliconfig/cliconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions command/cliconfig/cliconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions internal/providercache/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 0d62001

Please sign in to comment.