Introduction
This article provides solutions for a Setup failed: Failed to copy tfVars file error that can occur during a terraform init operation in a Terraform Enterprise workspace. This error typically indicates a misconfiguration of the Terraform Working Directory setting.
Problem
When you run terraform init in a Terraform Enterprise workspace, the operation may fail with the following error message.
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
This error occurs when Terraform Enterprise cannot find the specified working directory inside its execution container. This is usually because the Terraform Working Directory setting in the workspace points to a path that does not exist in your version control system (VCS) repository.
Solutions
Solution 1: Verify the Terraform Working Directory Setting
Check the workspace settings in the Terraform Enterprise UI to confirm if a working directory is configured.
- Navigate to your workspace in the Terraform Enterprise UI.
- Go to Settings > General.
- Inspect the Terraform Working Directory field.
If a path is specified, ensure it is the correct path for your configuration files. If the field should be empty, remove the path and save the settings.
Solution 2: Confirm the Working Directory Exists in the VCS Repository
If a working directory is correctly specified in the workspace settings, you must verify that this directory path exists in your connected VCS repository.
For example, if the working directory is set to terraform/environments/shared, confirm that this exact path exists at the root of your repository. If the directory does not exist, create it in your repository and commit the change.
After you verify the setting is correct and the directory exists in your VCS repository, the terraform init operation should succeed.
Additional Information
For more details on this setting, refer to the Terraform Working Directory documentation.