Courseiva
Understand Terraform basicseasyMultiple ChoiceObjective-mapped

TF-004 Understand Terraform basics Practice Question

A junior engineer cloned a Terraform repository from GitHub and ran terraform init inside the project directory. The command downloaded the required provider plugins successfully. Next, they ran terraform plan and received the following error: 'Error: No configuration files found in the current directory.' The engineer checked and confirmed that the main.tf file exists in the current directory. What is the most likely cause of this error?

⚠ Common exam trap

HashiCorp often tests the subtle distinction between file existence and file recognition by Terraform, exploiting the common assumption that any file in the directory will be read, when in fact only files with the exact `.tf` extension are parsed.

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 file is named main.tf.txt instead of main.tf

Terraform requires configuration files to have the `.tf` extension to be recognized. If the file is named `main.tf.txt` (e.g., due to Windows hiding known file extensions or accidental renaming), Terraform will not parse it as a configuration file, resulting in the 'No configuration files found' error even though the file exists in the directory. The `terraform init` command succeeded because it only downloads providers and modules, not requiring `.tf` files to be present.

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 file is named main.tf.txt instead of main.tf

    Why this is correct

    Terraform's configuration loader specifically scans for files ending with the `.tf` extension within the working directory and its subdirectories. Files named with other extensions, such as `.tf.txt`, are completely ignored during the parsing phase, even if they contain valid HCL syntax. Consequently, if the primary configuration is misnamed, Terraform will report that no configuration files were found, as it simply doesn't recognize the file as part of its operational scope. This prevents accidental inclusion of non-Terraform files.

  • The terraform init command was not run with -upgrade flag

    Why it's wrong here

    The `terraform init -upgrade` flag is used to upgrade provider plugins to the newest available versions that satisfy the configuration's version constraints. While `terraform init` is crucial for initializing a working directory, the `-upgrade` flag specifically influences provider resolution, not the initial discovery or parsing of `.tf` configuration files. If Terraform cannot find any `.tf` files, `init` would fail much earlier, indicating "No configuration files," regardless of whether an upgrade was requested.

  • The main.tf file contains syntax errors

    Why it's wrong here

    If the `main.tf` file contained syntax errors, Terraform would successfully discover the file due to its correct `.tf` extension. However, during the parsing phase, it would then report specific syntax error messages, indicating the line and column where the error occurred, rather than stating that no configuration files were found. The "No configuration files" error explicitly means Terraform couldn't even identify any files to parse in the first place, distinguishing it from parsing failures.

  • The terraform plan command requires the -out flag

    Why it's wrong here

    The `terraform plan` command does not require the `-out` flag to execute successfully. The `-out` flag is an optional parameter used to save the generated execution plan to a specified file, which can then be passed to `terraform apply` for a precise, verified application. Without `-out`, `terraform plan` will still generate and display the proposed changes to standard output, but it will not persist the plan for later use, which is a common and valid workflow.

About these practice questions

This TF-004 question is part of Courseiva's 428-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. 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.