• Docs
  • Developers
  • Debugging a Provider

Debugging a Provider

Running the provider in debug mode

With the go-plugin architecture, providers run in a different process than the cloudquery-core executable. So, to run a locally-built provider instead of the default one from cloudquery-hub, we need to "attach" it to the main CloudQuery core executable.

First, we must run the provider in debug mode. To do this, set the environment variable CQ_PROVIDER_DEBUG=1 in our IDE or terminal and execute the provider.

💡

Your credentials need to be exported in the environment of your provider executable, not in the environment of the core cloudquery executable.

The following message will appear when executing the plugin binary.

Provider started, to attach CloudQuery set the CQ_REATTACH_PROVIDERS env var:
        export CQ_REATTACH_PROVIDERS=/cq-my-provider/.cq_reattach
Provider started, to attach CloudQuery set the CQ_REATTACH_PROVIDERS env var:
 
	Command Prompt:	set CQ_REATTACH_PROVIDERS=./providers/cq-my-provider/.cq_reattach
	PowerShell:	$env:CQ_REATTACH_PROVIDERS=./providers/cq-my-provider/.cq_reattach

Once we set up CQ_REATTACH_PROVIDERS, we will be able to execute any command from our CQ binary and it will use the debugged plugin instead of the latest version.

💡

We can now execute our provider from our favorite IDE in debug mode and put in breakpoints to test and debug our provider.

Example

In the following example, we will download an existing provider, compile it, and execute it in debug mode.

git clone https://github.com/cloudquery/cq-provider-aws.git
go build -o cq-provider-aws
 
export CQ_PROVIDER_DEBUG=1
 
// export credentials:
export AWS_ACCESS_KEY_ID={YOUR_AWS_ACCESS_KEY_ID}
export AWS_SECRET_ACCESS_KEY={YOUR_AWS_SECRET_ACCESS_KEY}
export AWS_SESSION_TOKEN={YOUR_AWS_SESSION_TOKEN}
 
./cq-provider-aws // Execute the provider binary
// Provider started, to attach CloudQuery set the CQ_REATTACH_PROVIDERS env var:
//        export CQ_REATTACH_PROVIDERS=/<path_to_your_provider>/.cq_reattach

After executing the provider, we will get a message about how to reattach our provider when we execute the main CQ binary.

// Path where we executed our aws provider
export CQ_REATTACH_PROVIDERS=/providers/cq-provider-aws/.cq_reattach
./cloudquery fetch --dsn "host=localhost user=postgres password=pass DB.name=postgres port=5432"
💡

The same example can be run from the IDE to add breakpoints.