Problem
When running terraform plan (either remotely or directly in the Terraform Cloud UI), the following error message may be encountered:
Error: No Terraform configuration files found in working directory
Terraform requires configuration files to plan changes. Planning without a
configuration would mark everything for destruction, which is normally not what
is desired. If you would like to destroy everything, queue a destroy plan
instead. Otherwise, create a Terraform configuration file (.tf file), or check
that the working directory is set correctly on the workspace, and try again.
Operation failed: failed checking for terraform files: lstat /home/tfc-agent/.tfc-agent/component/terraform/runs/run-XXXXXXXXXXXXXXXX/config/my_terraform_working_dir: no such file or directory
Cause
Once a run is triggered remotely or queued within the UI, Terraform Cloud will clone the content of the VCS repo into the /home/tfc-agent/.tfc-agent/component/terraform/runs/run-XXXXXXXXXXXXXXXX/config/
directory on the TF Cloud agent node. If there is a Terraform Working Directory defined within the UI Workspace located under General Settings
> Terraform Working Directory
Terraform will then attempt to execute cd path/to/working/directory
and will run the Terraform code located in this directory. The directory and path configured in the TFC workspace Terraform Working Directory must match the location and name within the VCS repo that is attached to the Workspace or the run will fail.
Solutions:
Make sure the directory name that is listed in the error message Operation failed: failed checking for terraform files: lstat
exists in your VCS repo and that the correct path to it is set for the TFC workspace Terraform Working Directory.
Outcome
When the directory and path are configured appropriately Terraform will be able to resolve the directory and its contents and the Plan/run will be successful.
Additional Information
- For additional assistance please contact HashiCorp Support to request additional assistance.