Problem
With no changes in Terraform code, Terraform Cloud runs errored with errors related to files/directories missing.
E.g.
- On argument
filename
ofaws_lambda_function
resource - On using
templatefile
function - On using
external
data 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.cwd
and usepath.root
orpath.module
instead. This is becausepath.cwd
expands to an absolute file path while the others return safe, relative path.
Outcome
Terraform runs to be completed successfully