How to fix Error: No configuration files in Terraform
The 'No configuration files' error occurs when Terraform cannot find any .tf files in the working directory. This typically happens when you're in the wrong directory, your files lack the correct extension, or the workspace is misconfigured. Navigate to the correct directory containing your Terraform files to resolve it.
Quick fix
Fixes Error: No configuration files
pwd
ls -la- Verify your current directory
- Navigate to the Terraform root directory
- Check file extensions
- Verify Terraform files exist
pwdls -laError: No configuration files
What this error means
This error means Terraform was invoked in a directory that contains no Terraform configuration files (files with the .tf extension). By default, Terraform includes all *.tf files in the current working directory as part of the root module configuration. When you run commands like `terraform init`, `terraform plan`, or `terraform apply`, Terraform searches the current directory for configuration files. If it finds none, it cannot proceed because there's nothing to plan or apply. This error is straightforward but occurs frequently when working with multiple Terraform projects or when following tutorials that assume a specific directory structure.
Typical symptoms
- Error appears when running terraform init, terraform plan, or terraform apply
- Error message includes 'No configuration files. Plan requires configuration to be present'
- Commands complete successfully in one directory but fail in another
- Working from a subdirectory instead of the root Terraform directory
- CI/CD pipelines fail when the working directory isn't set correctly
- Message suggests: "Planning without a configuration would mark everything for destruction"
- Recently cloned a repository and running commands from wrong folder
Common causes
- Running Terraform commands from the wrong directory (not where .tf files are located)
- Terraform files don't have the .tf extension (e.g., named config.txt or main instead of main.tf)
- All Terraform files are in a subdirectory but you're running commands from the parent directory
- TF_WORKSPACE environment variable is set incorrectly, pointing to a different workspace
- In CI/CD environments, the working directory path isn't configured to match the Terraform root module
- Module source URLs are incorrect, causing Terraform to look in the wrong location
- Files were accidentally deleted or moved from the expected directory
How to fix "Error: No configuration files"
Check where you are in the filesystem and list the contents:
pwd
ls -laLook for files ending in .tf. If you see nothing or only other files (like .json or .yaml), you're likely in the wrong directory.
Change to the directory containing your Terraform configuration files:
cd /path/to/your/terraform
ls *.tfYou should see at least one file with a .tf extension (commonly main.tf, variables.tf, or outputs.tf). If you still see nothing, your files may be in a subdirectory—keep exploring.
Terraform only recognizes files ending in .tf. If you have configuration files with different extensions, rename them:
# Wrong - these won't be recognized
ls
# main, config.txt, terraform.yml
# Right - these will be recognized
mv main main.tf
mv config.txt config.tfAll files in the directory ending in .tf will be loaded, regardless of name. You can organize them as main.tf, variables.tf, outputs.tf, etc.
List all .tf files in your current directory and subdirectories:
find . -name "*.tf" -type fIf you find files in a subdirectory, either:
- Move to that subdirectory before running Terraform, or
- Use the -chdir option to specify the directory:
terraform -chdir=./terraform init
terraform -chdir=./terraform planOnce you're in the right directory with .tf files present, initialize Terraform:
cd /path/to/your/terraform
terraform initYou should see output indicating providers are being installed. If you still get the error, double-check that at least one .tf file exists in the current directory.
For GitHub Actions:
- name: Terraform Init
working-directory: ./terraform
run: terraform initFor GitLab CI:
terraform-plan:
script:
- cd terraform
- terraform init
- terraform planFor other CI systems, ensure the working directory is set to the folder containing your .tf files before running any Terraform commands.
If you have set the TF_WORKSPACE environment variable, verify it's pointing to a valid workspace:
echo $TF_WORKSPACE
unset TF_WORKSPACE
terraform initTry unsetting the workspace variable and reinitializing. If that works, your workspace configuration was incorrect.
Advanced notes
When Terraform is initialized with a remote backend (like Terraform Cloud or S3), it stores state remotely but still requires local .tf files to function. The "No configuration files" error will occur even with a properly configured backend if .tf files are missing locally.
For monorepo setups where you have multiple Terraform configurations in different directories, consider using a wrapper script or Makefile to ensure you're always running Terraform from the correct directory:
#!/bin/bash
cd terraform/$(echo $1 | cut -d/ -f1)
terraform $@In CI/CD pipelines, use terraform -chdir instead of cd commands to avoid directory context issues that might affect subsequent commands or steps. This makes your pipeline more explicit and maintainable.
Frequently asked questions
- What does "Error: No configuration files" mean?
- tf extension). tf files in the current working directory as part of the root module configuration. When you run commands like terraform init, terraform plan, or terraform apply, Terraform searches the current directory for configuration files.
- How do I fix "Error: No configuration files"?
- The 'No configuration files' error occurs when Terraform cannot find any .tf files in the working directory. This typically happens when you're in the wrong directory, your files lack the correct extension, or the workspace is misconfigured. Navigate to the correct directory containing your Terraform files to resolve it.
- What causes "Error: No configuration files"?
- Running Terraform commands from the wrong directory (not where .tf files are located) Terraform files don't have the .tf extension (e.g., named config.txt or main instead of main.tf) All Terraform files are in a subdirectory but you're running commands from the parent directory
- Is the "Error: No configuration files" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚Terraform Official Documentation
- 🐙GitHub - Terraform Issue #34974(GitHub)
- 📖Terraform CLI - terraform init(Official Docs)