Problem
With no changes in Terraform code, Terraform Cloud runs errored with errors related to files/directories missing.
E.g.
- On argument
filenameofaws_lambda_functionresource - On using
templatefilefunction - On using
externaldata source
Cause
From Terraform Cloud document
Terraform Cloud performs Terraform runs in single-use Linux virtual machines, running on an x86_64 architecture.
The operating system and other software installed on the worker VMs is an internal implementation detail of Terraform Cloud. It is not part of a stable public interface, and is subject to change at any time.
As the implementation detail of Terraform worker VM can be changed at any time, users who have hard-coded absolute file paths in the Terraform configurations may face with errors on missing files/directories
Solution
- Avoid using absolute but relative file paths in Terraform configurations
- Avoid using named value
path.cwdand usepath.rootorpath.moduleinstead. This is becausepath.cwdexpands to an absolute file path while the others return safe, relative path.
Outcome
Terraform runs to be completed successfully