Bird
Raised Fist0
Terraformcloud~20 mins

Provider caching and mirrors in Terraform - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
πŸŽ–οΈ
Provider Mirror Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Terraform Provider Mirror Usage

What is the primary benefit of configuring a provider mirror in Terraform?

AIt reduces the need to download providers repeatedly by caching them locally or on a private server.
BIt automatically updates Terraform core to the latest version.
CIt encrypts all provider binaries to enhance security during downloads.
DIt allows Terraform to run without any internet connection permanently.
Attempts:
2 left
πŸ’‘ Hint

Think about how mirrors help with repeated downloads in other software.

❓ Configuration
intermediate
2:00remaining
Configuring a Provider Mirror in Terraform

Which of the following Terraform CLI configuration snippets correctly sets a provider mirror for registry.terraform.io to a local file path /mnt/terraform-providers?

A
provider_installation {
  filesystem_mirror {
    path    = "/mnt/terraform-providers"
    include = ["registry.terraform.io/*"]
  }
  direct {
    exclude = ["registry.terraform.io/*"]
  }
}
B
provider_installation {
  mirror {
    url = "/mnt/terraform-providers"
  }
}
C
provider_installation {
  filesystem_mirror {
    path    = "/mnt/terraform-providers"
    exclude = ["registry.terraform.io/*"]
  }
  direct {}
}
D
provider_installation {
  direct {
    path    = "/mnt/terraform-providers"
    include = ["registry.terraform.io/*"]
  }
}
Attempts:
2 left
πŸ’‘ Hint

Look for the block that defines a filesystem mirror and includes the correct registry.

❓ Architecture
advanced
2:00remaining
Designing a Provider Mirror for Multiple Teams

Your company has multiple teams using Terraform. You want to set up a centralized provider mirror server to cache providers and reduce internet usage. Which architecture best supports this goal?

AConfigure each team’s Terraform to use different mirrors to avoid single points of failure.
BRequire each team to download providers directly from the public Terraform registry without caching.
CUse a cloud storage bucket without HTTP access and have teams manually copy providers from it.
DSet up a private HTTP server hosting cached provider binaries and configure all team Terraform CLI configs to use this mirror URL.
Attempts:
2 left
πŸ’‘ Hint

Think about how a shared HTTP mirror can serve multiple clients efficiently.

❓ security
advanced
2:00remaining
Security Considerations for Provider Mirrors

When using a private provider mirror server, which security practice is most important to ensure provider integrity?

AAllow anonymous access to the mirror server for convenience.
BVerify provider checksums and signatures before caching and serving them to clients.
CDisable TLS to speed up downloads from the mirror server.
DModify provider binaries to add company branding before caching.
Attempts:
2 left
πŸ’‘ Hint

Think about how to trust the providers you distribute internally.

❓ service_behavior
expert
2:00remaining
Terraform Provider Mirror Fallback Behavior

Given a Terraform CLI configured with a filesystem mirror for registry.terraform.io providers, what happens if a requested provider version is not found in the mirror?

ATerraform prompts the user to manually download and place the provider in the mirror.
BTerraform skips the provider and continues without it, causing runtime errors later.
CTerraform automatically downloads the provider directly from the public registry and caches it in the mirror path.
DTerraform fails immediately with an error stating the provider is missing in the mirror.
Attempts:
2 left
πŸ’‘ Hint

Consider how Terraform handles missing providers in mirrors to maintain smooth runs.

Practice

(1/5)
1. What is the main purpose of provider caching in Terraform?
easy
A. To encrypt provider plugins for security
B. To store provider plugins locally and speed up Terraform runs
C. To delete unused providers automatically
D. To force Terraform to always download providers from the internet

Solution

  1. Step 1: Understand provider caching concept

    Provider caching means saving provider plugins on your local machine so Terraform doesn't need to download them every time.
  2. Step 2: Identify the benefit of caching

    This local storage speeds up Terraform runs by avoiding repeated downloads.
  3. Final Answer:

    To store provider plugins locally and speed up Terraform runs -> Option B
  4. Quick Check:

    Provider caching = local storage for speed [OK]
Hint: Caching means saving locally to avoid repeated downloads [OK]
Common Mistakes:
  • Thinking caching deletes providers
  • Confusing caching with encryption
  • Assuming caching forces downloads
2. Which block is used in Terraform configuration to specify a local directory for provider caching?
easy
A. direct
B. cache_location
C. filesystem_mirror
D. provider_cache

