Skip to content
Error: No configuration files

Error: No configuration files

DodaTech 3 min read

Terraform’s “No configuration files” error means no .tf or .tf.json files exist in the current directory. Terraform needs them to plan or apply.

What It Means

Terraform scans the current directory for files ending in .tf or .tf.json. When none are found, it refuses to proceed. This usually happens because you’re in the wrong directory, the files have a different extension, or no configuration has been written yet.

Why It Happens

  • You’re in a directory that doesn’t contain Terraform configuration files.
  • The configuration files use a wrong extension (e.g. .txt instead of .tf).
  • You cloned a repository but haven’t changed into the correct subdirectory.
  • You ran terraform plan before creating any .tf files.
  • The configuration is in a parent or subdirectory but not in the current one.
  • Hidden files or symlinks are causing confusion.

How to Fix It

Step 1: Verify you’re in the right directory

Check what’s in your current directory:

ls -la *.tf

If you see files like main.tf or variables.tf, you’re in the right place. If not, check if the configuration exists in another directory:

find .. -name "*.tf"

Change to the correct directory:

cd /path/to/your/terraform-config/

Step 2: Create a basic configuration file

If no configuration exists yet, create a minimal main.tf:

terraform {
  required_version = ">= 1.0"
}

resource "local_file" "example" {
  content  = "hello world"
  filename = "${path.module}/example.txt"
}

Step 3: Check file extensions

Terraform only recognizes .tf and .tf.json files. Rename any files with incorrect extensions:

mv myconfig.txt main.tf

Step 4: Initialize the directory

Some providers require terraform init to download modules and providers before they can be found:

terraform init

If you’re using modules, ensure they’re downloaded:

terraform get

Step 5: Run from the root module

Terraform expects you to run commands from the root module directory. If your project has subdirectories for each environment:

ls environments/production/
terraform plan   # ❌ wrong directory
cd environments/production && terraform plan  # ✅ correct
Can Terraform read .tf files from subdirectories?
Only if you use -chdir=<path> to point Terraform at the subdirectory, or if the subdirectory is a called module. Terraform does not recursively scan parent directories looking for .tf files — you must run the command from the module root.
What happens if I run terraform apply without any configuration?
Terraform will immediately return “No configuration files” and exit. It will not destroy or modify any existing infrastructure unless you explicitly run terraform destroy. The error is purely about missing input files.
Does terraform init alone create configuration files?
No — terraform init only initializes the working directory by downloading providers and modules referenced in existing .tf files. You must create or copy .tf files into the directory before or after running init. The terraform workspace new command also does not create configuration files.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro