Your Terraform apply command is hanging indefinitely. What is the best way to troubleshoot this?
- Wait longer for the operation to complete
- Restart the Terraform daemon
- Delete the state file and reinitialize
- Use TF_LOG=DEBUG to enable detailed logging and examine the output ✓
Correct answer: Use TF_LOG=DEBUG to enable detailed logging and examine the output
Setting the TF_LOG environment variable to DEBUG enables Terraform's most verbose logging level, which outputs detailed information about API calls, provider operations, and internal state transitions, allowing you to identify exactly where the apply is blocking, such as a hung API call or a provider waiting on a resource to reach a target state. Option A is incorrect because waiting indefinitely without investigation does not resolve the underlying issue and wastes time; a hung apply usually indicates a real problem such as a resource in an error state or a network timeout. Option B is incorrect because Terraform does not run as a persistent daemon; it is a CLI tool that executes and exits, so there is no daemon to restart. Option C is incorrect because deleting the state file is a destructive action that would cause Terraform to lose track of all managed resources, potentially leading to duplicate resource creation or orphaned infrastructure.
Topic: · terraform debugging, tf_log, terraform apply, infrastructure as code