TL;DR; I couldn’t repeat it in a clean setup. So I must have gotten something wrong somewhere/somehow!
So. Here we go!
$ find . -type f | grep -v idea
./archive.tf
./.terraform-version
.terraform-version
:
1.7.5
.achive.tf
terraform {
required_version = ">= 1.3.0"
required_providers {
archive = {
source = "hashicorp/archive"
version = "2.4.2"
}
}
}
data "archive_file" "this_file" {
type = "zip"
source_file = "${path.module}/archive.tf"
output_path = "${path.module}/archive.zip"
}
No lock file and no TF_
envvars:
$ env | grep TF_
Running terraform providers lock -platform=darwin_amd64 -platform=linux_amd64 -platform=darwin_arm64
$ terraform providers lock -platform=darwin_amd64 -platform=linux_amd64 -platform=darwin_arm64
- Fetching hashicorp/archive 2.4.2 for darwin_amd64...
- Retrieved hashicorp/archive 2.4.2 for darwin_amd64 (signed by HashiCorp)
- Fetching hashicorp/archive 2.4.2 for linux_amd64...
- Retrieved hashicorp/archive 2.4.2 for linux_amd64 (signed by HashiCorp)
- Fetching hashicorp/archive 2.4.2 for darwin_arm64...
- Retrieved hashicorp/archive 2.4.2 for darwin_arm64 (signed by HashiCorp)
- Obtained hashicorp/archive checksums for darwin_amd64; This was a new provider and the checksums for this platform are now tracked in the lock file
- Obtained hashicorp/archive checksums for linux_amd64; This was a new provider and the checksums for this platform are now tracked in the lock file
- Obtained hashicorp/archive checksums for darwin_arm64; This was a new provider and the checksums for this platform are now tracked in the lock file
e[1me[32mSuccess!e[0m e[1mTerraform has updated the lock file.e[0me[0m
Review the changes in .terraform.lock.hcl and then commit to your
version control system to retain the new checksums.
.terraform.lock.hcl
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/archive" {
version = "2.4.2"
constraints = "2.4.2"
hashes = [
"h1:1eOz9vM/55vnQjxk23RhnYga7PZq8n2rGxG+2Vx2s6w=",
"h1:G4v6F6Lhqlo3EKGBKEK/kJRhNcQiRrhEdUiVpBHKHOA=",
"h1:WfIjVbYA9s/uN2FwhGoiffT7CLFydy7MT1waFbt9YrY=",
"zh:08faed7c9f42d82bc3d406d0d9d4971e2d1c2d34eae268ad211b8aca57b7f758",
"zh:3564112ed2d097d7e0672378044a69b06642c326f6f1584d81c7cdd32ebf3a08",
"zh:53cd9afd223c15828c1916e68cb728d2be1cbccb9545568d6c2b122d0bac5102",
"zh:5ae4e41e3a1ce9d40b6458218a85bbde44f21723943982bca4a3b8bb7c103670",
"zh:5b65499218b315b96e95c5d3463ea6d7c66245b59461217c99eaa1611891cd2c",
"zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3",
"zh:7f45b35a8330bebd184c2545a41782ff58240ed6ba947274d9881dd5da44b02e",
"zh:87e67891033214e55cfead1391d68e6a3bf37993b7607753237e82aa3250bb71",
"zh:de3590d14037ad81fc5cedf7cfa44614a92452d7b39676289b704a962050bc5e",
"zh:e7e6f2ea567f2dbb3baa81c6203be69f9cd6aeeb01204fd93e3cf181e099b610",
"zh:fd24d03c89a7702628c2e5a3c732c0dede56fa75a08da4a1efe17b5f881c88e2",
"zh:febf4b7b5f3ff2adff0573ef6361f09b6638105111644bdebc0e4f575373935f",
]
}
Run terraform -init
$ terraform init
Initializing the backend...
Initializing provider plugins...
- Reusing previous version of hashicorp/archive from the dependency lock file
- Installing hashicorp/archive v2.4.2...
- Installed hashicorp/archive v2.4.2 (signed by HashiCorp)
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
The only provider in .terraform/providers
:
./.terraform/providers/registry.terraform.io/hashicorp/archive/2.4.2/darwin_arm64:
total 29584
drwxr-xr-x 3 arrayqueue staff 96B 10 Apr 16:34 ./
drwxr-xr-x 3 arrayqueue staff 96B 10 Apr 16:34 ../
-rwxr-xr-x 1 arrayqueue staff 14M 10 Apr 16:34 terraform-provider-archive_v2.4.2_x5*
Run terraform validate
:
$ terraform validate
Success! The configuration is valid.
So far so good.
Now removing the lock and providers, setting the envvar, creating an empty directory for the envvar and rerunning.
$ export TF_PLUGIN_CACHE_DIR=$HOME/dev/tf-plugin-cache && mkdir $TF_PLUGIN_CACHE_DIR && ls -al $TF_PLUGIN_CACHE_DIR
total 0
drwxr-xr-x 2 arrayqueue staff 64B 10 Apr 16:38 ./
drwxr-xr-x 9 arrayqueue staff 288B 10 Apr 16:38 ../
$ rm -rf .terraform
.terraform/providers/registry.terraform.io/hashicorp/archive/2.4.2/darwin_arm64/terraform-provider-archive_v2.4.2_x5
.terraform/providers/registry.terraform.io/hashicorp/archive/2.4.2/darwin_arm64
.terraform/providers/registry.terraform.io/hashicorp/archive/2.4.2
.terraform/providers/registry.terraform.io/hashicorp/archive
.terraform/providers/registry.terraform.io/hashicorp
.terraform/providers/registry.terraform.io
.terraform/providers
.terraform
$ rm .terraform.lock.hcl
remove .terraform.lock.hcl? y
.terraform.lock.hcl
$ find . -type f | grep -v idea
./archive.tf
./.terraform-version
All reset.
Locks
$ terraform providers lock -platform=darwin_amd64 -platform=linux_amd64 -platform=darwin_arm64
- Fetching hashicorp/archive 2.4.2 for darwin_amd64...
- Retrieved hashicorp/archive 2.4.2 for darwin_amd64 (signed by HashiCorp)
- Fetching hashicorp/archive 2.4.2 for linux_amd64...
- Retrieved hashicorp/archive 2.4.2 for linux_amd64 (signed by HashiCorp)
- Fetching hashicorp/archive 2.4.2 for darwin_arm64...
- Retrieved hashicorp/archive 2.4.2 for darwin_arm64 (signed by HashiCorp)
- Obtained hashicorp/archive checksums for darwin_amd64; This was a new provider and the checksums for this platform are now tracked in the lock file
- Obtained hashicorp/archive checksums for linux_amd64; This was a new provider and the checksums for this platform are now tracked in the lock file
- Obtained hashicorp/archive checksums for darwin_arm64; This was a new provider and the checksums for this platform are now tracked in the lock file
Success! Terraform has updated the lock file.
Review the changes in .terraform.lock.hcl and then commit to your
version control system to retain the new checksums.
.terraform.lock.hcl
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/archive" {
version = "2.4.2"
constraints = "2.4.2"
hashes = [
"h1:1eOz9vM/55vnQjxk23RhnYga7PZq8n2rGxG+2Vx2s6w=",
"h1:G4v6F6Lhqlo3EKGBKEK/kJRhNcQiRrhEdUiVpBHKHOA=",
"h1:WfIjVbYA9s/uN2FwhGoiffT7CLFydy7MT1waFbt9YrY=",
"zh:08faed7c9f42d82bc3d406d0d9d4971e2d1c2d34eae268ad211b8aca57b7f758",
"zh:3564112ed2d097d7e0672378044a69b06642c326f6f1584d81c7cdd32ebf3a08",
"zh:53cd9afd223c15828c1916e68cb728d2be1cbccb9545568d6c2b122d0bac5102",
"zh:5ae4e41e3a1ce9d40b6458218a85bbde44f21723943982bca4a3b8bb7c103670",
"zh:5b65499218b315b96e95c5d3463ea6d7c66245b59461217c99eaa1611891cd2c",
"zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3",
"zh:7f45b35a8330bebd184c2545a41782ff58240ed6ba947274d9881dd5da44b02e",
"zh:87e67891033214e55cfead1391d68e6a3bf37993b7607753237e82aa3250bb71",
"zh:de3590d14037ad81fc5cedf7cfa44614a92452d7b39676289b704a962050bc5e",
"zh:e7e6f2ea567f2dbb3baa81c6203be69f9cd6aeeb01204fd93e3cf181e099b610",
"zh:fd24d03c89a7702628c2e5a3c732c0dede56fa75a08da4a1efe17b5f881c88e2",
"zh:febf4b7b5f3ff2adff0573ef6361f09b6638105111644bdebc0e4f575373935f",
]
}
Testing terraform validate
fails as no terraform init
yet run.
$ terraform validate
╷
│ Error: registry.terraform.io/hashicorp/archive: there is no package for registry.terraform.io/hashicorp/archive 2.4.2 cached in .terraform/providers
│
│
╵
Running terraform init
$ terraform init
Initializing the backend...
Initializing provider plugins...
- Reusing previous version of hashicorp/archive from the dependency lock file
- Installing hashicorp/archive v2.4.2...
- Installed hashicorp/archive v2.4.2 (signed by HashiCorp)
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
We now have a new file in the cache directory
$ ls -alR $TF_PLUGIN_CACHE_DIR
(snipped out the directory elements)
/Users/arrayqueue/dev/tf-plugin-cache/registry.terraform.io/hashicorp/archive/2.4.2/darwin_arm64:
total 29584
drwxr-xr-x 3 arrayqueue staff 96B 10 Apr 16:43 ./
drwxr-xr-x 3 arrayqueue staff 96B 10 Apr 16:43 ../
-rwxr-xr-x 1 arrayqueue staff 14M 10 Apr 16:43 terraform-provider-archive_v2.4.2_x5*
Local files:
$ find . -type f | grep -v idea
./archive.tf
./.terraform-version
./.terraform.lock.hcl
No provider for a “file”, so check for “links”:
$ find . -type l | grep -v idea
./.terraform/providers/registry.terraform.io/hashicorp/archive/2.4.2/darwin_arm64
$ ls -alR .
(snipped)
./.terraform/providers/registry.terraform.io/hashicorp/archive/2.4.2:
total 0
drwxr-xr-x 3 arrayqueue staff 96B 10 Apr 16:43 ./
drwxr-xr-x 3 arrayqueue staff 96B 10 Apr 16:43 ../
lrwxr-xr-x 1 arrayqueue staff 96B 10 Apr 16:43 darwin_arm64@ -> /Users/arrayqueue/dev/tf-plugin-cache/registry.terraform.io/hashicorp/archive/2.4.2/darwin_arm64
At this stage, the .terraform.lock.hcl
file is unmodified. The same 3 h1
s.
Running terraform validate
:
$ terraform validate
Success! The configuration is valid.
Which is odd. I changed the required version to ~> 2.0
. No difference.
So this suggests that there’s something else going on.
Added some extra providers:
terraform {
required_version = ">= 1.3.0"
required_providers {
archive = {
source = "hashicorp/archive"
version = "~> 2.0"
}
aws = {
source = "hashicorp/aws"
version = "~> 5"
}
cloudflare = {
source = "cloudflare/cloudflare"
version = "~> 4.0"
}
random = {
source = "hashicorp/random"
version = "~> 3.0"
}
}
}
The cache directory has the extra files (as expected), and the validation passes.
Moving the location of the plugin directory to the usual documented location $HOME/.terraform.d/plugin-cache
$ export TF_PLUGIN_CACHE_DIR=$HOME/.terraform.d/plugin-cache && mkdir $TF_PLUGIN_CACHE_DIR && ll $TF_PLUGIN_CACHE_DIR
total 16
drwxr-xr-x 3 arrayqueue staff 96B 9 Apr 10:03 ./
drwxr-xr-x 7 arrayqueue staff 224B 9 Apr 11:24 ../
-rw-r--r--@ 1 arrayqueue staff 6.0K 9 Apr 10:03 .DS_Store
Do all the things. No change there!
And so now I’M stuck!
And so, I’ll leave this for now.
I’ll slowly add more to my test setup and see if it is something daft like Make getting in the way (we have a LOT of Makefile content to help reduce the amount of typing and Make is sort of everywhere, and so a nice simple way of doing everything everywhere all the time … ish).