Problem
A remote run in HCP Terraform may appear to be stuck after displaying the Initializing Terraform configuration... message. No further log output is generated for an extended period, making it seem as though the run has frozen during the initialization phase.
A typical run begins with the following output.
Terraform v1.0.8 on linux_amd64 Configuring remote state backend... Initializing Terraform configuration...
Under normal conditions, log output for the plan or apply continues after a few seconds. When this issue occurs, the run does not progress past this point.
Cause
The next step after Initializing Terraform configuration... is the execution of the terraform plan or terraform apply command. This issue can occur when a Terraform provider attempts to communicate with its API but encounters a problem, such as invalid or expired credentials.
Some providers, like the AWS provider, will silently retry failing API requests multiple times before timing out and producing an error message. During this retry period, the Terraform command is running but has not yet generated any output, making the run appear frozen.
Solution
To diagnose the underlying activity, enable detailed logging for the run by setting the TF_LOG environment variable in your HCP Terraform workspace.
- Navigate to the target workspace in HCP Terraform and select Variables.
- Add an Environment Variable.
- Set the Key to
TF_LOGand the Value toTRACE. - Queue a new plan or apply.
Outcome
Enabling trace-level logging forces the terraform plan or terraform apply command to provide immediate, detailed output about its operations. The TRACE logs will reveal the specific actions the Terraform provider is attempting, such as API requests and retries, helping you identify the root cause of the delay.
Additional Information
For more details on enabling debug logging, refer to the official Terraform documentation for the TF_LOG environment variable.