1

Is there any way to include verbose / debugging output in Terraform / Terragrunt?

I'm new to the language, and often struggle with knowing exactly what's going on. It would be helpful for me to be able to inspect certain values; e.g. to confirm that locals & variables have the values I expect, to get the ids of created components, etc.

I can include such info by creating outputs and assigning values there; but if I'm debugging a module I then have to include the output in the module's output, and again in the calling code's output for it to be visible; then have to delete those entries before delivering the solution.

I'd like a solution more like C#'s Debug.WriteLine(/*...*/) or PowerShell's Write-Verbose #... i.e. somewhere I can say what value I'd like to inspect, but have that output only show in the terminal when run with verbose output enabled, so these statements can be toggled on when needed, rather than impacting the delivered solution.

Does anything like this exist in the language? So far I've found nothing documented or by Googling.

Note: The TF_LOG environment variable documented here is helpful for providing more info on what's going on under the covers; but only allows you to see predefined output; not to push your own content to the output stream.

1 Answer 1

1

You might be able to do something with the local-exec Provisioner to push the information out to an external script or file which you could monitor separately during the run.

The issue you might encounter is the run order, HCL isn't processed top to bottom like a "traditional" programming language, it works out a dependency tree for the resources it is creating, so might not run the local-exec when you'd expect them to be run.

1
  • That's a good shout / a feature I'd not been aware of - thank-you. I've only upvoted rather than flagging as a solution since it's a workaround with a few side effects (e.g. creates a dependency on anyone using the module to have the required interpreter installed to meet this non-functional requirement), but will definitely have a play with this idea next time I hit this type of scenario.
    – JohnLBevan
    May 13, 2021 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.