Skip to content

Instantly share code, notes, and snippets.

@straubt1
Last active August 5, 2025 16:02
Show Gist options
  • Select an option

  • Save straubt1/95a834b82ffebb4db63d8509dd4ce0e4 to your computer and use it in GitHub Desktop.

Select an option

Save straubt1/95a834b82ffebb4db63d8509dd4ce0e4 to your computer and use it in GitHub Desktop.
Local Terraform Init Without Downloading Providers
#!/bin/bash
# Define providers as name/version pairs
architecture="darwin_arm64"
providers=(
"random/3.7.2"
"aws/5.30.0"
"azurerm/3.80.0"
)
# Clean up in case things were run before
unset TF_PLUGIN_CACHE_DIR
rm -rf .terraform .terraform.lock.hcl terraform.rc mirror
LOCAL_PLUGIN_DIR="$(pwd)/mirror"
# Loop over providers place dummy files
for provider in "${providers[@]}"; do
name="${provider%%/*}"
version="${provider##*/}"
provider_dir="${LOCAL_PLUGIN_DIR}/registry.terraform.io/hashicorp/${name}/${version}/${architecture}"
mkdir -p "${provider_dir}"
touch "${provider_dir}/terraform-provider-${name}_v${version}_x5"
done
terraform init -plugin-dir "${LOCAL_PLUGIN_DIR}"
# Remove the lock file
rm .terraform.lock.hcl
# Output of running this script:
# ./local-init.sh
# Initializing the backend...
# Initializing provider plugins...
# - Finding hashicorp/random versions matching "3.7.2"...
# - Finding hashicorp/aws versions matching "5.30.0"...
# - Installing hashicorp/random v3.7.2...
# - Installed hashicorp/random v3.7.2 (unauthenticated)
# - Installing hashicorp/aws v5.30.0...
# - Installed hashicorp/aws v5.30.0 (unauthenticated)
# Terraform has created a lock file .terraform.lock.hcl to record the provider
# selections it made above. Include this file in your version control repository
# so that Terraform can guarantee to make the same selections by default when
# you run "terraform init" in the future.
#
# ╷
# │ Warning: Incomplete lock file information for providers
# │
# │ Due to your customized provider installation methods, Terraform was forced to calculate
# │ lock file checksums locally for the following providers:
# │ - hashicorp/aws
# │ - hashicorp/random
# │
# │ The current .terraform.lock.hcl file only includes checksums for darwin_arm64, so Terraform
# │ running on another platform will fail to install these providers.
# │
# │ To calculate additional checksums for another platform, run:
# │ terraform providers lock -platform=linux_amd64
# │ (where linux_amd64 is the platform to generate)
# ╵
# Terraform has been successfully initialized!
#
# You may now begin working with Terraform. Try running "terraform plan" to see
# any changes that are required for your infrastructure. All Terraform commands
# should now work.
#
# If you ever set or change modules or backend configuration for Terraform,
# rerun this command to reinitialize your working directory. If you forget, other
# commands will detect it and remind you to do so if necessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment