SUSE Support

Here When You Need Us

How to enable debug logging when using Terraform?

This document (000020022) is provided subject to the disclaimer at the end of this document.

Environment

Rancher Terraform Provider

Situation

If you encounter an issue with the Rancher2 Terraform Provider it may be helpful to capture debug output from Terraform, so that you can provide this to Rancher Support. This article details how to enable debug output and set the log location for Terraform commands such as terraform apply.

 

 

    Resolution

    You can set the Terraform log level and location via the TF_LOG and TF_LOG_PATH environment variables.

    Set log level with TF_LOG

    The environment variableTF_LOG defines the log level. Valid log levels are (in order of decreasing verbosity): TRACE, DEBUG, INFO, WARN or ERROR.

    Set the log level in your environment with the appropriate command (substituting your preferred log level):

    Bash: export TF_LOG="DEBUG"

    PowerShell: $env:TF_LOG="DEBUG"

    Redirect Terraform logs with TF_LOG

    The environment variable TF_LOG_PATH specifies the file in which Terraform will write logs. If TF_LOG_PATH is not set, output is sent to standard output and error in the terminal. If the environment variable is set, Terraform will append logs from each run to the specified file.

    Set the Terraform log location in your environment with the appropriate command (substituting the path to your preferred file):

    Bash: export TF_LOG_PATH="tmp/terraform.log"

    PowerShell: $env:TF_LOG_PATH="C:\tmp\terraform.log"

    To set them permanently, you can add these environment variables to your .profile, .bashrc, PowerShell profile (if it exists, the path is stored in $profile environment variable) file, or the appropriate profile for your chosen shell.

    N.B. As this will append the log with the Terraform output every time you run a Terraform command, you may wish to configure log rotation for the chosen log file if this is enabled permanently. Alternatively, disable logging to file once you have finished troubleshooting.

    Further reading

    Disclaimer

    This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.

    • Document ID:000020022
    • Creation Date: 06-May-2021
    • Modified Date:28-Mar-2024
      • SUSE Rancher

    < Back to Support Search

    For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com

    tick icon

    SUSE Support Forums

    Get your questions answered by experienced Sys Ops or interact with other SUSE community experts.

    tick icon

    Support Resources

    Learn how to get the most from the technical support you receive with your SUSE Subscription, Premium Support, Academic Program, or Partner Program.

    tick icon

    Open an Incident

    Open an incident with SUSE Technical Support, manage your subscriptions, download patches, or manage user access.