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.
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.
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.
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.
Error: Error rendering template: template not found
How to fix "template not found" error in Terraform
Error: Error generating private key
How to fix 'Error generating private key' in Terraform
Error creating Kubernetes Service: field is immutable
How to fix "field is immutable" errors in Terraform
Error: Error creating local file: open: permission denied
How to fix "Error creating local file: permission denied" in Terraform
Error: line endings have changed from CRLF to LF
Line endings have changed from CRLF to LF in Terraform