hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.45k stars 9.51k forks source link

Problem with caching of vendor plugins in Terraform 1.4.0 and later versions #33497

Open BrianTuduri opened 1 year ago

BrianTuduri commented 1 year ago

Terraform Version

Terraform v1.4.0
on linux_amd64

Terraform Configuration Files

# Dockerfile
FROM jenkins/agent:alpine
USER root
ENV PYTHONUNBUFFERED=1
ENV TF_PLUGIN_CACHE_DIR="/tf_cache"
ENV TF_CLI_CONFIG_FILE="/tf_cache/.terraformrc"
...
RUN mkdir /tf_cache && \
    chown -R jenkins:jenkins /tf_cache && \
    chmod 775 /tf_cache && \
    chmod 775 /bin/* 

COPY .terraformrc /tf_cache/.terraformrc

VOLUME ["/tf_cache"]
# .terraformrc
plugin_cache_dir = "/tf_cache"
disable_checkpoint = true
plugin_cache_may_break_dependency_lock_file = true

Debug Output

2023-07-10T13:14:44.009Z [TRACE] providercache.Dir.InstallPackage: installing registry.terraform.io/hashicorp/kubernetes v2.21.1 from https://releases.hashicorp.com/terraform-provider-kubernetes/2.21.1/terraform-provider-kubernetes_2.21.1_linux_amd64.zip
2023-07-10T13:14:53.340Z [TRACE] providercache.Dir.LinkFromOtherCache: linking registry.terraform.io/hashicorp/kubernetes v2.21.1 from existing cache /tf_cache/registry.terraform.io/hashicorp/kubernetes/2.21.1/linux_amd64 to .terraform/providers/registry.terraform.io/hashicorp/kubernetes/2.21.1/linux_amd64
- Installed hashicorp/kubernetes v2.21.1 (signed by HashiCorp)

+ terraform init -reconfigure
2023-07-10T13:14:43.413Z [INFO]  Terraform version: 1.4.0
2023-07-10T13:14:43.413Z [DEBUG] using github.com/hashicorp/go-tfe v1.18.0
2023-07-10T13:14:43.413Z [DEBUG] using github.com/hashicorp/hcl/v2 v2.16.0
2023-07-10T13:14:43.413Z [DEBUG] using github.com/hashicorp/terraform-config-inspect v0.0.0-20210209133302-4fd17a0faac2
2023-07-10T13:14:43.413Z [DEBUG] using github.com/hashicorp/terraform-svchost v0.1.0
2023-07-10T13:14:43.413Z [DEBUG] using github.com/zclconf/go-cty v1.12.1
2023-07-10T13:14:43.413Z [INFO]  Go runtime version: go1.19.6
2023-07-10T13:14:43.413Z [INFO]  CLI args: []string{"terraform", "init", "-reconfigure"}
2023-07-10T13:14:43.413Z [TRACE] Stdout is not a terminal
2023-07-10T13:14:43.413Z [TRACE] Stderr is not a terminal
2023-07-10T13:14:43.413Z [TRACE] Stdin is not a terminal
2023-07-10T13:14:43.413Z [DEBUG] Attempting to open CLI config file: /tf_cache/.terraformrc
2023-07-10T13:14:43.413Z [DEBUG] Not reading CLI config directory because config location is overridden by environment variable
2023-07-10T13:14:43.413Z [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2023-07-10T13:14:43.413Z [DEBUG] ignoring non-existing provider search directory /root/.terraform.d/plugins
2023-07-10T13:14:43.413Z [DEBUG] ignoring non-existing provider search directory /root/.local/share/terraform/plugins
2023-07-10T13:14:43.413Z [DEBUG] ignoring non-existing provider search directory /usr/local/share/terraform/plugins
2023-07-10T13:14:43.413Z [DEBUG] ignoring non-existing provider search directory /usr/share/terraform/plugins
2023-07-10T13:14:43.414Z [INFO]  CLI command args: []string{"init", "-reconfigure"}

Initializing the backend...
2023-07-10T13:14:43.418Z [TRACE] Meta.Backend: built configuration for "kubernetes" backend with hash value 3266516096
2023-07-10T13:14:43.418Z [TRACE] Meta.Backend: backend has not previously been initialized in this working directory
2023-07-10T13:14:43.418Z [DEBUG] New state was assigned lineage "5d3830a1-9e0c-0aac-5879-5dda8f288e4e"
2023-07-10T13:14:43.418Z [TRACE] Meta.Backend: moving from default local state only to "kubernetes" backend
2023-07-10T13:14:43.419Z [DEBUG] checking for provisioner in "."
2023-07-10T13:14:43.421Z [DEBUG] checking for provisioner in "/bin"
2023-07-10T13:14:43.421Z [TRACE] backend/local: state manager for workspace "default" will:
 - read initial snapshot from terraform.tfstate
 - write new snapshots to terraform.tfstate
 - create any backup at terraform.tfstate.backup
2023-07-10T13:14:43.421Z [TRACE] statemgr.Filesystem: reading initial snapshot from terraform.tfstate
2023-07-10T13:14:43.421Z [TRACE] statemgr.Filesystem: snapshot file has nil snapshot, but that's okay
2023-07-10T13:14:43.421Z [TRACE] statemgr.Filesystem: read nil snapshot
2023-07-10T13:14:43.421Z [TRACE] Meta.Backend: ignoring local "default" workspace because its state is empty
2023-07-10T13:14:43.422Z [DEBUG] Using kubeconfig: /root/.kube/config
2023-07-10T13:14:43.425Z [INFO]  Successfully initialized config
2023-07-10T13:14:43.426Z [DEBUG] New state was assigned lineage "34810b53-3e0f-cdf2-1d23-5b9407ad069b"
2023-07-10T13:14:43.482Z [TRACE] Meta.selectWorkspace: the currently selected workspace is present in the configured backend (default)

2023-07-10T13:15:05.532Z [TRACE] providercache.Dir.InstallPackage: installing registry.terraform.io/hashicorp/helm v2.10.1 from https://releases.hashicorp.com/terraform-provider-helm/2.10.1/terraform-provider-helm_2.10.1_linux_amd64.zip
2023-07-10T13:15:17.124Z [TRACE] providercache.Dir.LinkFromOtherCache: linking registry.terraform.io/hashicorp/helm v2.10.1 from existing cache /tf_cache/registry.terraform.io/hashicorp/helm/2.10.1/linux_amd64 to .terraform/providers/registry.terraform.io/hashicorp/helm/2.10.1/linux_amd64
- Installed hashicorp/helm v2.10.1 (signed by HashiCorp)

2023-07-10T13:15:05.121Z [TRACE] providercache.Dir.InstallPackage: installing registry.terraform.io/rancher/rancher2 v3.0.2 from https://releases.hashicorp.com/terraform-provider-rancher2/3.0.2/terraform-provider-rancher2_3.0.2_linux_amd64.zip
2023-07-10T13:15:05.122Z [TRACE] providercache.Dir.LinkFromOtherCache: linking registry.terraform.io/rancher/rancher2 v3.0.2 from existing cache /tf_cache/registry.terraform.io/rancher/rancher2/3.0.2/linux_amd64 to .terraform/providers/registry.terraform.io/rancher/rancher2/3.0.2/linux_amd64
- Installed rancher/rancher2 v3.0.2 (signed by a HashiCorp partner, key ID 2EEB0F9AD44A135C)

Initializing provider plugins...
- Finding latest version of hashicorp/kubernetes...
2023-07-10T13:14:43.550Z [DEBUG] Service discovery for registry.terraform.io at https://registry.terraform.io/.well-known/terraform.json
2023-07-10T13:14:43.550Z [TRACE] HTTP client GET request to https://registry.terraform.io/.well-known/terraform.json
2023-07-10T13:14:43.854Z [DEBUG] GET https://registry.terraform.io/v1/providers/hashicorp/kubernetes/versions
2023-07-10T13:14:43.854Z [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/hashicorp/kubernetes/versions
- Finding latest version of rancher/rancher2...
2023-07-10T13:14:43.913Z [DEBUG] GET https://registry.terraform.io/v1/providers/rancher/rancher2/versions
2023-07-10T13:14:43.913Z [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/rancher/rancher2/versions
- Finding latest version of hashicorp/helm...
2023-07-10T13:14:43.963Z [DEBUG] GET https://registry.terraform.io/v1/providers/hashicorp/helm/versions
2023-07-10T13:14:43.963Z [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/hashicorp/helm/versions
2023-07-10T13:14:44.008Z [TRACE] providercache.fillMetaCache: scanning directory .terraform/providers
2023-07-10T13:14:44.008Z [TRACE] getproviders.SearchLocalDirectory: failed to resolve symlinks for .terraform/providers: lstat .terraform/providers: no such file or directory
2023-07-10T13:14:44.008Z [TRACE] providercache.fillMetaCache: error while scanning directory .terraform/providers: cannot search .terraform/providers: lstat .terraform/providers: no such file or directory
2023-07-10T13:14:44.008Z [TRACE] providercache.fillMetaCache: scanning directory /tf_cache
2023-07-10T13:14:44.008Z [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/helm v2.10.1 for linux_amd64 at /tf_cache/registry.terraform.io/hashicorp/helm/2.10.1/linux_amd64
2023-07-10T13:14:44.008Z [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/kubernetes v2.21.1 for linux_amd64 at /tf_cache/registry.terraform.io/hashicorp/kubernetes/2.21.1/linux_amd64
2023-07-10T13:14:44.009Z [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/rancher/rancher2 v3.0.2 for linux_amd64 at /tf_cache/registry.terraform.io/rancher/rancher2/3.0.2/linux_amd64
2023-07-10T13:14:44.009Z [TRACE] providercache.fillMetaCache: including /tf_cache/registry.terraform.io/hashicorp/helm/2.10.1/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/helm 2.10.1
2023-07-10T13:14:44.009Z [TRACE] providercache.fillMetaCache: including /tf_cache/registry.terraform.io/hashicorp/kubernetes/2.21.1/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/kubernetes 2.21.1
2023-07-10T13:14:44.009Z [TRACE] providercache.fillMetaCache: including /tf_cache/registry.terraform.io/rancher/rancher2/3.0.2/linux_amd64 as a candidate package for registry.terraform.io/rancher/rancher2 3.0.2
2023-07-10T13:14:44.009Z [DEBUG] GET https://registry.terraform.io/v1/providers/hashicorp/kubernetes/2.21.1/download/linux/amd64
2023-07-10T13:14:44.009Z [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/hashicorp/kubernetes/2.21.1/download/linux/amd64
2023-07-10T13:14:44.057Z [DEBUG] GET https://releases.hashicorp.com/terraform-provider-kubernetes/2.21.1/terraform-provider-kubernetes_2.21.1_SHA256SUMS
2023-07-10T13:14:44.057Z [TRACE] HTTP client GET request to https://releases.hashicorp.com/terraform-provider-kubernetes/2.21.1/terraform-provider-kubernetes_2.21.1_SHA256SUMS
2023-07-10T13:14:44.268Z [DEBUG] GET https://releases.hashicorp.com/terraform-provider-kubernetes/2.21.1/terraform-provider-kubernetes_2.21.1_SHA256SUMS.72D7468F.sig
2023-07-10T13:14:44.268Z [TRACE] HTTP client GET request to https://releases.hashicorp.com/terraform-provider-kubernetes/2.21.1/terraform-provider-kubernetes_2.21.1_SHA256SUMS.72D7468F.sig
- Installing hashicorp/kubernetes v2.21.1...
2023-07-10T13:14:44.286Z [TRACE] providercache.Dir.InstallPackage: installing registry.terraform.io/hashicorp/kubernetes v2.21.1 from https://releases.hashicorp.com/terraform-provider-kubernetes/2.21.1/terraform-provider-kubernetes_2.21.1_linux_amd64.zip
2023-07-10T13:14:44.286Z [TRACE] HTTP client GET request to https://releases.hashicorp.com/terraform-provider-kubernetes/2.21.1/terraform-provider-kubernetes_2.21.1_linux_amd64.zip
2023-07-10T13:14:52.765Z [DEBUG] Provider signed by 34365D9472D7468F HashiCorp Security (hashicorp.com/security) <security@hashicorp.com>
2023-07-10T13:14:53.337Z [TRACE] providercache.fillMetaCache: scanning directory /tf_cache
2023-07-10T13:14:53.338Z [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/helm v2.10.1 for linux_amd64 at /tf_cache/registry.terraform.io/hashicorp/helm/2.10.1/linux_amd64
2023-07-10T13:14:53.338Z [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/kubernetes v2.21.1 for linux_amd64 at /tf_cache/registry.terraform.io/hashicorp/kubernetes/2.21.1/linux_amd64
2023-07-10T13:14:53.338Z [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/rancher/rancher2 v3.0.2 for linux_amd64 at /tf_cache/registry.terraform.io/rancher/rancher2/3.0.2/linux_amd64
2023-07-10T13:14:53.338Z [TRACE] providercache.fillMetaCache: including /tf_cache/registry.terraform.io/hashicorp/helm/2.10.1/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/helm 2.10.1
2023-07-10T13:14:53.338Z [TRACE] providercache.fillMetaCache: including /tf_cache/registry.terraform.io/hashicorp/kubernetes/2.21.1/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/kubernetes 2.21.1
2023-07-10T13:14:53.338Z [TRACE] providercache.fillMetaCache: including /tf_cache/registry.terraform.io/rancher/rancher2/3.0.2/linux_amd64 as a candidate package for registry.terraform.io/rancher/rancher2 3.0.2
2023-07-10T13:14:53.338Z [TRACE] providercache.Dir.LinkFromOtherCache: linking registry.terraform.io/hashicorp/kubernetes v2.21.1 from existing cache /tf_cache/registry.terraform.io/hashicorp/kubernetes/2.21.1/linux_amd64 to .terraform/providers/registry.terraform.io/hashicorp/kubernetes/2.21.1/linux_amd64
2023-07-10T13:14:53.340Z [TRACE] providercache.fillMetaCache: scanning directory .terraform/providers
2023-07-10T13:14:53.340Z [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/kubernetes v2.21.1 for linux_amd64 at .terraform/providers/registry.terraform.io/hashicorp/kubernetes/2.21.1/linux_amd64
2023-07-10T13:14:53.340Z [TRACE] providercache.fillMetaCache: including .terraform/providers/registry.terraform.io/hashicorp/kubernetes/2.21.1/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/kubernetes 2.21.1
- Installed hashicorp/kubernetes v2.21.1 (signed by HashiCorp)
2023-07-10T13:14:53.586Z [TRACE] providercache.fillMetaCache: using cached result from previous scan of .terraform/providers
2023-07-10T13:14:53.586Z [TRACE] providercache.fillMetaCache: using cached result from previous scan of /tf_cache
2023-07-10T13:14:53.586Z [DEBUG] GET https://registry.terraform.io/v1/providers/rancher/rancher2/3.0.2/download/linux/amd64
2023-07-10T13:14:53.586Z [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/rancher/rancher2/3.0.2/download/linux/amd64
2023-07-10T13:14:53.632Z [DEBUG] GET https://github.com/rancher/terraform-provider-rancher2/releases/download/v3.0.2/terraform-provider-rancher2_3.0.2_SHA256SUMS
2023-07-10T13:14:53.632Z [TRACE] HTTP client GET request to https://github.com/rancher/terraform-provider-rancher2/releases/download/v3.0.2/terraform-provider-rancher2_3.0.2_SHA256SUMS
2023-07-10T13:14:53.987Z [TRACE] HTTP client GET request to https://objects.githubusercontent.com/github-production-release-asset-2e65be/186468979/5bc12e80-1f67-4957-913d-fe03d45ede77?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20230710%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230710T131453Z&X-Amz-Expires=300&X-Amz-Signature=7163325c625ffa9fc09cea6d10ef1f263a65881514a682adbaa165d1c62a80fc&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=186468979&response-content-disposition=attachment%3B%20filename%3Dterraform-provider-rancher2_3.0.2_SHA256SUMS&response-content-type=application%2Foctet-stream
2023-07-10T13:14:54.224Z [DEBUG] GET https://github.com/rancher/terraform-provider-rancher2/releases/download/v3.0.2/terraform-provider-rancher2_3.0.2_SHA256SUMS.sig
2023-07-10T13:14:54.224Z [TRACE] HTTP client GET request to https://github.com/rancher/terraform-provider-rancher2/releases/download/v3.0.2/terraform-provider-rancher2_3.0.2_SHA256SUMS.sig
2023-07-10T13:14:54.276Z [TRACE] HTTP client GET request to https://objects.githubusercontent.com/github-production-release-asset-2e65be/186468979/02ddf9de-1a88-4c64-b672-8a5a6e69550f?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20230710%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230710T131343Z&X-Amz-Expires=300&X-Amz-Signature=04ba69ff060c9bde7f3de367e1bab9b403d7106ce95897a9465cabfcc9570eae&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=186468979&response-content-disposition=attachment%3B%20filename%3Dterraform-provider-rancher2_3.0.2_SHA256SUMS.sig&response-content-type=application%2Foctet-stream
- Installing rancher/rancher2 v3.0.2...
2023-07-10T13:14:54.623Z [TRACE] providercache.Dir.InstallPackage: installing registry.terraform.io/rancher/rancher2 v3.0.2 from https://github.com/rancher/terraform-provider-rancher2/releases/download/v3.0.2/terraform-provider-rancher2_3.0.2_linux_amd64.zip
2023-07-10T13:14:54.623Z [TRACE] HTTP client GET request to https://github.com/rancher/terraform-provider-rancher2/releases/download/v3.0.2/terraform-provider-rancher2_3.0.2_linux_amd64.zip
2023-07-10T13:14:54.954Z [TRACE] HTTP client GET request to https://objects.githubusercontent.com/github-production-release-asset-2e65be/186468979/535d6035-7760-4483-a9a8-0a8dd8109265?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20230710%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230710T131454Z&X-Amz-Expires=300&X-Amz-Signature=19fb424d0563b8067d93ae6da1575711193ad51a39823262189d3cb488f9d1f3&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=186468979&response-content-disposition=attachment%3B%20filename%3Dterraform-provider-rancher2_3.0.2_linux_amd64.zip&response-content-type=application%2Foctet-stream
2023-07-10T13:15:04.416Z [DEBUG] Provider signed by 2EEB0F9AD44A135C Rancher terraform (Rancher GPG key for signing terraform providers and modules) <terraform-gpg@rancher.com>
2023-07-10T13:15:05.118Z [TRACE] providercache.fillMetaCache: scanning directory /tf_cache
2023-07-10T13:15:05.118Z [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/helm v2.10.1 for linux_amd64 at /tf_cache/registry.terraform.io/hashicorp/helm/2.10.1/linux_amd64
2023-07-10T13:15:05.119Z [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/kubernetes v2.21.1 for linux_amd64 at /tf_cache/registry.terraform.io/hashicorp/kubernetes/2.21.1/linux_amd64
2023-07-10T13:15:05.119Z [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/rancher/rancher2 v3.0.2 for linux_amd64 at /tf_cache/registry.terraform.io/rancher/rancher2/3.0.2/linux_amd64
2023-07-10T13:15:05.119Z [TRACE] providercache.fillMetaCache: including /tf_cache/registry.terraform.io/hashicorp/helm/2.10.1/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/helm 2.10.1
2023-07-10T13:15:05.119Z [TRACE] providercache.fillMetaCache: including /tf_cache/registry.terraform.io/hashicorp/kubernetes/2.21.1/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/kubernetes 2.21.1
2023-07-10T13:15:05.119Z [TRACE] providercache.fillMetaCache: including /tf_cache/registry.terraform.io/rancher/rancher2/3.0.2/linux_amd64 as a candidate package for registry.terraform.io/rancher/rancher2 3.0.2
2023-07-10T13:15:05.119Z [TRACE] providercache.Dir.LinkFromOtherCache: linking registry.terraform.io/rancher/rancher2 v3.0.2 from existing cache /tf_cache/registry.terraform.io/rancher/rancher2/3.0.2/linux_amd64 to .terraform/providers/registry.terraform.io/rancher/rancher2/3.0.2/linux_amd64
2023-07-10T13:15:05.121Z [TRACE] providercache.fillMetaCache: scanning directory .terraform/providers
2023-07-10T13:15:05.121Z [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/kubernetes v2.21.1 for linux_amd64 at .terraform/providers/registry.terraform.io/hashicorp/kubernetes/2.21.1/linux_amd64
2023-07-10T13:15:05.122Z [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/rancher/rancher2 v3.0.2 for linux_amd64 at .terraform/providers/registry.terraform.io/rancher/rancher2/3.0.2/linux_amd64
2023-07-10T13:15:05.122Z [TRACE] providercache.fillMetaCache: including .terraform/providers/registry.terraform.io/hashicorp/kubernetes/2.21.1/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/kubernetes 2.21.1
2023-07-10T13:15:05.122Z [TRACE] providercache.fillMetaCache: including .terraform/providers/registry.terraform.io/rancher/rancher2/3.0.2/linux_amd64 as a candidate package for registry.terraform.io/rancher/rancher2 3.0.2
- Installed rancher/rancher2 v3.0.2 (signed by a HashiCorp partner, key ID 2EEB0F9AD44A135C)
2023-07-10T13:15:05.405Z [TRACE] providercache.fillMetaCache: using cached result from previous scan of .terraform/providers
2023-07-10T13:15:05.405Z [TRACE] providercache.fillMetaCache: using cached result from previous scan of /tf_cache
2023-07-10T13:15:05.405Z [DEBUG] GET https://registry.terraform.io/v1/providers/hashicorp/helm/2.10.1/download/linux/amd64
2023-07-10T13:15:05.405Z [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/hashicorp/helm/2.10.1/download/linux/amd64
2023-07-10T13:15:05.465Z [DEBUG] GET https://releases.hashicorp.com/terraform-provider-helm/2.10.1/terraform-provider-helm_2.10.1_SHA256SUMS
2023-07-10T13:15:05.465Z [TRACE] HTTP client GET request to https://releases.hashicorp.com/terraform-provider-helm/2.10.1/terraform-provider-helm_2.10.1_SHA256SUMS
2023-07-10T13:15:05.514Z [DEBUG] GET https://releases.hashicorp.com/terraform-provider-helm/2.10.1/terraform-provider-helm_2.10.1_SHA256SUMS.72D7468F.sig
2023-07-10T13:15:05.514Z [TRACE] HTTP client GET request to https://releases.hashicorp.com/terraform-provider-helm/2.10.1/terraform-provider-helm_2.10.1_SHA256SUMS.72D7468F.sig
- Installing hashicorp/helm v2.10.1...
2023-07-10T13:15:05.532Z [TRACE] providercache.Dir.InstallPackage: installing registry.terraform.io/hashicorp/helm v2.10.1 from https://releases.hashicorp.com/terraform-provider-helm/2.10.1/terraform-provider-helm_2.10.1_linux_amd64.zip
2023-07-10T13:15:05.532Z [TRACE] HTTP client GET request to https://releases.hashicorp.com/terraform-provider-helm/2.10.1/terraform-provider-helm_2.10.1_linux_amd64.zip
2023-07-10T13:15:16.548Z [DEBUG] Provider signed by 34365D9472D7468F HashiCorp Security (hashicorp.com/security) <security@hashicorp.com>
2023-07-10T13:15:17.123Z [TRACE] providercache.fillMetaCache: scanning directory /tf_cache
2023-07-10T13:15:17.123Z [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/helm v2.10.1 for linux_amd64 at /tf_cache/registry.terraform.io/hashicorp/helm/2.10.1/linux_amd64
2023-07-10T13:15:17.124Z [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/kubernetes v2.21.1 for linux_amd64 at /tf_cache/registry.terraform.io/hashicorp/kubernetes/2.21.1/linux_amd64
2023-07-10T13:15:17.124Z [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/rancher/rancher2 v3.0.2 for linux_amd64 at /tf_cache/registry.terraform.io/rancher/rancher2/3.0.2/linux_amd64
2023-07-10T13:15:17.124Z [TRACE] providercache.fillMetaCache: including /tf_cache/registry.terraform.io/hashicorp/helm/2.10.1/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/helm 2.10.1
2023-07-10T13:15:17.124Z [TRACE] providercache.fillMetaCache: including /tf_cache/registry.terraform.io/hashicorp/kubernetes/2.21.1/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/kubernetes 2.21.1
2023-07-10T13:15:17.124Z [TRACE] providercache.fillMetaCache: including /tf_cache/registry.terraform.io/rancher/rancher2/3.0.2/linux_amd64 as a candidate package for registry.terraform.io/rancher/rancher2 3.0.2
2023-07-10T13:15:17.124Z [TRACE] providercache.Dir.LinkFromOtherCache: linking registry.terraform.io/hashicorp/helm v2.10.1 from existing cache /tf_cache/registry.terraform.io/hashicorp/helm/2.10.1/linux_amd64 to .terraform/providers/registry.terraform.io/hashicorp/helm/2.10.1/linux_amd64
2023-07-10T13:15:17.125Z [TRACE] providercache.fillMetaCache: scanning directory .terraform/providers
2023-07-10T13:15:17.125Z [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/helm v2.10.1 for linux_amd64 at .terraform/providers/registry.terraform.io/hashicorp/helm/2.10.1/linux_amd64
2023-07-10T13:15:17.125Z [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/kubernetes v2.21.1 for linux_amd64 at .terraform/providers/registry.terraform.io/hashicorp/kubernetes/2.21.1/linux_amd64
2023-07-10T13:15:17.125Z [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/rancher/rancher2 v3.0.2 for linux_amd64 at .terraform/providers/registry.terraform.io/rancher/rancher2/3.0.2/linux_amd64
2023-07-10T13:15:17.125Z [TRACE] providercache.fillMetaCache: including .terraform/providers/registry.terraform.io/hashicorp/helm/2.10.1/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/helm 2.10.1
2023-07-10T13:15:17.125Z [TRACE] providercache.fillMetaCache: including .terraform/providers/registry.terraform.io/hashicorp/kubernetes/2.21.1/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/kubernetes 2.21.1
2023-07-10T13:15:17.125Z [TRACE] providercache.fillMetaCache: including .terraform/providers/registry.terraform.io/rancher/rancher2/3.0.2/linux_amd64 as a candidate package for registry.terraform.io/rancher/rancher2 3.0.2
- Installed hashicorp/helm v2.10.1 (signed by HashiCorp)

Expected Behavior

I was expecting Terraform to use cached vendor plugins instead of downloading them again.

Actual Behavior

Terraform is downloading again the plugins from the providers, even though they are already present in the cache and apparently it detects them, if I am making a mistake please let me know.

Steps to Reproduce

  1. terraform init
  2. terraform apply

Additional Context

I am using Jenkins 2.235.5 and I have configured an agent template with a Terraform image. This image already includes a directory and volume "tf_cache", as well as the environment variables: TF_PLUGIN_CACHE_DIR="/tf_cache" and ENV TF_CLI_CONFIG_FILE="/tf_cache/.terraformrc". Additionally, I copy a file named .terraformrc to "tf_cache" which contains the following settings:

plugin_cache_dir = "/tf_cache".
disable_checkpoint = true
plugin_cache_may_break_dependency_lock_file = true

These settings are intended to set the plugin cache directory of the provider plugins to /tf_cache. This setting works as expected up to Terraform version 1.3.9. However, starting with version 1.4.0, Terraform re-downloads vendor plugins, even though they are already present in the cache.

The "tf_cache" volume is mounted on the server where Jenkins is running. Although versions after 1.4.0 of Terraform persist the providers in "tf_cache", they do not use them and instead redownload them. This results in inefficient and undesirable behavior.

References

I am not aware of any other problems or pull requests that should be linked here.

crw commented 1 year ago

Thanks for this request! It may be a duplicate of https://github.com/hashicorp/terraform/issues/32901.

apparentlymart commented 1 year ago

Hi @BrianTuduri! Sorry for this strange behavior and thanks for reporting it.

I've been trying to make sense of the series of messages in the trace log you shared, but there are some oddities that I can't explain and I wonder if you have some additional context that might help me understand what's going on.

The main thing that confuses me is that I see log lines about installing provider packages from the cache before Terraform actually reached the point of "Initializing provider plugins..." and thus before it should know which versions it's supposed to be using:

2023-07-10T13:15:05.532Z [TRACE] providercache.Dir.InstallPackage: installing registry.terraform.io/hashicorp/helm v2.10.1 from https://releases.hashicorp.com/terraform-provider-helm/2.10.1/terraform-provider-helm_2.10.1_linux_amd64.zip
2023-07-10T13:15:17.124Z [TRACE] providercache.Dir.LinkFromOtherCache: linking registry.terraform.io/hashicorp/helm v2.10.1 from existing cache /tf_cache/registry.terraform.io/hashicorp/helm/2.10.1/linux_amd64 to .terraform/providers/registry.terraform.io/hashicorp/helm/2.10.1/linux_amd64
- Installed hashicorp/helm v2.10.1 (signed by HashiCorp)

2023-07-10T13:15:05.121Z [TRACE] providercache.Dir.InstallPackage: installing registry.terraform.io/rancher/rancher2 v3.0.2 from https://releases.hashicorp.com/terraform-provider-rancher2/3.0.2/terraform-provider-rancher2_3.0.2_linux_amd64.zip
2023-07-10T13:15:05.122Z [TRACE] providercache.Dir.LinkFromOtherCache: linking registry.terraform.io/rancher/rancher2 v3.0.2 from existing cache /tf_cache/registry.terraform.io/rancher/rancher2/3.0.2/linux_amd64 to .terraform/providers/registry.terraform.io/rancher/rancher2/3.0.2/linux_amd64
- Installed rancher/rancher2 v3.0.2 (signed by a HashiCorp partner, key ID 2EEB0F9AD44A135C)

Initializing provider plugins...
- Finding latest version of hashicorp/kubernetes...
2023-07-10T13:14:43.550Z [DEBUG] Service discovery for registry.terraform.io at https://registry.terraform.io/.well-known/terraform.json
[etc]

However, I notice that the timestamp on the final log line is 13:14:43.55 while the earlier one was 13:15:05.532, so it seems like perhaps these log lines have somehow been misordered by the system that you used to collect them?

If I try to slot those lines into the place where their timestamps suggest they should go then the sequence of events does seem plausible, so if I assume that this was just a log aggregation quirk then indeed it does seem like Terraform is somehow concluding that the items in the cache are not valid, but unfortunately the logs here don't seem to give any indication as to why, so I think this might take some additional debugging.

I see in your CLI configuration you enabled plugin_cache_may_break_dependency_lock_file = true, and the code which handles that special exception is written to generate a log line acknowledging it:

[WARN] plugin_cache_may_break_dependency_lock_file: Using global cache dir package for %s v%s even though it doesn't match this configuration's dependency lock file

There seems to be no such message in the logs you shared, which (assuming that there are no log lines missing from what you shared) suggests that the plugin_cache_may_break_dependency_lock_file was not active for some reason.

The log lines we can see seem consistent with how Terraform would behave if that setting were not in effect and if the cache directory checksums were unverifyable, so it seems like Terraform is for some reason not honoring that setting, as opposed to the relevant log lines just being absent in your trace log.

So of course this raises the question of why exactly Terraform cannot "see" the plugin_cache_may_break_dependency_lock_file setting.

Although I don't yet have a direct explanation for why this would be true, I have a hypothesis that for some reason that setting might be ineffective when the CLI configuration location is overridden using the TF_CLI_CONFIG_FILE environment variable. Of course that's not the intended behavior, but setting that environment variable does alter some of the configuration loading behavior (since it's loading exactly one file rather than scanning for possibly many files in different directories), and so there might be a bug in how that different situation gets handled.

Is it possible for you to temporarily arrange for that CLI configuration file to be in one of the standard search locations, so you can see if the incorrect behavior persists when you don't set TF_CLI_CONFIG_FILE? Thanks!

Surya4DevOps commented 1 year ago

Even I faced similar issue and I spent lot of time in fixing this issue by trying different possibilities. Finally here is what I did as workaround for the issue in terraform version v1.5.3.

First make sure all the downloaded plugins from terraform repo are available at $HOME/.terraform.d/tf-cache

Add below .terraformrc config file to home directory.

cat <<EOF > $HOME/.terraformrc
provider_installation {
  filesystem_mirror {
    path="${HOME}/.terraform.d/tf-cache/"
    include=["registry.terraform.io/hashicorp/*"]
  }
  direct {
    exclude=["registry.terraform.io/hashicorp/*"]
  }
}
plugin_cache_dir="${HOME}/.terraform.d/tf-cache/"
disable_checkpoint=true
EOF

While running terraform init use --plugin-dir option, it started working.

terraform init -backend-config=terraform-state.tfvars --plugin-dir "$HOME/.terraform.d/tf-cache/"

Hope this helps.

magodo commented 7 months ago

I have a similar issue with a fresh new environment setup to run terraform. I have following config:

plugin_cache_dir   = "$HOME/.terraform.d/plugin-cache"

Everytime when I run terraform init, it downloads the provider again even though they exist in the cache.

The log looks like below:

Log
2024-03-07T13:38:34.267+0800 [INFO]  Terraform version: 1.7.4
2024-03-07T13:38:34.267+0800 [DEBUG] using github.com/hashicorp/go-tfe v1.41.0
2024-03-07T13:38:34.267+0800 [DEBUG] using github.com/hashicorp/hcl/v2 v2.19.1
2024-03-07T13:38:34.267+0800 [DEBUG] using github.com/hashicorp/terraform-svchost v0.1.1
2024-03-07T13:38:34.267+0800 [DEBUG] using github.com/zclconf/go-cty v1.14.1
2024-03-07T13:38:34.267+0800 [INFO]  Go runtime version: go1.21.5
2024-03-07T13:38:34.267+0800 [INFO]  CLI args: []string{"terraform", "init"}
2024-03-07T13:38:34.267+0800 [TRACE] Stdout is a terminal of width 198
2024-03-07T13:38:34.267+0800 [TRACE] Stderr is a terminal of width 198
2024-03-07T13:38:34.267+0800 [TRACE] Stdin is a terminal
2024-03-07T13:38:34.267+0800 [DEBUG] Attempting to open CLI config file: /home/magodo/.terraformrc
2024-03-07T13:38:34.267+0800 [INFO]  Loading CLI configuration from /home/magodo/.terraformrc
2024-03-07T13:38:34.267+0800 [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2024-03-07T13:38:34.267+0800 [DEBUG] ignoring non-existing provider search directory /home/magodo/.terraform.d/plugins
2024-03-07T13:38:34.267+0800 [DEBUG] ignoring non-existing provider search directory /home/magodo/.local/share/terraform/plugins
2024-03-07T13:38:34.267+0800 [DEBUG] ignoring non-existing provider search directory /usr/local/share/terraform/plugins
2024-03-07T13:38:34.267+0800 [DEBUG] ignoring non-existing provider search directory /usr/share/terraform/plugins
2024-03-07T13:38:34.268+0800 [INFO]  CLI command args: []string{"init"}

Initializing the backend...
2024-03-07T13:38:34.269+0800 [TRACE] Meta.Backend: no config given or present on disk, so returning nil config
2024-03-07T13:38:34.269+0800 [TRACE] Meta.Backend: backend has not previously been initialized in this working directory
2024-03-07T13:38:34.269+0800 [DEBUG] New state was assigned lineage "faa16da8-6f83-086e-e859-5bb56fd36ed8"
2024-03-07T13:38:34.269+0800 [TRACE] Meta.Backend: using default local state only (no backend configuration, and no existing initialized backend)
2024-03-07T13:38:34.269+0800 [TRACE] Meta.Backend: instantiated backend of type 
2024-03-07T13:38:34.269+0800 [DEBUG] checking for provisioner in "."
2024-03-07T13:38:34.270+0800 [DEBUG] checking for provisioner in "/usr/bin"
2024-03-07T13:38:34.270+0800 [TRACE] Meta.Backend: backend  does not support operations, so wrapping it in a local backend
2024-03-07T13:38:34.270+0800 [TRACE] backend/local: state manager for workspace "default" will:
 - read initial snapshot from terraform.tfstate
 - write new snapshots to terraform.tfstate
 - create any backup at terraform.tfstate.backup
2024-03-07T13:38:34.270+0800 [TRACE] statemgr.Filesystem: reading initial snapshot from terraform.tfstate
2024-03-07T13:38:34.270+0800 [TRACE] statemgr.Filesystem: snapshot file has nil snapshot, but that's okay
2024-03-07T13:38:34.270+0800 [TRACE] statemgr.Filesystem: read nil snapshot

Initializing provider plugins...
- Finding latest version of hashicorp/azurerm...
2024-03-07T13:38:34.270+0800 [DEBUG] Service discovery for registry.terraform.io at https://registry.terraform.io/.well-known/terraform.json
2024-03-07T13:38:34.270+0800 [TRACE] HTTP client GET request to https://registry.terraform.io/.well-known/terraform.json
2024-03-07T13:38:34.564+0800 [DEBUG] GET https://registry.terraform.io/v1/providers/hashicorp/azurerm/versions
2024-03-07T13:38:34.564+0800 [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/hashicorp/azurerm/versions
2024-03-07T13:38:34.837+0800 [TRACE] providercache.fillMetaCache: scanning directory .terraform/providers
2024-03-07T13:38:34.837+0800 [TRACE] getproviders.SearchLocalDirectory: failed to resolve symlinks for .terraform/providers: lstat .terraform: no such file or directory
2024-03-07T13:38:34.837+0800 [TRACE] providercache.fillMetaCache: error while scanning directory .terraform/providers: cannot search .terraform/providers: lstat .terraform/providers: no such file or directory
2024-03-07T13:38:34.837+0800 [TRACE] providercache.fillMetaCache: scanning directory /home/magodo/.terraform.d/plugin-cache
2024-03-07T13:38:34.837+0800 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/azuread v2.38.0 for linux_amd64 at /home/magodo/.terraform.d/plugin-cache/registry.terraform.io/hashicorp/azuread/2.38.0/linux_amd64
2024-03-07T13:38:34.837+0800 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/azurerm v3.94.0 for linux_amd64 at /home/magodo/.terraform.d/plugin-cache/registry.terraform.io/hashicorp/azurerm/3.94.0/linux_amd64
2024-03-07T13:38:34.837+0800 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/time v0.9.1 for linux_amd64 at /home/magodo/.terraform.d/plugin-cache/registry.terraform.io/hashicorp/time/0.9.1/linux_amd64
2024-03-07T13:38:34.837+0800 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/tls v4.0.4 for linux_amd64 at /home/magodo/.terraform.d/plugin-cache/registry.terraform.io/hashicorp/tls/4.0.4/linux_amd64
2024-03-07T13:38:34.837+0800 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/tls v4.0.5 for linux_amd64 at /home/magodo/.terraform.d/plugin-cache/registry.terraform.io/hashicorp/tls/4.0.5/linux_amd64
2024-03-07T13:38:34.837+0800 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/vancluever/acme v2.20.2 for linux_amd64 at /home/magodo/.terraform.d/plugin-cache/registry.terraform.io/vancluever/acme/2.20.2/linux_amd64
2024-03-07T13:38:34.837+0800 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/vancluever/acme v2.7.1 for linux_amd64 at /home/magodo/.terraform.d/plugin-cache/registry.terraform.io/vancluever/acme/2.7.1/linux_amd64
2024-03-07T13:38:34.837+0800 [TRACE] providercache.fillMetaCache: including /home/magodo/.terraform.d/plugin-cache/registry.terraform.io/hashicorp/azuread/2.38.0/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/azuread 2.38.0
2024-03-07T13:38:34.837+0800 [TRACE] providercache.fillMetaCache: including /home/magodo/.terraform.d/plugin-cache/registry.terraform.io/hashicorp/azurerm/3.94.0/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/azurerm 3.94.0
2024-03-07T13:38:34.837+0800 [TRACE] providercache.fillMetaCache: including /home/magodo/.terraform.d/plugin-cache/registry.terraform.io/hashicorp/time/0.9.1/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/time 0.9.1
2024-03-07T13:38:34.837+0800 [TRACE] providercache.fillMetaCache: including /home/magodo/.terraform.d/plugin-cache/registry.terraform.io/hashicorp/tls/4.0.4/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/tls 4.0.4
2024-03-07T13:38:34.837+0800 [TRACE] providercache.fillMetaCache: including /home/magodo/.terraform.d/plugin-cache/registry.terraform.io/hashicorp/tls/4.0.5/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/tls 4.0.5
2024-03-07T13:38:34.837+0800 [TRACE] providercache.fillMetaCache: including /home/magodo/.terraform.d/plugin-cache/registry.terraform.io/vancluever/acme/2.7.1/linux_amd64 as a candidate package for registry.terraform.io/vancluever/acme 2.7.1
2024-03-07T13:38:34.837+0800 [TRACE] providercache.fillMetaCache: including /home/magodo/.terraform.d/plugin-cache/registry.terraform.io/vancluever/acme/2.20.2/linux_amd64 as a candidate package for registry.terraform.io/vancluever/acme 2.20.2
2024-03-07T13:38:34.837+0800 [DEBUG] GET https://registry.terraform.io/v1/providers/hashicorp/azurerm/3.94.0/download/linux/amd64
2024-03-07T13:38:34.837+0800 [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/hashicorp/azurerm/3.94.0/download/linux/amd64
2024-03-07T13:38:35.136+0800 [DEBUG] GET https://releases.hashicorp.com/terraform-provider-azurerm/3.94.0/terraform-provider-azurerm_3.94.0_SHA256SUMS
2024-03-07T13:38:35.136+0800 [TRACE] HTTP client GET request to https://releases.hashicorp.com/terraform-provider-azurerm/3.94.0/terraform-provider-azurerm_3.94.0_SHA256SUMS
2024-03-07T13:38:35.544+0800 [DEBUG] GET https://releases.hashicorp.com/terraform-provider-azurerm/3.94.0/terraform-provider-azurerm_3.94.0_SHA256SUMS.72D7468F.sig
2024-03-07T13:38:35.545+0800 [TRACE] HTTP client GET request to https://releases.hashicorp.com/terraform-provider-azurerm/3.94.0/terraform-provider-azurerm_3.94.0_SHA256SUMS.72D7468F.sig
- Installing hashicorp/azurerm v3.94.0...
2024-03-07T13:38:35.636+0800 [TRACE] providercache.Dir.InstallPackage: installing registry.terraform.io/hashicorp/azurerm v3.94.0 from https://releases.hashicorp.com/terraform-provider-azurerm/3.94.0/terraform-provider-azurerm_3.94.0_linux_amd64.zip
2024-03-07T13:38:35.636+0800 [TRACE] HTTP client GET request to https://releases.hashicorp.com/terraform-provider-azurerm/3.94.0/terraform-provider-azurerm_3.94.0_linux_amd64.zip

Only when I enable plugin_cache_may_break_dependency_lock_file, it stopps the re-downloading. I suspect this is also unexpected?

haidaraM commented 4 days ago

Same problem here. If you enable plugin_cache_may_break_dependency_lock_file, you now get a warning which a bit annoying. This used to work before, IIRC.