Troubleshooting tfvars error
Introduction
The Terraform working directory is where Terraform will execute, specified as a relative path from the root of the configuration directory. Defaults to the root of the configuration directory.
Terraform Cloud will change to this directory before starting a Terraform run, and will report an error if the directory does not exist.
Setting a working directory creates a default filter for automatic run triggering, and sometimes causes CLI-driven runs to upload additional configuration content.
Problem
Some Terraform Enterprise instances may encounter the following error when trying to perform a terraform init
function:
Setup failed: Failed to copy tfVars file: Failed copying file "/tmp/terraform-build-worker443011914/terraform.tfvars" to "b5df3588-f0ba-cd4d-531b-211fda64b8c4:/terraform/environments/shared/terraform.tfvars": exit status 1
Output:
Error response from daemon: Could not find the file /terraform/environments/shared in container b5df3588-f0ba-cd4d-531b-211fda64b8c4
Cause
The error could be related to the use, or misconfiguration, of a working directory within the Terraform Enterprise settings.
Solution
First, check and see if a working directory has been specified within the Terraform Enterprise settings:
-
Verify that no working directory is set by browsing to the TFE web interface, logging in and examining the Workspace in question. Under
settings>general>Terraform Working Directory
see if any subdirectory has been configured there. If so, try running theinit
function again with this option:terraform init ${working_dir}
. -
If the setting is blank we want to check that the subdirectory actually exists In the VCS repository. If not, please create it in:
/terraform/environments/shared
Please note that the actual directory will likely be different than the one used in this example scenario.
By verifying the working directory is correct, or actually exists in the VCS repository, the terraform init
function should work without issue.
Additional Information
Terraform working directory details: https://www.terraform.io/docs/cloud/workspaces/settings.html#terraform-working-directory