TF Mirror

TF Mirror is a mirror/proxy for publicly available Terraform registries, like the Hashicorp Terraform Registry. TF Mirror is simple to configure and provides end-users the added benefit of knowing the domain (tfmirror.dev) in which all downloading Terraform provider and module source files come from. This is different than the typical flow with the Hashicorp Terraform Registry which redirects end-users multiple times to various domains to ultimately serve the provider and module source files. To view a list of all of the TF Mirror URLs or to learn more about the inner workings, checkout the Technical Details section at the bottom of this page.

Configuration

Below are the end-user configuration steps to use TF Mirror as the source to obtain Terraform providers and modules.

Providers

Consume a Terraform provider through TF Mirror by configuring a network mirror within your Terraform CLI Configuration File.
Note: Only Terraform providers from publicly accessible provider registries, like Hashicorp Terraform Registry, can be mirrored.

    
provider_installation {
    network_mirror {
        url = "https://tfmirror.dev/"
    }
}
    
    

Modules

Consume a Terraform module through TF Mirror by prepending the TF Mirror domain hostname (tfmirror.dev) to the beginning of a standard registry module source URL.
Note: Currently only modules from the Hashicorp Terraform Registry can be mirrored.

The example below updates the source attribute to include the tfmirror.dev domain hostname for the original module source terraform-aws-modules/alb/aws

module "example1" {
    source = "tfmirror.dev/terraform-aws-modules/alb/aws"
    version = "8.2.1"
}

    

Technical Details

Below is the general request flow of obtaining provider or module source files along with the TF Mirror domain and URLs used.

The first request made by an end-user's Terraform is for a list of available versions for the requested provider or module. Upon this first request, if not cached, TF Mirror will request a list of available versions from the original Terraform registry source for the requested provider or module. TF Mirror will cache the returned list of available provider or module versions for the next 24 hours. End-user requests for the list of available version will be served from TF Mirror's cache for the next 24 hours, upon which the process starts over. TF Mirror's caches the list of available versions to minimize the need for round-trip calls to the original Terraform registry source.

The next requests made by the end-user's Terraform is for the download of a specific provider or module version. Upon these requests, if not cached, TF Mirror will request the specific provider or module version source files and store them in TF Mirror's cache. After which, TF Mirror direct end-user's Terraform to a download to provider or module source from TF Mirror's cache downloads URL.

All of this is handled behind the scenes by TF Mirror and the end-user won't even notice. End-users will only ever access the TF Mirror domain of tfmirror.dev

Provider Mirror Steps/URLs

  1. https://tfmirror.dev/{provider_registry_host}/{provider_namespace}/{provider_name}/index.json
  2. https://tfmirror.dev/{provider_registry_host}/{provider_namespace}/{provider_name}/{version_number}.json
  3. https://tfmirror.dev/{provider_registry_host}/{provider_namespace}/{provider_name}/terraform-provider-{provider_name}_{provider_version}_{provider_os}_{provider_architecture}.download
  4. https://tfmirror.dev/downloads/providers/{provider_registry_host}/{provider_namespace}/{provider_name}/terraform-provider-{provider_name}_{provider_version}_{provider_os}_{provider_architecture}.zip

Module Steps/URLs

  1. https://tfmirror.dev/.well-known/terraform.json
  2. https://tfmirror.dev/v1/modules/{module_namespace}/{module_name}/{module_provider}/versions
  3. https://tfmirror.dev/v1/modules/{module_namespace}/{module_name}/{module_provider}/{module_version}/download
  4. https://tfmirror.dev/downloads/modules/{module_namespace}/{module_name}/{module_provider}/{module_version}.zip

TF Mirror came about as a weekend project, by @Chammock, to further understand the internal workings of the Terraform provider and module registry protocols, along with the Terraform Network Provider Mirror protocol. TF Mirror is completely open source, so to learn more checkout Chammock's blog post or the TF Mirror GitHub project.