0
0
Terraformcloud~10 mins

Provider caching and mirrors in Terraform - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Provider caching and mirrors
Terraform Init Starts
Check Provider Source
Is Mirror Configured?
NoDownload from Original Source
Yes
Redirect to Mirror URL
Download Provider
Cache Provider Locally
Use Cached Provider for Terraform Run
Terraform Run Continues
Terraform checks if a mirror is configured for a provider source. If yes, it downloads from the mirror and caches it locally for faster future use.
Execution Sample
Terraform
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.0"
    }
  }
  provider_installation {
    filesystem_mirror {
      path    = "/terraform-mirror"
      include = ["hashicorp/aws"]
    }
    direct {
      exclude = ["hashicorp/aws"]
    }
  }
}
This Terraform configuration sets up a local filesystem mirror for the AWS provider and uses direct download for others.
Process Table
StepActionProvider SourceMirror Configured?Download LocationCache Status
1Terraform init startshashicorp/awsYesRedirect to /terraform-mirrorNo
2Check local cachehashicorp/awsYesLocal cache checkNo
3Download providerhashicorp/awsYesFrom /terraform-mirrorNo
4Cache provider locallyhashicorp/awsYesCached at /terraform-cacheYes
5Use cached providerhashicorp/awsYesFrom /terraform-cacheYes
6Terraform run continueshashicorp/awsYesUsing cached providerYes
7Check another providercustom/providerNoDownload from original sourceNo
8Download providercustom/providerNoFrom original sourceNo
9Cache provider locallycustom/providerNoCached at /terraform-cacheYes
10Use cached providercustom/providerNoFrom /terraform-cacheYes
11Terraform run continuescustom/providerNoUsing cached providerYes
💡 Terraform finishes initialization using cached providers or downloads if not cached.
Status Tracker
VariableStartAfter Step 3After Step 4After Step 5Final
cache_status_awsNoNoYesYesYes
cache_status_customNoNoNoYesYes
Key Moments - 3 Insights
Why does Terraform redirect to a mirror URL instead of the original provider source?
Terraform redirects to the mirror URL when a mirror is configured for that provider source, as shown in execution_table step 1, to speed up downloads and reduce external calls.
What happens if a provider is not included in the mirror configuration?
If a provider is not included in the mirror configuration, Terraform downloads it directly from the original source, as seen in execution_table steps 7 and 8.
How does caching improve Terraform runs?
Caching stores downloaded providers locally (execution_table step 4), so subsequent runs use the cached version (step 5), making initialization faster and offline-capable.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does Terraform cache the AWS provider locally?
AStep 4
BStep 5
CStep 3
DStep 6
💡 Hint
Check the 'Cache provider locally' action for AWS provider in execution_table.
According to variable_tracker, what is the cache status of the custom provider after step 5?
ANo
BYes
CUnknown
DNot applicable
💡 Hint
Look at cache_status_custom column after step 5 in variable_tracker.
If the mirror configuration is removed, how would the download location for the AWS provider change in the execution_table?
AIt would fail to download
BIt would remain the same as /terraform-mirror
CIt would change to direct download from original source
DIt would download from cache only
💡 Hint
Refer to execution_table steps 1 and 7 for mirror vs no mirror download locations.
Concept Snapshot
Terraform Provider Caching & Mirrors:
- Configure mirrors to redirect provider downloads.
- Terraform downloads from mirror if configured.
- Providers are cached locally after download.
- Cached providers speed up future runs.
- Providers not in mirror download directly.
- Use 'provider_installation' block to set mirrors.
Full Transcript
This visual execution shows how Terraform handles provider caching and mirrors during initialization. Terraform first checks if a mirror is configured for a provider source. If yes, it redirects the download to the mirror location. The provider is then downloaded and cached locally. Subsequent Terraform runs use the cached provider to speed up initialization. Providers not included in the mirror configuration are downloaded directly from their original sources and cached similarly. This process improves efficiency and reliability of Terraform runs.