Problem
When using a custom build worker in Terraform Enterprise, environment variables defined in the worker's ~/.bashrc file are not sourced or available to local-exec provisioners during a run.
Prerequisites
- Terraform Enterprise version
v202308-1or older. - A custom build worker with environment variables configured in its
~/.bashrcfile.
Cause
By default, the local-exec provisioner in Terraform Enterprise does not execute commands within a bash shell. As a result, shell-specific startup files like ~/.bashrc are not loaded, and the environment variables they define are not available to the provisioner's command.
Solution
Specify a Bash Interpreter
To resolve this, explicitly define the interpreter for the local-exec provisioner to be /bin/bash. This forces the command to run within a bash shell, which will source the ~/.bashrc file.
You can configure the interpreter directly within the provisioner block.
resource "null_resource" "example" {
provisioner "local-exec" {
command = "env"
interpreter = ["/bin/bash", "-c"]
}
}Additional Information
- For more details on
local-execarguments, refer to the local-exec Provisioner Documentation.