Problem
After a remote execution run completes in Terraform Enterprise (TFE), a 401 Unauthorized error message may appear in the task-worker service logs. This error is a false positive that occurs when the agent attempts to update its status.
The log entry resembles the following output.
[ERROR] core: Unexpected HTTP response code: method=PUT url=https://<TFE_HOSTNAME>/api/agent/status status=401
Prerequisites
- Terraform Enterprise version
v202406-1or later.
Cause
This is a known issue where the agent's token expires just before the final status update, leading to a benign authorization failure at the end of the run. The core functionality of the run is not affected. The Terraform Enterprise engineering team is aware of this issue and is working on a resolution for a future release.
Solutions
The following workarounds can be applied until a permanent fix is available.
Solution 1: Ignore the Error Message
Because this error is a false positive and occurs after the run has successfully completed, you can safely ignore it. The error does not indicate a failure in the Terraform execution or the agent's primary tasks.
Solution 2: Adjust Monitoring Systems
If you have monitoring or alerting systems configured to parse the task-worker logs for errors, you should adjust them to disregard this specific 401 Unauthorized error for the /api/agent/status endpoint. This will prevent false alarms related to this known issue.
Additional Information
For more details on Terraform Enterprise agents, please refer to the official Terraform Enterprise documentation.