Solution

  1. Step 1: Recall Terraform provider mirror blocks

    Terraform uses filesystem_mirror blocks to define local directories for caching providers.
  2. Step 2: Confirm correct block name

    The direct block is for direct downloads, not caching. Other options are invalid.
  3. Final Answer:

    filesystem_mirror -> Option C
  4. Quick Check:

    Local cache directory = filesystem_mirror [OK]
Hint: Filesystem mirror means local cache folder [OK]
Common Mistakes:
  • Confusing direct with caching block
  • Using non-existent block names
  • Assuming provider_cache is valid
3. Given this Terraform CLI configuration snippet:
provider_installation {
  filesystem_mirror {
    path    = "/cache/providers"
  }
  direct {
    exclude = ["hashicorp/aws"]
  }
}

What happens when Terraform needs the hashicorp/aws provider?
medium
A. Terraform downloads hashicorp/aws directly from the internet
B. Terraform uses the cached version from /cache/providers
C. Terraform throws an error because hashicorp/aws is excluded
D. Terraform ignores the provider and continues without it

Solution

  1. Step 1: Analyze the filesystem_mirror and direct blocks

    The filesystem_mirror caches providers locally except those excluded in direct.
  2. Step 2: Understand the exclude setting

    The direct block excludes hashicorp/aws, so Terraform will not use the cache for it.
  3. Step 3: Determine provider source

    Terraform downloads hashicorp/aws directly from the internet.
  4. Final Answer:

    Terraform downloads hashicorp/aws directly from the internet -> Option A
  5. Quick Check:

    Exclude means direct download [OK]
Hint: Exclude in direct means download from internet [OK]
Common Mistakes:
  • Assuming excluded providers use cache
  • Thinking exclusion causes errors
  • Believing providers are ignored if excluded
4. You configured a filesystem_mirror path but Terraform still downloads providers from the internet. What is the most likely cause?
medium
A. The filesystem_mirror path is incorrect or inaccessible
B. Terraform does not support provider caching
C. You forgot to install Terraform CLI
D. The provider version is not specified in configuration

Solution

  1. Step 1: Check filesystem_mirror path validity

    If the path is wrong or Terraform cannot access it, caching won't work and providers download from the internet.
  2. Step 2: Rule out other causes

    Terraform supports caching, CLI must be installed, and version absence doesn't force downloads if cache is valid.
  3. Final Answer:

    The filesystem_mirror path is incorrect or inaccessible -> Option A
  4. Quick Check:

    Invalid cache path causes downloads [OK]
Hint: Check cache path accessibility first [OK]
Common Mistakes:
  • Assuming Terraform lacks caching support
  • Ignoring filesystem permissions
  • Blaming missing provider version
5. You want to speed up Terraform runs in a team by caching providers locally but still allow direct downloads for some custom providers. Which configuration correctly achieves this?
hard
A.
provider_installation {
  direct {
    include = ["customcorp/custom"]
  }
  filesystem_mirror {
    path = "/team/cache"
  }
}
B.
provider_installation {
  direct {
    path = "/team/cache"
  }
  filesystem_mirror {
    exclude = ["customcorp/custom"]
  }
}
C.
provider_installation {
  filesystem_mirror {
    exclude = ["customcorp/custom"]
  }
  direct {
    path = "/team/cache"
  }
}
D.
provider_installation {
  filesystem_mirror {
    path = "/team/cache"
  }
  direct {
    exclude = ["customcorp/custom"]
  }
}

Solution

  1. Step 1: Understand correct block usage

    filesystem_mirror defines the local cache path; direct defines providers to download directly.
  2. Step 2: Check correct syntax and order

    provider_installation {
      filesystem_mirror {
        path = "/team/cache"
      }
      direct {
        exclude = ["customcorp/custom"]
      }
    }
    correctly sets filesystem_mirror with path and direct with exclude list for custom providers.
  3. Step 3: Identify incorrect options

    Other options misuse keys or swap path and exclude incorrectly.
  4. Final Answer:

    provider_installation {
      filesystem_mirror {
        path = "/team/cache"
      }
      direct {
        exclude = ["customcorp/custom"]
      }
    }
    -> Option D
  5. Quick Check:

    Cache path in filesystem_mirror, exclude in direct [OK]
Hint: Cache path in filesystem_mirror, exclude in direct block [OK]
Common Mistakes:
  • Swapping path and exclude keys
  • Putting exclude in filesystem_mirror
  • Misplacing blocks order