Command: providers mirror
Theterraform providers mirror command downloads provider plugins required by the current configuration and saves them to a local directory.
Usage
Description
This command populates a local directory with copies of the provider plugins needed for the current configuration. The resulting directory can be used either:- Directly as a filesystem mirror - Configure Terraform to install providers from this local directory
- As the basis for a network mirror - Publish the directory contents on an HTTP server for remote access
Arguments
<target-dir>(required) - The directory path where provider packages should be saved.
Options
Platform Options
-
-platform=os_arch- Choose which target platform to build a mirror for. By default, Terraform obtains plugin packages suitable only for the platform where you run this command. Use this flag multiple times to include packages for multiple target systems. Target names consist of an operating system and a CPU architecture. For example,linux_amd64selects the Linux operating system running on an AMD64 or x86_64 CPU. Common platforms:linux_amd64- Linux on AMD64/x86_64linux_arm64- Linux on ARM64darwin_amd64- macOS on Intel processorsdarwin_arm64- macOS on Apple Silicon (M1/M2/M3)windows_amd64- Windows on AMD64/x86_64
Lock File Options
-
-lock-file=false- Ignore the provider lock file when fetching providers. By default (when-lock-file=true), the mirror command uses the version information in the lock file if the configuration directory has been previously initialized. This ensures the mirrored versions match what’s already locked. Set tofalseto select the newest available version matching the configuration’s version constraints instead.
Behavior
The command:- Reads the current configuration to determine provider requirements
- Checks the dependency lock file (if present and
-lock-fileis not disabled) - Validates lock file against configuration requirements
- For each required provider:
- Queries the origin registry for available versions
- Selects the appropriate version (from lock file or newest matching constraints)
- Downloads packages for each specified platform
- Authenticates packages using registry signatures
- Saves packages to the target directory
- Generates JSON index files for network mirror compatibility
Version Selection
The command selects provider versions using this logic:- If a lock file exists and
-lock-file=true(default): Uses the locked version - Otherwise: Uses the newest version matching the configuration’s version constraints
- If no constraints are specified: Uses the newest available version
Package Authentication
For each downloaded package, Terraform:- Verifies the package against registry-provided checksums
- Validates cryptographic signatures when available
- Reports the authentication result (e.g., “signed by HashiCorp”)
Output Files
The command creates a directory structure compatible with both filesystem and network mirrors:Index Files
JSON index files are generated for network mirror compatibility:index.json- Lists all available versions for a provider<version>.json- Lists all platforms and download URLs for a specific version
terraform init when configured to use a network mirror, but are ignored for filesystem mirrors.
Examples
Basic Mirror for Current Platform
Create a mirror with providers for the current platform:Multi-Platform Mirror
Create a mirror supporting Linux, macOS (both Intel and Apple Silicon), and Windows:Mirror Without Lock File
Create a mirror using the newest available versions instead of locked versions:Mirror for Production
Create a comprehensive production mirror:Output Example
Use Cases
Offline Environments
Create a provider mirror for use in air-gapped or restricted network environments:-
On a machine with internet access:
-
Transfer the
./providersdirectory to the offline environment -
Configure Terraform to use the filesystem mirror in
~/.terraformrc:
Network Mirror Setup
Create a network mirror to share providers across a team:-
Create the mirror:
- Serve the directory via HTTPS (e.g., using nginx, Apache, or a cloud storage service)
-
Configure team members to use the network mirror:
CI/CD Pipeline Optimization
Cache providers in CI/CD to speed up deployments:Disaster Recovery
Maintain a backup of critical provider versions:Using the Mirror
Filesystem Mirror
Configure Terraform to use a local filesystem mirror in~/.terraformrc or .terraformrc:
Network Mirror
Configure Terraform to use a network mirror:Important Notes
- The command always consults the origin registry, even if you have a local mirror configured in your CLI configuration. This ensures the mirror is populated with authentic packages.
- Downloaded packages are authenticated using registry signatures before being saved.
- The command does not optimize for packages already present; it always downloads everything required.
- Run this command periodically to keep your mirror up to date with new provider versions.
Related Commands
terraform providers lock- Generate lock file with checksumsterraform providers- Show provider requirementsterraform init- Initialize and download providersterraform providers schema- Show provider schemas