Terraform-plugin-log not outputting logs

I integrated terraform-plugin-log into my provider code and replaced my existing log.Printf("[DEBUG] ...") with tflog.Debug(ctx, "...").

When I run TF_LOG=DEBUG terraform plan, the debug logs no longer output by terraform.

What am I doing wrong here?

Hi @alexhung :wave: Thank you for raising this and sorry you ran into trouble here. Is the code you are using publicly available? If so, that would be great to see.

Otherwise to try and help without that context, here are some troubleshooting things to check:

  • Ensuring your github.com/hashicorp/terraform-plugin-sdk and/or github.com/hashicorp/terraform-plugin-framework (if using) Go dependencies are up to date
  • If using terraform-plugin-sdk, that the provider logic is using context-aware functions, such as CreateContext or CreateWithoutTimeout. terraform-plugin-log requires that previously setup context to operate correctly.
  • That the provider logic is not creating a separate context, e.g. context.Background() or context.TODO() before passing it to terraform-plugin-log.

Hi @bflad,

My code is not up on GitHub right now but I can push a branch for you to take a peek at.

To answer your questions, it’s ‘yes’ to all three. Hence I ran out of ideas and turn to the community for help.

I’ll share the branch once I push it up.

Turns out I didn’t have the latest terraform-plugin-sdk when I started the work. I was running 2.7.0 and after not able to get logging working, I shelved the branch and worked on another feature.

In this change, I updated the module to 2.14.0 so when I just now go back to the logging branch and update it, now it is running latest. And the logging works!


Thanks for taking the time to respond to me.

1 Like

Thank you for the followup! I created Denote Which Versions of Framework/SDK Are Required · Issue #57 · hashicorp/terraform-plugin-log · GitHub to ensure the documentation states the minimum required versions (at least until Fallback to Generic Logger Output · Issue #52 · hashicorp/terraform-plugin-log · GitHub is resolved). :+1:

1 Like