Courseiva
Interact with Terraform modulesmediumMultiple ChoiceObjective-mapped

TF-004 Interact with Terraform modules Practice Question

A team is using a private module registry from a third-party vendor. When running terraform init, they receive an error: 'Error downloading module: could not download module... server responded with 401 Unauthorized'. What is the most likely cause?

⚠ Common exam trap

HashiCorp often tests the distinction between authentication errors (401) and authorization errors (403) or network connectivity errors, so candidates may incorrectly attribute a 401 to a wrong URL or firewall issue instead of missing or invalid credentials.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

The registry credentials are missing or invalid.

The 401 Unauthorized error indicates that the request to the private module registry was received but authentication failed. Private registries require valid credentials (such as an API token or username/password) to be configured, typically via a `.terraformrc` or `credentials` block in the CLI configuration. Without these, Terraform cannot authenticate and the download is rejected.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • The module source URL is incorrect.

    Why it's wrong here

    An incorrect module source URL would typically result in an HTTP 404 Not Found error, indicating that the requested resource path does not exist on the server. This differs fundamentally from a 401 Unauthorized error, which signifies that the server *found* the resource but rejected access because the client failed to provide valid authentication credentials. Therefore, a URL typo would not trigger a 401 response.

  • The registry credentials are missing or invalid.

    Why this is correct

    An HTTP 401 Unauthorized response explicitly indicates that the request lacks valid authentication credentials for the target resource. When interacting with a private module registry, Terraform requires specific credentials, often an API token or username/password, configured via a `credentials.tfrc.json` file or environment variables. If these credentials are either missing from Terraform's configuration or are invalid/expired, the registry server will correctly deny access with a 401 status.

  • The Terraform version is too old for the module.

    Why it's wrong here

    Terraform module compatibility based on version constraints is handled client-side by the Terraform CLI itself, not by the module registry server. If the `required_version` specified within a module's `terraform` block is incompatible with the local Terraform CLI version, Terraform will exit with a specific error message detailing the version mismatch *before* attempting to download the module, rather than receiving an HTTP 401 from the registry.

  • The network firewall is blocking outbound connections.

    Why it's wrong here

    A network firewall blocking outbound connections would prevent the Terraform CLI from establishing a TCP connection to the private module registry's server entirely. This scenario typically manifests as a connection timeout, a "no route to host" error, or a similar low-level network error, rather than an HTTP status code. An HTTP 401 implies a successful TCP connection and an application-layer response from the server, which would not occur if the firewall was blocking the connection.

About these practice questions

One of 428 original TF-004 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This TF-004 practice question is part of Courseiva's free HashiCorp certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the TF-004 exam.