opentofu/internal
Martin Atkins d0a35c60a7 providercache: Ignore lock-mismatching global cache entries
When we originally introduced the trust-on-first-use checksum locking
mechanism in v0.14, we had to make some tricky decisions about how it
should interact with the pre-existing optional read-through global cache
of provider packages:

The global cache essentially conflicts with the checksum locking because
if the needed provider is already in the cache then Terraform skips
installing the provider from upstream and therefore misses the opportunity
to capture the signed checksums published by the provider developer. We
can't use the signed checksums to verify a cache entry because the origin
registry protocol is still using the legacy ziphash scheme and that is
only usable for the original zipped provider packages and not for the
unpacked-layout cache directory. Therefore we decided to prioritize the
existing cache directory behavior at the expense of the lock file behavior,
making Terraform produce an incomplete lock file in that case.

Now that we've had some real-world experience with the lock file mechanism,
we can see that the chosen compromise was not ideal because it causes
"terraform init" to behave significantly differently in its lock file
update behavior depending on whether or not a particular provider is
already cached. By robbing Terraform of its opportunity to fetch the
official checksums, Terraform must generate a lock file that is inherently
non-portable, which is problematic for any team which works with the same
Terraform configuration on multiple different platforms.

This change addresses that problem by essentially flipping the decision so
that we'll prioritize the lock file behavior over the provider cache
behavior. Now a global cache entry is eligible for use if and only if the
lock file already contains a checksum that matches the cache entry. This
means that the first time a particular configuration sees a new provider
it will always be fetched from the configured installation source
(typically the origin registry) and record the checksums from that source.

On subsequent installs of the same provider version already locked,
Terraform will then consider the cache entry to be eligible and skip
re-downloading the same package.

This intentionally makes the global cache mechanism subordinate to the
lock file mechanism: the lock file must be populated in order for the
global cache to be effective. For those who have many separate
configurations which all refer to the same provider version, they will
need to re-download the provider once for each configuration in order to
gather the information needed to populate the lock file, whereas before
they would have only downloaded it for the _first_ configuration using
that provider.

This should therefore remove the most significant cause of folks ending
up with incomplete lock files that don't work for colleagues using other
platforms, and the expense of bypassing the cache for the first use of
each new package with each new configuration. This tradeoff seems
reasonable because otherwise such users would inevitably need to run
"terraform providers lock" separately anyway, and that command _always_
bypasses the cache. Although this change does decrease the hit rate of the
cache, if we subtract the never-cached downloads caused by
"terraform providers lock" then this is a net benefit overall, and does
the right thing by default without the need to run a separate command.
2022-11-04 16:18:15 -07:00
..
addrs addrs: ModuleSourceRemote.String correctly handles query string in URL 2022-08-31 09:13:24 -07:00
backend S3 Backend : Bucket key should not contain trailing slash 2022-10-31 16:19:26 -07:00
builtin add simple error indicating backend removal 2022-06-28 13:58:22 -04:00
checks core: Propagate check results accurately from plan to apply 2022-08-26 15:47:29 -07:00
cloud Add tests for cloud backend taskStage 2022-09-21 09:40:52 +08:00
command providercache: Ignore lock-mismatching global cache entries 2022-11-04 16:18:15 -07:00
communicator communicator/ssh: Fix crash using SSH+HTTP proxy 2022-05-03 08:24:59 -04:00
configs Do not apply type defaults to null values 2022-09-15 15:32:36 -04:00
copy test: use T.TempDir to create temporary test directory (#30803) 2022-04-08 17:34:16 +01:00
dag Clarify some comments in internal/dag 2022-10-06 15:10:33 -07:00
depsfile Ignore existing package hashes for providers lock command (#31389) 2022-07-20 13:27:24 +01:00
didyoumean didyoumean: move from "helper" to "internal" 2020-10-02 13:35:07 -07:00
e2e test: use T.TempDir to create temporary test directory (#30803) 2022-04-08 17:34:16 +01:00
earlyconfig tfdiags: Expose the "extra information" concept from HCL 2022-06-23 13:52:23 -07:00
experiments build: Use Go 1.19 2022-08-22 10:59:12 -07:00
getmodules add XTerraformGetLimit to prevent redirect loops 2022-06-01 12:46:22 -04:00
getproviders build: Use Go 1.19 2022-08-22 10:59:12 -07:00
grpcwrap s/Capabilities/ServerCapabilities/ 2022-07-06 13:47:35 -04:00
helper/slowmessage remove wrapped streams and readline 2021-10-28 11:51:39 -04:00
httpclient backend/azurerm: removing ADAL support 2022-05-18 16:56:10 +02:00
initwd expand module subdir globs 2022-08-17 16:27:58 -04:00
instances InstancesForModule should not panic 2021-12-17 13:31:41 -05:00
ipaddr build: Use Go 1.19 2022-08-22 10:59:12 -07:00
lang lang/funcs: "timecmp" function 2022-08-25 10:15:42 -07:00
legacy build: Use Go 1.19 2022-08-22 10:59:12 -07:00
logging cleanup panic output 2021-12-17 11:57:52 -05:00
modsdir Refactoring of module source addresses and module installation 2021-06-03 08:50:34 -07:00
moduledeps Move plugin/ and plugin6/ to internal/plugin{,6}/ 2021-05-17 14:09:07 -07:00
moduletest fixup broken test fixtures 2022-07-06 13:47:35 -04:00
plans update UIMode comment 2022-10-20 13:13:58 -04:00
plugin s/Capabilities/ServerCapabilities/ 2022-07-06 13:47:35 -04:00
plugin6 s/Capabilities/ServerCapabilities/ 2022-07-06 13:47:35 -04:00
provider-simple s/Capabilities/ServerCapabilities/ 2022-07-06 13:47:35 -04:00
provider-simple-v6 s/Capabilities/ServerCapabilities/ 2022-07-06 13:47:35 -04:00
provider-terraform/main Move plugin/ and plugin6/ to internal/plugin{,6}/ 2021-05-17 14:09:07 -07:00
providercache providercache: Ignore lock-mismatching global cache entries 2022-11-04 16:18:15 -07:00
providers s/Capabilities/ServerCapabilities/ 2022-07-06 13:47:35 -04:00
provisioner-local-exec/main Move plugin/ and plugin6/ to internal/plugin{,6}/ 2021-05-17 14:09:07 -07:00
provisioners Move configs/ to internal/configs/ 2021-05-17 14:09:07 -07:00
refactoring allow cross-package move statements (#31556) 2022-08-16 16:52:57 +02:00
registry revert "run goimports" 2022-08-01 16:26:26 -05:00
repl Unify all sensitive value plan output as "(sensitive value)" 2022-10-24 12:50:46 -06:00
replacefile Upgrade to Go 1.17 2021-08-17 15:20:05 -07:00
states normalize empty CheckResults fields in stateV4 2022-11-01 16:18:38 -04:00
terminal remove the use of panicwrap 2021-10-28 11:51:39 -04:00
terraform use UIMode instead of 0 changes to detect refresh 2022-11-02 10:56:08 -04:00
tfdiags build: Use Go 1.19 2022-08-22 10:59:12 -07:00
tfplugin5 docs/plugin-protocol: Add notes about missing configuration in ReadResource and UpgradeResourceState request messages (#31998) 2022-10-13 16:29:34 -04:00
tfplugin6 docs/plugin-protocol: Add notes about missing configuration in ReadResource and UpgradeResourceState request messages (#31998) 2022-10-13 16:29:34 -04:00