Problem
A custom provider bundle works correctly when used directly on a Terraform Enterprise (TFE) server, but fails during a plan or apply when executed by a remote agent. The run fails with an error message indicating a file creation issue because a directory already exists.
Operation failed: failed unpacking Terraform: failed creating file"/root/.tfc-agent/component/terraform/runs/run-xxxx.plan/.terraform.d/plugins":open /root/.tfc-agent/component/terraform/runs/run-xxx.plan/.terraform.d/plugins: is a directoryxxxplan/.terraform.d/plugins: is a directory
This issue can occur with custom, official, or community providers packaged in a custom bundle.
Prerequisites
- Terraform Enterprise with remote agents configured.
- A custom provider bundle created using the
zipcommand-line utility.
Cause
This error occurs when the .zip archive for the provider bundle is created without excluding directory entries. By default, the zip utility includes directory structures in the archive. The TFE agent's unpacking process cannot handle these directory entries and fails when it attempts to create a file where a directory path already exists from the archive.
Solution
To resolve this issue, you must create the .zip archive without including directory entries.
When using the zip utility to create the bundle, include the -D or --no-dir-entries flag. This flag ensures that only files are added to the archive, which allows the TFE agent to unpack the bundle correctly.
- Navigate to the directory containing your provider plugins.
Create the bundle using the
zipcommand with the-Dflag.$ zip -rD my-bundle.zip .
After creating the bundle with this flag, upload it to your Terraform Enterprise instance. Subsequent runs using this bundle on remote agents should complete successfully.
Additional Information
- While using
zipwith the correct flag is a valid solution, HashiCorp recommends using theterraform-bundlecommand to create provider bundles for Terraform Enterprise. For more information, please refer to the official documentation for creating custom provider bundles.