How to Configure Terraform to Use Local Providers From Nexus

If your organization has blocked and has instead downloaded the provider binaries to Nexus, then you can do the following to still make your Terraform execute correctly.

Step 1 - Download the Required Providers

In our example, we need the following providers:

  1. AWS
  2. Archive

These commands below are running directly from the pipeline that executes the Terraform:

# Download the providers from the Nexus repository
- curl -u ${Nexus_REPO_USER}:${Nexus_REPO_PASS} -o
- curl -u ${Nexus_REPO_USER}:${Nexus_REPO_PASS} -o
# Make a local directory to store these providers
- mkdir -p $HOME/.terraform.d/plugins/
- mkdir -p $HOME/.terraform.d/plugins/
# Move the downloaded zip files to these directories
- mv $HOME/.terraform.d/plugins/
- mv $HOME/.terraform.d/plugins/
# Give the permissions (not always required)
- chmod 777 -R $HOME/.terraform.d/plugins/

Step 2 - Run the Terraform code with a Plugin Directory

The following code continues the pipeline from above where we left off:

# Add the "-plugin-dir" to use the same location as above
- terraform init -plugin-dir=$HOME/.terraform.d/plugins/ -backend-config=env/dev/backend.conf -reconfigure-force-copy

Step 3 - Update the terraform block to the same versions as above

Now we need to modify or add the following code into our Terraform code:

terraform {

  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "4.65.0"
    archive = {
      source = "hashicorp/archive"
      version = "2.3.0"

  # Add other features you need here... e.g.
  # backend "s3" {
  #  ...