Closed mkyc closed 10 hours ago
Hey @mkyc,
Thanks for reporting this! Based on our documentation on module sources and supported archives (https://developer.hashicorp.com/terraform/language/modules/sources), I'd expect your use case to be valid and working.
I'm able to reproduce your issue using:
module "example" {
source = "s3::https://36080.s3.us-west-2.amazonaws.com/example.tbz2"
}
From a quick look, it seems that Terraform is successfully downloading the archive into the .terraform
directory:
2024-11-22T18:27:33.851+0100 [TRACE] ModuleInstaller: installing child modules for . into .terraform/modules
2024-11-22T18:27:33.851+0100 [DEBUG] Module installer: begin example
2024-11-22T18:27:33.851+0100 [TRACE] ModuleInstaller: example is not yet installed
2024-11-22T18:27:33.851+0100 [TRACE] ModuleInstaller: cleaning directory .terraform/modules/example prior to install of example
2024-11-22T18:27:33.851+0100 [TRACE] ModuleInstaller: example address "s3::https://36080.s3.us-west-2.amazonaws.com/example.tbz2" will be handled by go-getter
Downloading s3::https://36080.s3.us-west-2.amazonaws.com/example.tbz2 for example...
2024-11-22T18:27:33.851+0100 [TRACE] getmodules: fetching "s3::https://36080.s3.us-west-2.amazonaws.com/example.tbz2" to ".terraform/modules/example"
2024-11-22T18:27:34.809+0100 [TRACE] ModuleInstaller: example "s3::https://36080.s3.us-west-2.amazonaws.com/example.tbz2" was downloaded to .terraform/modules/example
2024-11-22T18:27:34.809+0100 [DEBUG] Module installer: example installed at .terraform/modules/example
It seems the download is successful, but something further down the line is causing an issue. I noticed the downloaded archive is missing a file extension, which is causing the “Unreadable module directory” error diagnostic to surface.
$ tree .terraform
.terraform
└── modules
├── modules.json
└── example
FWIW, uploading a copy of my archive, using a tar.tbz2 extension seems to work.
- source = "s3::https://36080.s3.us-west-2.amazonaws.com/example.tbz2"
+ source = "s3::https://36080.s3.us-west-2.amazonaws.com/example.tar.tbz2"
It’s possible that the documentation referencing the tbz2
file extension, is currently not supported.
From my understanding—though feel free to correct me if I’m wrong—tbz2, tar.tbz2 and tar.bz2 use the same compression algorithm (bzip2), with tbz2 being just a shorthand for the longer tar.tbz2 and tar.bz2 extensions[¹].
For clarity and to avoid confusion:
tar.bz2
, tar.tbz2
, tbz2
: Tar archives compressed with bzip2.bz2
: General bzip2-compressed file.In go-getter, the library Terraform uses to download files and directories from various sources, there is a decompressor for tar archives compressed with bzip2 that can handle both tbz2, tar.tbz2 and tar.bz2 files[²].
It seems we may have overlooked support for the tbz2 archive extension, causing the fetching process (via the getter) to succeed but leading to a decompression failure. This results in an unexpected file without an extension.
I’ll provide an update here as soon as I have more information. Thanks again!
Hi @bschaatsbergen,
thanks for solid investigation! I think you ticked all the boxes with your explanation 👍
Terraform Version
Terraform Configuration Files
irrelevant
Debug Output
irrelevant
Expected Behavior
Actual Behavior
I moved some of my modules to S3 as they can be served from there as described here.
As described archive can be of different extension as described in section above.
But when archive is in .tbz2 it doesn't work. With zip it's ok.
Steps to Reproduce
there is file:
and it is archive because I can extract it manually, but it doesn't get extracted by terraform.
With zip it works.
Additional Context
content of those two packages:
References
No response