Error: No configuration files
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.
.txtinstead of.tf). - You cloned a repository but haven’t changed into the correct subdirectory.
- You ran
terraform planbefore creating any.tffiles. - 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 *.tfIf 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.tfStep 4: Initialize the directory
Some providers require terraform init to download modules and providers before they can be found:
terraform initIf you’re using modules, ensure they’re downloaded:
terraform getStep 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 # ✅ correctBuilt by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro