cliconfig: Allow forcing use of the plugin cache despite the lock file

Currently Terraform will use an entry from the global plugin cache only if
it matches a checksum already recorded in the dependency lock file. This
allows Terraform to produce a complete lock file entry on the first
encounter with a new provider, whereas using the cache in that case would
cause the lock file to only cover the single package in the cache and
thereefore be unusable on any other operating system or CPU architecture.

This temporary CLI config option is a pragmatic exception to support those
who cannot currently correctly use the dependency lock file but who still
want to benefit from the plugin cache. With this setting enabled,
Terraform has permission to produce a dependency lock file that is only
suitable for the current system if that would allow use of an existing
entry in the plugin cache.

We are introducing this option to resolve a conflict between the needs of
folks who are using the dependency lock file as expected and the needs of
folks who cannot use the dependency lock file for some reason. The hope
then is to give respite to those who need this exception in the meantime
while we understand better why they cannot use the dependency lock file
and improve its design so that everyone will be able to use it
successfully in a future version of Terraform. This option will become a
silent no-op in a future version of Terraform, once the dependency lock
file behavior is sufficient for all supported Terraform development
workflows.
This commit is contained in:
Martin Atkins
2023-01-10 16:26:11 -08:00
parent 3cc7e55465
commit e2380b1038
7 changed files with 410 additions and 2 deletions

View File

@@ -38,6 +38,17 @@ type Config struct {
// avoid repeatedly re-downloading over the Internet.
PluginCacheDir string `hcl:"plugin_cache_dir"`
// PluginCacheMayBreakDependencyLockFile is an interim accommodation for
// those who wish to use the Plugin Cache Dir even in cases where doing so
// will cause the dependency lock file to be incomplete.
//
// This is likely to become a silent no-op in future Terraform versions but
// is here in recognition of the fact that the dependency lock file is not
// yet a good fit for all Terraform workflows and folks in that category
// would prefer to have the plugin cache dir's behavior to take priority
// over the requirements of the dependency lock file.
PluginCacheMayBreakDependencyLockFile bool `hcl:"plugin_cache_may_break_dependency_lock_file"`
Hosts map[string]*ConfigHost `hcl:"host"`
Credentials map[string]map[string]interface{} `hcl:"credentials"`

View File

@@ -103,6 +103,22 @@ type Meta struct {
// into the given directory.
PluginCacheDir string
// PluginCacheMayBreakDependencyLockFile is a temporary CLI configuration-based
// opt out for the behavior of only using the plugin cache dir if its
// contents match checksums recorded in the dependency lock file.
//
// This is an accommodation for those who currently essentially ignore the
// dependency lock file -- treating it only as transient working directory
// state -- and therefore don't care if the plugin cache dir causes the
// checksums inside to only be sufficient for the computer where Terraform
// is currently running.
//
// We intend to remove this exception again (making the CLI configuration
// setting a silent no-op) in future once we've improved the dependency
// lock file mechanism so that it's usable for everyone and there are no
// longer any compelling reasons for folks to not lock their dependencies.
PluginCacheMayBreakDependencyLockFile bool
// ProviderSource allows determining the available versions of a provider
// and determines where a distribution package for a particular
// provider version can be obtained.

View File

@@ -63,6 +63,7 @@ func (m *Meta) providerInstallerCustomSource(source getproviders.Source) *provid
inst := providercache.NewInstaller(targetDir, source)
if globalCacheDir != nil {
inst.SetGlobalCacheDir(globalCacheDir)
inst.SetGlobalCacheDirMayBreakDependencyLockFile(m.PluginCacheMayBreakDependencyLockFile)
}
var builtinProviderTypes []string
for ty := range m.internalProviders() {