Create portable Terraform and plugins with Terraform-bundle for Windows

The steps below are what I have followed to create a terraform-bundle to use terraform with non default providers on a server that doesn’t have access to Internet. You can find the tool explanation in the below link.
https://github.com/hashicorp/terraform/tree/master/tools/terraform-bundle

installation of golang with msi downloaded here
https://golang.org/doc/install

Clone the terraform repository to get the tool
https://github.com/hashicorp/terraform.git

cd terraform-master
go install .\tools\terraform-bundle

Check the terraform version

C:\Users\noyel\Desktop\tfforeach\nsxt>terraform version
Terraform v0.14.6
+ provider registry.terraform.io/vmware/nsxt v3.0.1

Create a terraform-bundle.hcl file

terraform {
  # Version of Terraform to include in the bundle. An exact version number
  # is required.
  version = "0.14.6"
}

# Define which provider plugins are to be included
providers {
  # Include the newest "nsxt" provider version in the 1.0 series.
  nsxt = {
    source = "vmware/nsxt"
    versions = ["~> 3.0.0"]
  }
}

Create the bundle

C:\Users\noyel\Desktop\tfforeach\nsxt>terraform-bundle package terraform-bundle.hcl
Fetching Terraform 0.14.6 core package...
Local plugin directory ".plugins" found; scanning for provider binaries.
No ".plugins" directory found, skipping local provider discovery.
- Finding vmware/nsxt versions matching "~> 3.0.0"...
- Installing vmware/nsxt v3.0.1...
Creating terraform_0.14.6-bundle2021021713_windows_amd64.zip ...
All done!

Move the zip file to the server you want to use. Unzip the file. For a basic utilization move the terraform.exe and plugins in the directory where your terraform files are.

The provider.tf file looks

terraform {
  required_providers {
    nsxt = {
      source = "vmware/nsxt"
      version = "3.0.1"
    }
  }
}

provider "nsxt" {
   host = "1.2.3.4"
   username   = "admin"
   password   = "123"
}

When initialize Terraform with the init command, specify the plugins directory.

C:\Users\bubibi\terraform\terraform init -plugin-dir=C:\Users\bubibi\terraform\plugins

Terraform has been successfuly initialized!

Related