Find out how to configure Terraform to make use of Native Suppliers from Nexus


In case your group has blocked registry.terraform.io and has as an alternative downloaded the supplier binaries to Nexus, then you are able to do the next to nonetheless make your Terraform execute accurately.

Step 1 – Obtain the Required Suppliers

In our instance, we’d like the next suppliers:

  1. AWS
  2. Archive

These instructions under are working straight from the pipeline that executes the Terraform:

# Obtain the suppliers from the Nexus repository
- curl -u ${Nexus_REPO_USER}:${Nexus_REPO_PASS} -o terraform-provider-aws4.65.0linuxamd64.zip https://nexus.instance.com/repository/some-local-mirror/registry.terraform.io/hashicorp/aws/terraform-provider-aws_4.65.0_linux_amd64.zip
- curl -u ${Nexus_REPO_USER}:${Nexus_REPO_PASS} -o terraform-provider-archive_2.3.0_linux_amd64.zip https://nexus.instance.com/repository/local-mirror/registry.terraform.io/hashicorp/archive/terraform-provider-archive_2.3.0_linux_amd64.zip
# Make a neighborhood listing to retailer these suppliers
- mkdir -p $HOME/.terraform.d/plugins/registry.terraform.io/hashicorp/aws/
- mkdir -p $HOME/.terraform.d/plugins/registry.terraform.io/hashicorp/archive/
# Transfer the downloaded zip information to those directories
- mv terraform-provider-aws_4.65.0_linux_amd64.zip $HOME/.terraform.d/plugins/registry.terraform.io/hashicorp/aws/
- mv terraform-provider-archive_2.3.0_linux_amd64.zip $HOME/.terraform.d/plugins/registry.terraform.io/hashicorp/archive/
# Give the permissions (not all the time required)
- chmod 777 -R $HOME/.terraform.d/plugins/

Step 2 – Run the Terraform code with a Plugin Listing

The next code continues the pipeline from above the place we left off:

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

Step 3 – Replace the terraform block to the identical variations as above

Now we have to modify or add the next code into our Terraform code:

terraform {

  required_providers {
    aws = {
      supply = "hashicorp/aws"
      model = "4.65.0"
    }
    archive = {
      supply = "hashicorp/archive"
      model = "2.3.0"
    }
  }

  # Add different options you want right here... e.g.
  # backend "s3" {
  #  ...
  #}

}

Leave a Reply

Your email address will not be published. Required fields are marked *