• Overview
    • Enforce Policy as Code
    • Infrastructure as Code
    • Inject Secrets into Terraform
    • Integrate with Existing Workflows
    • Manage Kubernetes
    • Manage Virtual Machine Images
    • Multi-Cloud Deployment
    • Network Infrastructure Automation
    • Terraform CLI
    • Terraform Cloud
    • Terraform Enterprise
  • Registry
  • Tutorials
    • About the Docs
    • Intro to Terraform
    • Configuration Language
    • Terraform CLI
    • Terraform Cloud
    • Terraform Enterprise
    • Provider Use
    • Plugin Development
    • Registry Publishing
    • Integration Program
    • Terraform Tools
    • CDK for Terraform
    • Glossary
  • Community
GitHubTerraform Cloud
Download

    SDKv2

  • Overview
  • Tutorials: Custom Providers
    • Overview
    • Schema Types
    • Schema Behaviors
    • Schema Methods
    • Overview
    • Customizing Differences
    • Import
    • Retries and Customizable Timeouts
    • State Migration
  • Debugging Providers
    • Compatibility with Terraform 0.12
    • Switching to the standalone SDK
    • v2 Upgrade Guide
    • Overview
    • Naming
    • Depending on Providers
    • Deprecations, Removals, and Renames
    • Detecting Drift
    • Handling Sensitive Data
    • Testing Patterns
    • Versioning and Changelog
    • Writing Non-Go Providers
    • Overview
      • Overview
      • Test Cases
      • Test Steps
      • Sweepers
    • Testing API
    • Testing Patterns
    • Unit Testing
  • Other Plugin Docs

  • Plugin Development
  • Framework
  • Logging
  • Combining and Translating
Type '/' to Search

»Debugging SDKv2 Providers

This page contains implementation details for inspecting runtime information of a Terraform provider developed with SDKv2 via a debugger tool. Review the top level Debugging page for information pertaining to the overall Terraform provider debugging process and other inspection options, such as log-based debugging.

»Code Implementation

Update the main function for the project to conditionally enable the plugin/ServeOpts.Debug field. Conventionally, a -debug flag is used to control the Debug value.

This example uses a -debug flag to enable debugging, otherwise starting the provider normally:

func main() {
    var debug bool

    flag.BoolVar(&debug, "debug", false, "set to true to run the provider with support for debuggers like delve")
    flag.Parse()

    opts := &plugin.ServeOpts{
        Debug:        debug,
        ProviderAddr: "registry.terraform.io/example-namespace/example",
        ProviderFunc: provider.New(),
    }

    plugin.Serve(opts)
}
func main() {
    var debug bool

    flag.BoolVar(&debug, "debug", false, "set to true to run the provider with support for debuggers like delve")
    flag.Parse()

    opts := &plugin.ServeOpts{
        Debug:        debug,
        ProviderAddr: "registry.terraform.io/example-namespace/example",
        ProviderFunc: provider.New(),
    }

    plugin.Serve(opts)
}
github logoEdit this page
  • Overview
  • Docs
  • Extend
  • Privacy
  • Security
  • Press Kit
  • Consent Manager