Pre-installed Plugins not work as expected


I’m working with different modules in my terraform repository and I want to pre-install in a folder and used it locally:

Terraform Doc

But I try to init my plugin folder with the following command and never find the modules:

terraform init -plugin-dir ./terraform-plugins
Initializing the backend...
2022-02-28T16:39:18.639+0100 [DEBUG] New state was assigned lineage "182fcd76-13c9-fce4-25f8-4e31fc6afd98"
2022-02-28T16:39:18.639+0100 [DEBUG] checking for provisioner in "./terraform-plugins"
2022-02-28T16:39:18.639+0100 [DEBUG] init: overriding provider plugin search paths
2022-02-28T16:39:18.639+0100 [DEBUG] will search for provider plugins in [./terraform-plugins]

Initializing provider plugins...
- Finding latest version of hashicorp/aws...
│ Error: Failed to query available provider packages
│ Could not retrieve the list of available versions for provider hashicorp/aws: provider was not found in any of
│ the search locations
│   - ./terraform-plugins

Inside the folder I have the following providers, are the same but with different names, because I’m not sure what is the reason to don’t find the provider by terraform.

└── terraform-plugins
    ├── terraform-provider-aws
    └── terraform-provider-aws_v4.1.0

I using terraform 0.15.3

Can someone help me to define the structure to automatically find by terraform the plugins?

Thank you!

1 Like

Hi @albertoCrego,

Terraform requires a particular directory structure under a filesystem mirror directory, so that it can use the directory names to understand which provider, version, and platform this executable is intended for.

You can use either of the layouts mentioned in the filesystem_mirror documentation:

  • Packed layout: HOSTNAME/NAMESPACE/TYPE/ is the distribution zip file obtained from the provider’s origin registry.
  • Unpacked layout: HOSTNAME/NAMESPACE/TYPE/VERSION/TARGET is a directory containing the result of extracting the provider’s distribution zip file.

In your case then, your executable file should be placed at the following path, to use the unpacked layout :

The PLATFORM part here will be a string like linux_amd64 specifying the operating system and architecture you’re using Terraform on. You can find out which one you need by running terraform version.

Unfortunately the documentation you linked to seems to be outdated; it’s describing something that would’ve worked for Terraform v0.12 or earlier but hasn’t been valid since Terraform v0.13, which is the first version that supported third-party providers and thus required providers to be identified by a HOSTNAME/NAMESPACE/TYPE address.