I am trying to build a VM using terraform from my office's network. I am getting the following error because the server doesn't have internet access. Is there anyway I can download the plugins offline?
Initializing provider plugins...
- Checking for available provider plugins...
Registry service unreachable.
This may indicate a network issue, or an issue with the requested Terraform Registry.
Error: registry service is unreachable, check https://status.hashicorp.com/ for status updates
Note: The instructions in this comment were correct when I originally wrote it, but the situation changed slightly from Terraform v0.13 and later because Terraform now supports automatic installation from multiple namespaces in multiple registries.
You can find more information about configuring automatic plugin installation for modern Terraform in the CLI Configuration documentation, specifically in the Provider Installation section.
I've preserved the content below, and it remains roughly true for modern Terraform in that Terraform still supports -plugin-dir as a legacy alternative to the provider_installation settings, but the content below is mainly useful only for Terraform v0.12 and earlier.
By default Terraform makes requests to registry.terraform.io to find provider plugins. If you are running Terraform in a context where it cannot access services over the internet directly then you can indeed ask Terraform to run in a local-only mode with regard to plugins.
To do that, first locate the provider plugin executables you wish to use. At the time of writing those are on releases.hashicorp.com, though that location might change in future.
Extract the zip files you downloaded into a single directory, so you end up with a flat directory with only executable files in it named something like this:
terraform-provider-aws_v2.0.0
terraform-provider-null_v1.0.0
terraform-provider-template_v2.0.0
Once you've populated this plugin directory, you can run terraform init with the extra option -plugin-dir, passing the path to the directory you just populated. For example:
terraform init -plugin-dir=/opt/terraform/plugins
When you use -plugin-dir, this disables Terraform's automatic discovery and download functions and instructs it to look only in this local directory. terraform init will return errors if any of the necessary plugins aren't in that directory, in which case you can download these extra plugins into your directory to fix that.
Note that Terraform plugins are versioned, and Terraform will only accept a plugin that matches the version constraints given in the configuration. Normally the auto-install behavior can select a suitable version automatically, but when you are downloading plugins manually yourself you will need to select suitable versions.
Terraform has a command terraform providers which will print out the provider requirements for the current configuration, as a prompt to help you decide which versions to download.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With